PtokaX forum

Archive => Archived 5.1 boards => Request for scripts => Topic started by: Pieter on 04 November, 2006, 17:13:42

Title: Trivia topscorer in hubaddmessage
Post by: Pieter on 04 November, 2006, 17:13:42
Hi everyone,
I'm using robocop 10.023 and trivia-ex 0.68 and i'd like to put the best trivia player into robo's hubaddmessage.
It should look inside the scorefile and take the nick of the player with the highest score from there, but I don't know enough about lua to make this piece of script by myself, can someone please help ?

Greetz Pieter
Title: Re: Trivia topscorer in hubaddmessage
Post by: Rincewind on 04 November, 2006, 19:46:51
you'll not be able to get this into Robocop's hub add message as robocop is a compiled bot. What you could do is replicate the hub add message and disabl'e Robocops and then script the replacement o get your trivia top scorer.
Title: Re: Trivia topscorer in hubaddmessage
Post by: Pieter on 07 November, 2006, 14:38:17
can't it be put into hubaddmessage.lua inside the lua folder of robo ? it's an editable lua file...  ???
Title: Re: Trivia topscorer in hubaddmessage
Post by: Rincewind on 07 November, 2006, 19:48:18
If that part is uncompiled then yes it should be able to be added. I thought that bit was compiled. My bad.
Title: Re: Trivia topscorer in hubaddmessage
Post by: Pieter on 08 November, 2006, 00:17:27
QuoteIf that part is uncompiled then yes it should be able to be added.
I'm glad to hear that it's at least possible Rincewind ;)

Do you also know how i should make the piece of script ?

The robo hubaddmessage.lua looks like this :

Code (lua) Select

SendAdMessage = function()
local weeks,days,hours,minutes,seconds = GetUptimeSeconds(frmHub:GetUpTime())
local name,version = getHubVersion()
local info = "\r\n\r\n"
info = info.."  ================================\r\n"
info = info.."  ? Hub Information:\r\n"
-- shortened it a little ;-)
info = info.."  ================================\r\n"
SendToAll(tSettings.sBot, info)
end


The scorefile TriviaExScores.txt looks like this :

Code (lua) Select

TrivEx._Scores = {
["Pieter"] = {
["Streak"] = 1,
["Score"] = 19,
["AvTime"] = {
[2] = 2,
[1] = 18,
[3] = 9,
},
},
--here are the other players
}


Hope you (or someone else) can help  :)
Title: Re: Trivia topscorer in hubaddmessage
Post by: Rincewind on 09 November, 2006, 19:06:47
Adding something like
dofile("topscorer.txt")
local topscore,topscorer = 0,""
for i,v in pairs(TrivEx_Scores) do
if v.Score > topscore then
topscore = v.Score
topscorer = i
end
end

would get the top scorer that you can then add into the info string.
Title: Re: Trivia topscorer in hubaddmessage
Post by: Pieter on 09 November, 2006, 22:22:41
I have made this infoline in the hubaddmessage:
Code (lua) Select

info = info.." ? Trivia Topscorer:\t\t"..GetTopScorer().."\r\n"

And I made this function:
Code (lua) Select

GetTopScorer = function()
dofile("C:\\Ptokax\\scripts\\TRIVIA\\TriviaExScores.txt")
local topscore,topscorer = 0,""
for i,v in pairs(TrivEx_Scores) do
if v.Score > topscore then
topscore = v.Score
topscorer = i
end
end
end


Now I get a syntax error : TriviaExScores.txt:38: attempt to index global 'TrivEx' (a nil value)
Line 38 is the line "for i,v in pairs(TrivEx._Scores) do"

What have I done wrong  ???  (don't know much about it so it can be a very stupid mistake  ;) )
Title: Re: Trivia topscorer in hubaddmessage
Post by: Rincewind on 09 November, 2006, 23:23:25
It would look from the error line
Quote"for i,v in pairs(TrivEx._Scores) do"
that the code you posted is not quite right. The ipairs in the code did not have a . after TrivEx but the error line does.
Title: Re: Trivia topscorer in hubaddmessage
Post by: Pieter on 12 November, 2006, 02:01:13
Made a typing fault in my post, sorry  ;) 
It's without the dot, same as in the piece of code I posted above it
Posted on: 09 November 2006, 22:51:13
I see I said something wrong  :-[
TriviaExScores.txt:38: attempt to index global 'TrivEx' (a nil value)
The error in line 38 is not from the lua file but from the score file, it is the last line of the file.
In my previous post you can see how the file ends ( with a } )
Title: Re: Trivia topscorer in hubaddmessage
Post by: Rincewind on 12 November, 2006, 09:42:50
Is there actually a . in the score files table name?
Title: Re: Trivia topscorer in hubaddmessage
Post by: Pieter on 13 November, 2006, 23:24:12
The file looks like this:
Code (lua) Select

TrivEx._Scores = {
["Pieter"] = {
["Streak"] = 1,
["Score"] = 19,
["AvTime"] = {
[2] = 2,
[1] = 18,
[3] = 9,
},
},
--here are the other players
}


I guess TrivEx._Scores is the table name, and that's with a . indeed

Posted on: 12 November 2006, 10:34:21
I tried a few things this weekend ;D
To prevent the previous error i've added a few lines from the trivia script. ( is this correct ?)
Also I changed the table name, added the .  (same as in the scoresfile)

I've made this script now:

Code (lua) Select

TrivEx = {}
TrivEx._Scores = {}

GetTopScorer = function()
dofile("C:\\Ptokax\\scripts\\TRIVIA\\TriviaExScores.txt");
local topscore,topscorer = 0,""
for i,v in pairs(TrivEx._Scores) do
if v.Score > topscore then
topscore = v.Score
topscorer = i
end
end
end


But now it gives syntax error hubaddmessage.lua:22: attempt to concatenate a nil value
I guess this means that the function does not give any output  :(
How do I get output from the function ?

Posted on: 13 November 2006, 21:33:33
Just found out that return topscorer works  :)

Code (lua) Select


TrivEx = {}
TrivEx._Scores = {}

GetTopScorer = function()
dofile "C:\\Ptokax\\scripts\\TRIVIA\\TriviaExScores.txt");
local topscore,topscorer = 0,""
for i,v in pairs(TrivEx._Scores) do
if v.Score > topscore then
topscore = v.Score
topscorer = i
end
end
return topscorer
end


It gives the correct topscorer now but there is one problem:
it deletes everybody from the trivia scorefile when I exit ptokax   :o ???
Title: Re: Trivia topscorer in hubaddmessage
Post by: Rincewind on 13 November, 2006, 23:31:33

TrivEx._Scores = {} is blanking the score table and I assume that there is a write of the table on script exit which is why your table gets blanked.
Title: Re: Trivia topscorer in hubaddmessage
Post by: Pieter on 13 November, 2006, 23:46:09
Aha I copied one line too much  ;D

Works great now  :P  Thanxxx Rincewind
Title: Re: Trivia topscorer in hubaddmessage
Post by: Rincewind on 14 November, 2006, 08:48:14
Not a problem. Pleased you got sorted  :)