i need a script canceling votes at the end of map ( no kmod) if etadmin:mod running and tried to vote a lua but i'm not good in this so i tried but failed hard i want to chancel config votes at the end of map ! here u see my code of mess
function et_ClientCommand( cno, cmd )
entered_command = string.lower(et.trap_Argv(0))
entered_argument = string.lower(et.trap_Argv(1))
if entered_command == "callvote" then
if entered_argument == "config" then
timelimit=tonumber(et.trap_Cvar_Get("timelimit"))
local cancel_percent = ( timelimit * ( 95 / 100 ) )
if (cancel_percent < 2) then
et.trap_SendServerCommand(cno, "cpm \"^1Sry this vote is disabled at the end of map!\n\"" )
return 1
end
end
end
return 0
end
I dont have a server up atm so this is a bit of guesswork. The gamestate cvar might be easier to use than a timelimit calculation. I would suggest something like this:
function et_ClientCommand( cno, cmd )
local gamestate = tonumber(et.trap_Cvar_Get( "gamestate" ))
if gamestate ~= 3 then return 0 end -- GS_INTERMISSION(3), GS_WAITING_FOR_PLAYERS(4)
local entered_command = string.lower(et.trap_Argv(0))
local entered_argument = string.lower(et.trap_Argv(1))
if entered_command == "callvote" then
if entered_argument == "config" then
et.trap_SendServerCommand(cno, "cpm \"^1Sry this vote is disabled at the end of map!\n\"" )
return 1
end
end
return 0
end
Hmm, I went to debug it and then realised that voting is not allowed during the intermission anyway. Oops. (the script does work as intended though, so its not all bad).
I'm not sure exactly what you want the script to do. Do you want to prevent config votes when the game is still in progress and the timelimit is almost up?
Edit: It looks from your example that that is what you wanted. Yours is more or less there but the cvar "timelimit" is a constant and so cant be used to test the round time. You will probably need to do a little calculation like in the example below:
function et_InitGame( levelTime, randomSeed, restart )
local milliseconds = et.trap_Milliseconds()
local gamestate = tonumber(et.trap_Cvar_Get( "gamestate" ))
if gamestate == 0 then -- GS_PLAYING
local timelimit=tonumber(et.trap_Cvar_Get("timelimit"))
local timelimit_ms = timelimit*60*1000
cancel_time = (milliseconds+timelimit_ms)-(0.05*timelimit_ms)
end
end
function et_ClientCommand( cno, cmd )
local milliseconds = tonumber(et.trap_Milliseconds())
if milliseconds < cancel_time then return 0 end
local entered_command = string.lower(et.trap_Argv(0))
local entered_argument = string.lower(et.trap_Argv(1))
if entered_command == "callvote" then
if entered_argument == "config" then
et.trap_SendServerCommand(cno, "cpm \"^1Sry this vote is disabled at the end of map!\n\"" )
return 1
end
end
return 0
end
function et_ClientCommand( cno, cmd ) {
local entered_command = string.lower(et.trap_Argv(0))
local entered_argument = string.lower(et.trap_Argv(1))
if entered_command == "callvote" then
local timelimit=tonumber(et.trap_Cvar_Get("timelimit"))
//I don't know lua, but this is a c example
//where level.time and level.starttime are defined in game_init and game_run_frame
if (level.time - level.startTime >= (timelimit*60000)-10000) return 1;
}
If you're not manage to do this in LUA, I suggest you take a look at GameMonkey ScriptMod(www.gaminggone.net/gmScriptMod/), it has a much easier syntax, and is compatible with all ET mods.
In Lua, the start time can be defined in et_initgame (GAME_INIT), which is what I did in the example above. I used et.trap_Milliseconds in the way GAME_RUN_FRAME would be used.
If you want the config vote to be cancelled after 10 mins of any map then it makes things a little simpler. In my example, I based it on the calculation shown in yours (Crazyfrag) where cancel_time was 95% into the timelimit. It worked ok when I tested it.
This example cancels config votes after 10 mins, tested and working:
cancel_time_mins = 10
function et_InitGame( levelTime, randomSeed, restart )
local gamestate = tonumber(et.trap_Cvar_Get( "gamestate" ))
if gamestate == 0 then -- GS_PLAYING
local milliseconds = et.trap_Milliseconds()
cancel_time = (milliseconds) + (cancel_time_mins * 60 * 1000)
end
end
function et_ClientCommand( cno, cmd )
local milliseconds = tonumber(et.trap_Milliseconds())
if milliseconds < cancel_time then return 0 end
local entered_command = string.lower(et.trap_Argv(0))
local entered_argument = string.lower(et.trap_Argv(1))
if entered_command == "callvote" then
if entered_argument == "config" then
et.trap_SendServerCommand(cno, "cpm \"^1Sry this vote is disabled at the end of map!\n\"" )
return 1
end
end
return 0
end
function et_RunFrame(leveltime)
local gamestate = tonumber(et.trap_Cvar_Get( "gamestate" ))
if gamestate == 0 then -- GS_PLAYING
local milliseconds = et.trap_Milliseconds()
cancel_time = (milliseconds) + (cancel_time_mins * 60 * 1000)
end
end
That function is in et_initgame so that the level start time is captured. Put it in runframe and cancel_time will be continuously changed (and the script wont work). I used the gamestate check to capture the level start time when the round starts, rather than when warmup begins.
McSteve wrote:That function is in et_initgame so that the level start time is captured. Put it in runframe and cancel_time will be continuously changed (and the script wont work). I used the gamestate check to capture the level start time when the round starts, rather than when warmup begins.
cancel_time_mins = 5
function et_InitGame( levelTime, randomSeed, restart )
local gamestate = tonumber(et.trap_Cvar_Get( "gamestate" ))
if gamestate == 0 then -- GS_PLAYING
local milliseconds = et.trap_Milliseconds()
cancel_time = (milliseconds) + (cancel_time_mins * 60 * 1000)
end
end
function et_ClientCommand( cno, cmd )
local milliseconds = tonumber(et.trap_Milliseconds())
if milliseconds < cancel_time then return 0 end
local entered_command = string.lower(et.trap_Argv(0))
local entered_argument = string.lower(et.trap_Argv(1))
if entered_command == "callvote" then
if entered_argument == "config" then
et.trap_SendServerCommand(cno, "cp \"^1Sry this Vote is disabled after 5mins of playing!!\n\"" )
return 1
end
end
return 0
end
cancel_time_mins = 5
cancel_time = 0
function et_InitGame( levelTime, randomSeed, restart )
local gamestate = tonumber(et.trap_Cvar_Get( "gamestate" ))
if gamestate == 0 then -- GS_PLAYING
local milliseconds = et.trap_Milliseconds()
cancel_time = (milliseconds) + (cancel_time_mins * 60 * 1000)
end
end
function et_ClientCommand( cno, cmd )
local milliseconds = tonumber(et.trap_Milliseconds())
if milliseconds < cancel_time then return 0 end
local entered_command = string.lower(et.trap_Argv(0))
local entered_argument = string.lower(et.trap_Argv(1))
if entered_command == "callvote" then
if entered_argument == "config" then
et.trap_SendServerCommand(cno, "cp \"^1Sry this Vote is disabled after 5mins of playing!!\n\"" )
return 1
end
end
return 0
end
Agreed, Dutchmeat is right. "cancel_time" is not initialised until gamestate is changed to 'playing', hence will be nil during warmup giving that error message.