cancel vote at the end of rounds!

Discussions about ET modding (sdk code, player/weapon modeling)

Moderators: Forum moderators, developers

Post Reply
crazyfrag
Posts: 105
Joined: Fri Oct 01, 2004 1:17 pm

cancel vote at the end of rounds!

Post by crazyfrag »

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 :P

Code: Select all

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 &#40;cancel_percent < 2&#41; then 
			et.trap_SendServerCommand&#40;cno, "cpm \"^1Sry this vote is disabled at the end of map!\n\"" &#41;
				return 1
			 end
	end
end
return 0
end
McSteve
Posts: 113
Joined: Tue Sep 12, 2006 7:41 am

Post by McSteve »

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:

Code: Select all

function et_ClientCommand&#40; cno, cmd &#41;
	local gamestate = tonumber&#40;et.trap_Cvar_Get&#40; "gamestate" &#41;&#41;
	
	if gamestate ~= 3 then return 0 end --   GS_INTERMISSION&#40;3&#41;, GS_WAITING_FOR_PLAYERS&#40;4&#41;
   
	local entered_command = string.lower&#40;et.trap_Argv&#40;0&#41;&#41;
	local entered_argument = string.lower&#40;et.trap_Argv&#40;1&#41;&#41;

	if entered_command == "callvote" then
		if entered_argument == "config" then
			et.trap_SendServerCommand&#40;cno, "cpm \"^1Sry this vote is disabled at the end of map!\n\"" &#41;
			return 1
		end
	end
	
	return 0
	
end
GhosT:McSteve
Ghostworks Gaming Community
crazyfrag
Posts: 105
Joined: Fri Oct 01, 2004 1:17 pm

Post by crazyfrag »

not workin :-(
McSteve
Posts: 113
Joined: Tue Sep 12, 2006 7:41 am

Post by McSteve »

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:

Code: Select all

function et_InitGame&#40; levelTime, randomSeed, restart &#41;

	local milliseconds = et.trap_Milliseconds&#40;&#41;
	local gamestate = tonumber&#40;et.trap_Cvar_Get&#40; "gamestate" &#41;&#41;
	
	if gamestate == 0 then	-- GS_PLAYING 
		local timelimit=tonumber&#40;et.trap_Cvar_Get&#40;"timelimit"&#41;&#41;
		local timelimit_ms = timelimit*60*1000		
		cancel_time = &#40;milliseconds+timelimit_ms&#41;-&#40;0.05*timelimit_ms&#41;
	end
end


function et_ClientCommand&#40; cno, cmd &#41;

	local milliseconds = tonumber&#40;et.trap_Milliseconds&#40;&#41;&#41;	
	if milliseconds < cancel_time then return 0 end
   
	local entered_command = string.lower&#40;et.trap_Argv&#40;0&#41;&#41;
	local entered_argument = string.lower&#40;et.trap_Argv&#40;1&#41;&#41;

	if entered_command == "callvote" then
		if entered_argument == "config" then
			et.trap_SendServerCommand&#40;cno, "cpm \"^1Sry this vote is disabled at the end of map!\n\"" &#41;
			return 1
		end
	end
	
	return 0
	
end
GhosT:McSteve
Ghostworks Gaming Community
crazyfrag
Posts: 105
Joined: Fri Oct 01, 2004 1:17 pm

Post by crazyfrag »

i want to disable the config vote after 10 minuits of playing for the rest of map


i tested not worikin :-(
User avatar
dutchmeat
Posts: 62
Joined: Tue Jan 28, 2003 8:08 am
Location: Netherlands
Contact:

Post by dutchmeat »

Use GAME_INIT to define the starttime,
then use GAME_RUN_FRAME to define the current level time

then do something like this in your gameclientcommand function:

Code: Select all


function et_ClientCommand&#40; cno, cmd &#41; &#123;

	local entered_command = string.lower&#40;et.trap_Argv&#40;0&#41;&#41; 
	local entered_argument = string.lower&#40;et.trap_Argv&#40;1&#41;&#41; 


	if entered_command == "callvote" then 
		local timelimit=tonumber&#40;et.trap_Cvar_Get&#40;"timelimit"&#41;&#41; 


		//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 &#40;level.time - level.startTime >= &#40;timelimit*60000&#41;-10000&#41; return 1;

&#125;
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.
crazyfrag
Posts: 105
Joined: Fri Oct 01, 2004 1:17 pm

Post by crazyfrag »

i tried much thing but nothing workes :'(
McSteve
Posts: 113
Joined: Tue Sep 12, 2006 7:41 am

Post by McSteve »

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:

Code: Select all

cancel_time_mins = 10

function et_InitGame&#40; levelTime, randomSeed, restart &#41;

   local gamestate = tonumber&#40;et.trap_Cvar_Get&#40; "gamestate" &#41;&#41;
   
   if gamestate == 0 then   -- GS_PLAYING
      local milliseconds = et.trap_Milliseconds&#40;&#41;     
      cancel_time = &#40;milliseconds&#41; + &#40;cancel_time_mins * 60 * 1000&#41;
   end
end


function et_ClientCommand&#40; cno, cmd &#41;

   local milliseconds = tonumber&#40;et.trap_Milliseconds&#40;&#41;&#41;   
   if milliseconds < cancel_time then return 0 end
   
   local entered_command = string.lower&#40;et.trap_Argv&#40;0&#41;&#41;
   local entered_argument = string.lower&#40;et.trap_Argv&#40;1&#41;&#41;

   if entered_command == "callvote" then
      if entered_argument == "config" then
         et.trap_SendServerCommand&#40;cno, "cpm \"^1Sry this vote is disabled at the end of map!\n\"" &#41;
         return 1
      end
   end
   
   return 0
   
end
GhosT:McSteve
Ghostworks Gaming Community
crazyfrag
Posts: 105
Joined: Fri Oct 01, 2004 1:17 pm

Post by crazyfrag »

it works :-)

<3 u sooo much

thx thx thx ^^
User avatar
Luk4ward
Posts: 236
Joined: Sun Jul 30, 2006 1:55 pm
Location: Poland
Contact:

Post by Luk4ward »

as dutchmeat said i suggest to put gamestate var into et Frame function:

Code: Select all

function et_RunFrame&#40;leveltime&#41; 

   local gamestate = tonumber&#40;et.trap_Cvar_Get&#40; "gamestate" &#41;&#41;
   
   if gamestate == 0 then   -- GS_PLAYING
      local milliseconds = et.trap_Milliseconds&#40;&#41;     
      cancel_time = &#40;milliseconds&#41; + &#40;cancel_time_mins * 60 * 1000&#41;
   end
end 
wolFTeam.pl
McSteve
Posts: 113
Joined: Tue Sep 12, 2006 7:41 am

Post by McSteve »

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.
GhosT:McSteve
Ghostworks Gaming Community
User avatar
Luk4ward
Posts: 236
Joined: Sun Jul 30, 2006 1:55 pm
Location: Poland
Contact:

Post by Luk4ward »

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.
Ah i see, sorry then for misunderstanding
wolFTeam.pl
crazyfrag
Posts: 105
Joined: Fri Oct 01, 2004 1:17 pm

Post by crazyfrag »

now i get this in console logs:

etpro: et_ClientCommand error running lua script: [string "can.lua"]:18: attempt to compare number with nil

Code: Select all


cancel_time_mins = 5

function et_InitGame&#40; levelTime, randomSeed, restart &#41;

   local gamestate = tonumber&#40;et.trap_Cvar_Get&#40; "gamestate" &#41;&#41;
   
   if gamestate == 0 then   -- GS_PLAYING
      local milliseconds = et.trap_Milliseconds&#40;&#41;     
      cancel_time = &#40;milliseconds&#41; + &#40;cancel_time_mins * 60 * 1000&#41;
   end
end


function et_ClientCommand&#40; cno, cmd &#41;

   local milliseconds = tonumber&#40;et.trap_Milliseconds&#40;&#41;&#41;   
   if milliseconds < cancel_time then return 0 end
   
   local entered_command = string.lower&#40;et.trap_Argv&#40;0&#41;&#41;
   local entered_argument = string.lower&#40;et.trap_Argv&#40;1&#41;&#41;

   if entered_command == "callvote" then
      if entered_argument == "config" then
         et.trap_SendServerCommand&#40;cno, "cp \"^1Sry this Vote is disabled after 5mins of playing!!\n\"" &#41;
         return 1
      end
   end
   
   return 0
   
end 
User avatar
dutchmeat
Posts: 62
Joined: Tue Jan 28, 2003 8:08 am
Location: Netherlands
Contact:

Post by dutchmeat »

try:

Code: Select all



cancel_time_mins = 5 
cancel_time = 0

function et_InitGame&#40; levelTime, randomSeed, restart &#41; 

   local gamestate = tonumber&#40;et.trap_Cvar_Get&#40; "gamestate" &#41;&#41; 
    
   if gamestate == 0 then   -- GS_PLAYING 
      local milliseconds = et.trap_Milliseconds&#40;&#41;      
      cancel_time = &#40;milliseconds&#41; + &#40;cancel_time_mins * 60 * 1000&#41; 
   end 
end 


function et_ClientCommand&#40; cno, cmd &#41; 

   local milliseconds = tonumber&#40;et.trap_Milliseconds&#40;&#41;&#41;    
   if milliseconds < cancel_time then return 0 end 
    
   local entered_command = string.lower&#40;et.trap_Argv&#40;0&#41;&#41; 
   local entered_argument = string.lower&#40;et.trap_Argv&#40;1&#41;&#41; 

   if entered_command == "callvote" then 
      if entered_argument == "config" then 
         et.trap_SendServerCommand&#40;cno, "cp \"^1Sry this Vote is disabled after 5mins of playing!!\n\"" &#41; 
         return 1 
      end 
   end 
    
   return 0 
    
end 
McSteve
Posts: 113
Joined: Tue Sep 12, 2006 7:41 am

Post by McSteve »

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.

Well spotted.
GhosT:McSteve
Ghostworks Gaming Community
Post Reply