Ok, here is the script:
---start---
points = {}
function Main()
points = dofile("points.dat") or {}
end
function OnExit()
local f = openfile("points.dat", "w+")
assert(f, "points.dat")
write(f, "return {\n")
for nick, value in points do
write(f, "\t"..format("[%q]", nick).." = "..value..",\n")
end; write(f, "}")
closefile(f)
end
function DataArrival(user, data)
if strsub(data, 1, 1) == "<" then
local s, e, cmd, args = strfind(data, "^%b<> %+(%a+)%s*(.*)%|$")
if s then
cmd = strlower(cmd)
if cmd == "give" and user.bOperator then
local s, e, nick, value, reason = strfind(args, "^(%S+)%s*([%d%-]*)%s*(.*)$")
if s then
if value == "" then value = 1
else value = tonumber(value) end
if reason == "" then reason = "for no reason"
else reason = "because "..reason end
points[nick] = (points[nick] or 0) + value
user:SendData(">> "..nick.." now has "..points[nick].." points")
SendToNick(nick, ">> "..user.sName.." has given you "..value.." points "..reason)
OnExit();
else
user:SendData(">> syntax: +give [points] [reason]")
end
elseif cmd == "topusers" then
local index = {}
for nick, value in points do tinsert(index, nick) end
sort(index, function(a, b) return points[a] > points end)
local n = getn(index)
if n > 10 then n = 10 end
user:SendData(">> top "..n.." users..")
for i = 1, n do
local nick = index
local value = points[nick]
user:SendData(">>\t["..value.."]\t "..nick)
end
else return
end; return 1
end
end
end
--end--
This works perfectly: +give nick points reason
example: +give john 35 for sharing 500 gigs.
except in the main chat it only states nick and points , but not the reason. Can someone fix this to give the reason also? It should work like that but it doesn't.
i dont understand this >
if reason == "" then reason = "for no reason"
else reason = "because "..reason end
tip ;)
where in mainchat.. when you give points?
phatty ?
QuoteOriginally posted by tezlo
where in mainchat.. when you give points?
phatty ?
i dont understand the question, and ive notused the script, just how i look at it, looks wrong to me
well i wrote it.. whats wrong with it?
i use it like that too...
Is that OK or is it just waste of code since i thought of it as if Arg == nil
it is afterall looking for something to be there, and if there ain't then it's considered nil!!
But i know what's wrong... it send as user:SendData() which may be considered Main for some...
points = {}
function Main()
points = dofile("points.dat") or {}
end
function OnExit()
local f = openfile("points.dat", "w+")
assert(f, "points.dat")
write(f, "return {\n")
for nick, value in points do
write(f, "\t"..format("[%q]", nick).." = "..value..",\n")
end;
write(f, "}")
closefile(f)
end
function DataArrival(user, data)
if strsub(data, 1, 1) == "<" then
local s, e, cmd, args = strfind(data, "^%b<> %+(%a+)%s*(.*)%|$")
if s then
cmd = strlower(cmd)
if cmd == "give" and user.bOperator then
local s, e, nick, value, reason = strfind(args, "^(%S+)%s*([%d%-]*)%s*(.*)$")
if s then
if value == "" then value = 1
else value = tonumber(value) end
if reason == "" then reason = "for no reason"
else reason = "because "..reason end
points[nick] = (points[nick] or 0) + value
SendToAll(">> "..nick.." now has "..points[nick].." points "..reason)
SendToNick(nick, ">> "..user.sName.." has given you "..value.." points "..reason)
OnExit();
else
user:SendData(">> syntax: +give [points] [reason]")
end
elseif cmd == "topusers" then
local index = {}
for nick, value in points do tinsert(index, nick) end
sort(index, function(a, b) return points[a] > points[b] end)
local n = getn(index)
if n > 10 then n = 10 end
user:SendData(">> top "..n.." users..")
for i = 1, n do
local nick = index[i]
local value = points[nick]
user:SendData(">>\t["..value.."]\t "..nick)
end
else return
end; return 1
end
end
end
user:SendToAll ?
ad regexp..
(.*) will match any or an empty string
so if you dont specify one.. reason is "" (empty string.. not nil)
QuoteOriginally posted by tezlo
well i wrote it.. whats wrong with it?
sorry about that, i just tabbed it out, and me misread, note please use the code prefix for posting code, i can barely read it when its posted as normal text........
QuoteOriginally posted by tezlo
user:SendToAll ?
ad regexp..
(.*) will match any or an empty string
so if you dont specify one.. reason is "" (empty string.. not nil)
Yea, lol, went through it fast..
Well i ussualy use (.+) and then often with reasons and other things that shall be optional i use
if arg == nil then
--//Bla Bla
elseif arg = "" then
That is why i want to know if i really need to check it against nil..
say you have a regexp..
local s, e, somearg, someotherarg = strfind(something, "(%S+)%s*(.*)")
if s ~= nil then somearg and someotherarg are strings
you only need to check that
btw.. (.+) will never give you an empty string
Thnx Tezlo for fixing. I forgot who made this great script. I did make a notation in it before i started using it in the hub again. Awesome work my friend.
Thanks alot tezlo... that's why im asking.. waset of code!!