PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Exile on 08 February, 2005, 19:39:04

Title: PLEEEEEEASE HELP ME
Post by: Exile on 08 February, 2005, 19:39:04
i have this as part of a script i am writing...

function DataArrival(user, data)
s,e,cmd = strfind(data, "%b<>%s+(%S+)(%S+)")
if (cmd==Prefix..Start) and user.bOperator then
StartTimer()
OnTimer()
end
end

But I want a second command, that when you press it, it stops the timer :S how do i do it...please help

Title:
Post by: Jaras on 08 February, 2005, 20:04:12
function DataArrival( user, data )
           s,e,cmd = strfind( data, "%b<>%s+(%S+)" )
           if ( cmd == Prefix..Start ) and ( user.bOperator ) then
                      StartTimer( iAmountOfMilisecondsBetweenTimerHits )
           else
                      if ( cmd == Prefix..Stop ) and ( user.bOperator ) then
                                 StopTimer()
                      end
           end
end

function OnTimer()
--//insert here what has to be done when timer hits
end

where iAmountOfMilisecondsBetweenTimerHits isn't some inbuild var/const - it's for understadnding purposes... =]
f.e. StarTimer( 60000 ) will fire OnTimer function in 1 minute delays.
Title:
Post by: blackwings on 08 February, 2005, 20:12:37
Jaras, I think this looks nicer =>
function DataArrival(user, data)
           s,e,cmd = strfind(data, "%b<>%s+(%S+)")
           if (cmd == Prefix..Start) and user.bOperator then
            StartTimer(time) -- seconds x 1000 or minutes x 60000
           elseif (cmd == Prefix..Stop) and user.bOperator then
            StopTimer()
           end
end

function OnTimer()
--//insert here what has to be done when timer hits
end
Title:
Post by: Jaras on 08 February, 2005, 20:52:36
yup, but i hate using elseif and i always put condisions in brackets when there are more then one to make code look nicer  :D
Title:
Post by: plop on 09 February, 2005, 01:52:30
how about making cmd a local?

@jaras: your way uses 2 lua commands else and if, so elseif is always faster.
above 4 if/elseif's i advice 2 use a table.

plop