English Startround hook

5 replies
Goto Page
To the start Previous 1 Next To the start
26.05.16 07:12:14 pm
Up
Waldin
User
Offline Off
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.

Code:
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.
user Waldin (2014) has written:
can be create 3D option for tiles on 3D
user DC (2014) has written:
@user Waldin: This is a 2D game. there are no 3D tiles.
changelog (2017) has written:
ADDED Experimental 3D rendering mode
26.05.16 07:25:39 pm
Up
TrialAndError
User
Offline Off
Edit:

Code:
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
26.05.16 07:27:05 pm
Up
panteon00
User
Offline Off
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.
loading...
26.05.16 07:58:00 pm
Up
Waldin
User
Offline Off
@user TrialAndError: miss in line 12
Code:
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!
user Waldin (2014) has written:
can be create 3D option for tiles on 3D
user DC (2014) has written:
@user Waldin: This is a 2D game. there are no 3D tiles.
changelog (2017) has written:
ADDED Experimental 3D rendering mode
26.05.16 08:01:21 pm
Up
TrialAndError
User
Offline Off
@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
26.05.16 08:31:47 pm
Up
miere
User
Offline Off
You shouldn't do this weird stuff with timers, just invoke gamemode check function when lua script is loaded:
Code:
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