lua: removed nested ifs

hopefully this is much better
This commit is contained in:
Rafał Pawlak 2016-10-20 19:55:37 +02:00
parent 8ef8943618
commit 8fabe956de

View file

@ -1,5 +1,5 @@
modname = "Banners" modname = "Banners"
version = "0.2" version = "0.3"
welcome = "^WELCOME MESSAGE" -- Welcome message here when client finished connecting to the server welcome = "^WELCOME MESSAGE" -- Welcome message here when client finished connecting to the server
@ -22,53 +22,42 @@ timer5 = 0
-------------------- SAMPLE ----------------------------------------------------------------------------------- -------------------- SAMPLE -----------------------------------------------------------------------------------
-- timer = 100000 -- timer = 100000
-- timer1 = 5000 -- timer1 = 105000
-- timer2 = 6000 ARE THOSE VALUES CORRECT AND MAKE SENSE HERE -- timer2 = 106000 ARE THOSE VALUES CORRECT AND MAKE SENSE HERE
-- timer3 = 7000 OR ALL THEY SHOULD BE REPLACED BY 1000 ? (BUT THIS WAY MIGHT GET MESSY) -- timer3 = 107000 OR ALL THEY SHOULD BE REPLACED BY 1000 ? (BUT THIS WAY MIGHT GET MESSY)
-- timer4 = 8000 -- timer4 = 108000
-- timer5 = 9000 -- timer5 = 109000
------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------
------------------ TODO! ------------------------------------------------------------------------------------------ ------------------ TODO! ------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------
-- print welcome message to connected client to show gratitude for client -- print welcome message to connected client to show gratitude for client
-- Get millisec value then increase it with timer's values -- Get millisec value
-- FIND OUT HOW TO MAKE IT INTO LOOP!! -- FIND OUT HOW TO MAKE IT INTO LOOP!!
-- Do a conditional statement if/elseif/else comparing -- Do a conditional statement if/elseif/else comparing
------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------
------------------------------------------!!DO NOT CHANGE BELOW!!--------------------------------------------------
function et_InitGame( levelTime, randomSeed, restart ) function et_InitGame( levelTime, randomSeed, restart )
et.RegisterModname( modname .. " " .. version ) et.RegisterModname( modname .. " " .. version )
local milliseconds = et.trap_Milliseconds() -- is this right way ? local milliseconds = et.trap_Milliseconds() -- is this right way ?
local a = (milliseconds*1000)/60
if(milliseconds == timer) if(a == timer)
et.trap_SendServerCommand(clientNum, "cpm \"" .. banner .."^7\n") et.trap_SendServerCommand(clientNum, "cpm \"" .. banner .."^7\n")
elseif(a == timer1)
if(milliseconds == timer1)
et.trap_SendServerCommand(clientNum, "cpm \"" .. banner1 .."^7\n") et.trap_SendServerCommand(clientNum, "cpm \"" .. banner1 .."^7\n")
elseif(a == timer2)
if(miliseconds == timer2)
et.trap_SendServerCommand(clientNum, "cpm \"" .. banner2 .."^7\n") et.trap_SendServerCommand(clientNum, "cpm \"" .. banner2 .."^7\n")
elseif(a == timer3)
if(miliseconds == timer3)
et.trap_SendServerCommand(clientNum, "cpm \"" .. banner3 .."^7\n") et.trap_SendServerCommand(clientNum, "cpm \"" .. banner3 .."^7\n")
elseif(a == timer4)
if(miliseconds == timer4)
et.trap_SendServerCommand(clientNum, "cpm \"" .. banner4 .."^7\n") et.trap_SendServerCommand(clientNum, "cpm \"" .. banner4 .."^7\n")
elseif(a == timer5)
if(miliseconds == timer5)
et.trap_SendServerCommand(clientNum, "cpm \"" .. banner5 .."^7\n") et.trap_SendServerCommand(clientNum, "cpm \"" .. banner5 .."^7\n")
end -- is every if() statement needs else() ??
end
end
end
end
else else
et.trap_SendServerCommand(clientNum, "cpm \"" .. "NO BANNERS" .."^7\n") et.trap_SendServerCommand(clientNum, "cpm \"" .. "NO BANNERS" .."^7\n")
end end
@ -77,7 +66,6 @@ end
function et_ClientConnect( clientNum, firstTime, isBot ) function et_ClientConnect( clientNum, firstTime, isBot )
et.trap_SendServerCommand(clientNum, "cpm \"" .. welcome .."^7\n") et.trap_SendServerCommand(clientNum, "cpm \"" .. welcome .."^7\n")
end end
function et_ShutdownGame( restart ) function et_ShutdownGame( restart )