Lua script about the intermission [help pls]

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

Moderators: Forum moderators, developers

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

Lua script about the intermission [help pls]

Post by Luk4ward »

Hi,

Im wondering is it possible to write such lua:

Code: Select all

when the intermission stars then:

exec some cmds

elseif intermission time - 5 seconds then

exec some cmds
it has to be written in tricky way? I meant which will count the time from the start of round or smth?

thx for any help, regards
wolFTeam.pl
User avatar
nano
Posts: 5
Joined: Mon Sep 04, 2006 7:56 am

Post by nano »

etadmin_mod can display some statistics when the round is over. You could download the source code and look at what messages it reacts. I know that you can read something like "Timelimit hit" in the console when the time is over.
User avatar
Luk4ward
Posts: 236
Joined: Sun Jul 30, 2006 1:55 pm
Location: Poland
Contact:

Post by Luk4ward »

Yes i was thinking about it too. Btw dnt want to do such thing in etadmin. I found this:

Code: Select all

log("Timelimit: $timelimit")
( $line eq "Exit: Wolf EndRound." || $line eq "Exit: Timelimit hit." )
btw how can i exec some files with cmds inside) in lua?

Regards
wolFTeam.pl
User avatar
nano
Posts: 5
Joined: Mon Sep 04, 2006 7:56 am

Post by nano »

There is no such function that allows you to exec commands from a file, but it shouldn’t be that hard to write such one on your own.

Edit: What about the following?

Code: Select all

et.trap_SendConsoleCommand(et.EXEC_APPEND, "exec commands.txt")
McSteve
Posts: 113
Joined: Tue Sep 12, 2006 7:41 am

Post by McSteve »

The way nano said is the way I would do it. I'm sure there is a simple trigger you can pick up for when the round starts, just look for "FIGHT!" or something.
GhosT:McSteve
Ghostworks Gaming Community
Vetinari
Posts: 1
Joined: Sun Jan 21, 2007 10:38 pm

Post by Vetinari »

Code: Select all

intermission_time = <put_yours_here> * 1000
endofmap = false
function et_Print&#40;text&#41;
    if text == "Exit&#58; Timelimit hit.\n" or text == "Exit&#58; Wolf EndRound.\n" then
        endofmap = true
        next_exec = levelTime + &#40;intermission_time - 5000&#41;
        -- do something here
   end
end
function et_RunFrame&#40;lvltime&#41;
    levelTime = lvltime
    if endofmap then
        if next_exec <= levelTime then
           endofmap = false
           -- do something else here
        end
    end
end
User avatar
ReyalP
Posts: 1663
Joined: Fri Jul 25, 2003 11:44 am

Post by ReyalP »

the gamestate cvar might help you
send lawyers, guns and money
User avatar
Luk4ward
Posts: 236
Joined: Sun Jul 30, 2006 1:55 pm
Location: Poland
Contact:

Post by Luk4ward »

@Vetinari

hmm, nope, doesnt work :(:
inter.lua wrote: intermission_time = 60 * 1000
endofmap = false
function et_Print(text)
if text == "Exit: Timelimit hit.\n" or text == "Exit: Wolf EndRound.\n" then
endofmap = true
next_exec = levelTime + (intermission_time - 5000)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "exec fun_on.cfg")
end
end
function et_RunFrame(lvltime)
levelTime = lvltime
if endofmap then
if next_exec <= levelTime then
endofmap = false
et.trap_SendConsoleCommand(et.EXEC_APPEND, "exec fun_off.cfg")
end
end
end
@ReyalP

hmm, can u explain this?:>I havent seen such cvar...

Regards and thanks for the replies and your ideas
wolFTeam.pl
User avatar
ReyalP
Posts: 1663
Joined: Fri Jul 25, 2003 11:44 am

Post by ReyalP »

gamestate is used by the game to keep track of what state (warmup, playing intermission etc) the game is in. The values are defined by the following enum in q_shared.h

Code: Select all

// NERVE - SMF - wolf server/game states
typedef enum &#123;
	GS_INITIALIZE = -1,
	GS_PLAYING,
	GS_WARMUP_COUNTDOWN,
	GS_WARMUP,
	GS_INTERMISSION,
	GS_WAITING_FOR_PLAYERS,
	GS_RESET
&#125; gamestate_t;
edit:
For the non-C folks, that means GS_INITIALIXE is -1, GS_PLAYING is 0 etc.
send lawyers, guns and money
McSteve
Posts: 113
Joined: Tue Sep 12, 2006 7:41 am

Post by McSteve »

I think I see what you are trying to do Luk4ward, you want some fun settings during warmup yes? Try this:

Code: Select all

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

	gamestate = tonumber&#40;et.trap_Cvar_Get&#40; "gamestate" &#41;&#41;

	if gamestate == 0 then	-- GS_PLAYING 
		et.trap_SendConsoleCommand&#40;et.EXEC_APPEND, "exec fun_off.cfg \n"&#41;
	elseif gamestate == 1 then	-- GS_WARMUP_COUNTDOWN
		et.trap_SendConsoleCommand&#40;et.EXEC_APPEND, "exec fun_on.cfg \n"&#41;
	elseif gamestate == 2 then	-- GS_WARMUP
		et.trap_SendConsoleCommand&#40;et.EXEC_APPEND, "exec fun_on.cfg \n"&#41;
	end

end
I dont know what your server settings are, so I put in both warmup cases (wait for ready or begin countdown immediately).
GhosT:McSteve
Ghostworks Gaming Community
User avatar
Luk4ward
Posts: 236
Joined: Sun Jul 30, 2006 1:55 pm
Location: Poland
Contact:

Post by Luk4ward »

aaa, dnt know about such cvar, thanks for explanation. And thx McSteve for code, its working :). I modified it a bit and tried various ways with tests and still no result, eh

last code:

Code: Select all

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

   gamestate = tonumber&#40;et.trap_Cvar_Get&#40; "gamestate" &#41;&#41;
   
   wuptime=0 
     						if gamestate == 2 then   -- GS_WARMUP
															  							
   							et.trap_SendConsoleCommand&#40;et.EXEC_APPEND, "exec fun_on.cfg \n"&#41;
   							   							    					
      											repeat
      														   	  								    	  										
    	  								  	et.trap_SendConsoleCommand&#40;et.EXEC_APPEND, "cpmsay  \"^3FUN MODE ^2ON ^8&#40;only for warmup&#41;\n\""&#41;
    	  								  	
    	  								  	wuptime=wuptime+5000
    	  										    	  										
    	  								    until wuptime==55000		    
    	  						     	  							
 																		if &#40;wuptime==55000&#41; then    				
 					
 						   											et.trap_SendConsoleCommand&#40;et.EXEC_APPEND, "exec fun_off.cfg \n"&#41;
 						   											
 						   											end	
 						   							 						   											
 						   	end				
    
end
p.s sorry for the mess, but i couldnt post better, eh
wolFTeam.pl
McSteve
Posts: 113
Joined: Tue Sep 12, 2006 7:41 am

Post by McSteve »

I'll offer the following advice for now:

1. Sort your nesting if you want to show your code to anyone else.
2. Write pseudocode before starting any script, no matter how small.
3. Learn that 99% of writing a program/script is all about DEBUGGING (random statistic 4tw).

Someone may be kind enough to write the script for you, but it looks like you are not a million miles from being able to do this yourself. Give it another go and see how you get on.

:)
GhosT:McSteve
Ghostworks Gaming Community
McSteve
Posts: 113
Joined: Tue Sep 12, 2006 7:41 am

Post by McSteve »

Pah, I got bored so here you go. Untested though, gimme a shout if it doesnt work or attempt the debug yourself.

Code: Select all

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

	notify = 0
	local gamestate = tonumber&#40;et.trap_Cvar_Get&#40; "gamestate" &#41;&#41; 

	if gamestate == 0 then   -- GS_PLAYING 
     	et.trap_SendConsoleCommand&#40;et.EXEC_APPEND, "exec fun_off.cfg \n"&#41; 
		notify = 1
	elseif gamestate == 1 then   -- GS_WARMUP_COUNTDOWN 
		et.trap_SendConsoleCommand&#40;et.EXEC_APPEND, "exec fun_on.cfg \n"&#41; 
	elseif gamestate == 2 then   -- GS_WARMUP 
		et.trap_SendConsoleCommand&#40;et.EXEC_APPEND, "exec fun_on.cfg \n"&#41; 
	end 

end 

function et_RunFrame&#40;leveltime&#41;

	if notify == 1 then return end
	if math.mod&#40;leveltime, 5000&#41; ~= 0 then return end
	
	et.trap_SendConsoleCommand&#40;et.EXEC_APPEND, "qsay  \"^3FUN MODE ^2ON ^8&#40;only for warmup&#41;\"\n"&#41;
	
end
GhosT:McSteve
Ghostworks Gaming Community
User avatar
Luk4ward
Posts: 236
Joined: Sun Jul 30, 2006 1:55 pm
Location: Poland
Contact:

Post by Luk4ward »

heh, thx, but i think ill stay with the modification of your first script ;)

cheers
wolFTeam.pl
Post Reply