Forum

> > CS2D > Scripts > Startround hook
Forums overviewCS2D overview Scripts overviewLog in to reply

English Startround hook

5 replies
To the start Previous 1 Next To the start

old Startround hook

Waldin
User Off Offline

Quote
Hello im here again (im making a script and i need alot of help xd) asking us community for help ;p
im trying to detect if the gamemode is or isnt standard with the hook startround.

1
2
3
4
5
6
7
8
9
10
11
addhook('startround','help_start')
function help_start()
	local ccode = string.char(169)
	local gm = tonumber(game('sv_gamemode')) -- game() returns a string.
	if gm ~= 0 then
		msg(ccode.."255000000Script doesn't support this game mode.")
		timer(10000,'parse','sv_gamemode 0')
	elseif gm == 0 then
		-- My script.
	end
end

This code only works when i restart the sv, not in first round, how do i do to solve this?
Sorry for typos and bad english xd.

old Re: Startround hook

TrialAndError
User Off Offline

Quote
Edit:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
gm = 0

timer(1000,"a") -- This will run in the beggining only

addhook("startround","id") -- After the timer is ran, this should work for every other round.
function id()
	a()
end
	

function a()
	if #game("sv_gamemode") ~= gm then
		timer(1000,"parse","sv_gamemode 0") 
	end
end
edited 1×, last 26.05.16 07:36:33 pm

old Re: Startround hook

Cebra
User Off Offline

Quote
i dont know how you can solve this,
but i think it doesn't work because due the start, the script will be read, so it's "too late" to excute them.

old Re: Startround hook

Waldin
User Off Offline

Quote
@user TrialAndError: miss in line 12
1
if #game("sv_gamemode") ~= gm then
# returns the lenght of a variable (if the string hi is 'hello' then #hi will be 5). I replaced it with tonumber()

Thanks you, it works nice!

old Re: Startround hook

TrialAndError
User Off Offline

Quote
@user Waldin: The only important thing in the code was the first timer, the rest was just to demonstrate.
But it's true, it returns string length

old Re: Startround hook

miere
User Off Offline

Quote
You shouldn't do this weird stuff with timers, just invoke gamemode check function when lua script is loaded:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
addhook('startround','help_start')
function help_start()
     local ccode = string.char(169)
     local gm = tonumber(game('sv_gamemode')) -- game() returns a string.
     if gm ~= 0 then
          msg(ccode.."255000000Script doesn't support this game mode.")
          timer(10000,'parse','sv_gamemode 0')
     elseif gm == 0 then
          -- My script.
     end
end

-- this function will execute only once
-- in first round.
help_start()
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview