Forum

> > CS2D > Scripts > freehook and timer ask
Forums overviewCS2D overview Scripts overviewLog in to reply

English freehook and timer ask

6 replies
To the start Previous 1 Next To the start

old freehook and timer ask

tos12345678
User Off Offline

Quote
1. √ I need help with code because not work (when destroy supply)
1
2
3
4
5
6
addhook("objectkill","objectkill_")
function objectkill_(id,player)
     if object(id,"type") == 5 and object(id,"tilex") == 60 then
          freehook("use","camelon")
     end
	 end
How to delete (function use "camelon") when i kill object e.g. x-5 y-60

2. √ Can timer addhook? e.g. addhook will be working for 10 seconds from the start round.

3. √ How to free(delete) image on specific cordinate e.g. x-5 y-60
when destroy supply

old Re: freehook and timer ask

Bowlinghead
User Off Offline

Quote
First: Always read the description of the hook/command cs2d lua hook objectkill , cs2d lua cmd timer , cs2d lua cmd freehook , cs2d lua cmd freeimage , cs2d lua cmd addhook

1.)
Your 3rd line doesnt do sense (?): You only check wether the object is on x = 60.
So your example "x-5 y-60" CANT work because x isnt 60! Typo??!
Usually you check x and y both.


2.) You can only freehook added hooks (of course). You want to addhook "camelon" 10 seconds after you killed a supply center? Try this:
1
2
3
4
5
6
7
8
9
addhook("objectkill","objectkill_")
function objectkill_(id,player)
	if object(id,"type") == 5 and object(id,"tilex") == 60 then
		-- disable button
		freehook("use","camelon")
		-- reactivate after 10 seconds
		timer(10000,"parse","lua addhook('use', 'camelon')") 
	end
end
Note that every CS2D Function is a regular lua function. But because a timer can only pass 1 parameter, I abused the "parse(string)" lua function with only 1 parameter. cs2d cmd parse can execute lua functions with cs2d cmd lua You could also create a new one:
1
2
3
function add_camelon()
	addhook("use","camelon")
end
1
2
-- ... obj- kill hook ...
timer(10000,"add_camelon")
See, no parameter.


3.) Just use cs2d lua cmd freeimage inside of the "objectkill" function.
1
2
3
4
5
6
7
8
9
10
11
addhook("objectkill","objectkill_")
function objectkill_(id,player)
	if object(id,"type") == 5 and object(id,"tilex") == 60 then
		-- disable button
		freehook("use","camelon")
		-- reactivate after 10 seconds
		timer(10000,"parse","lua addhook('use', 'camelon')") 
		-- delete image
		freeimage(someImage)
	end
end

Problems? Copy&Paste red ERROR in console

old Re: freehook and timer ask

tos12345678
User Off Offline

Quote
10 second cooldown on start round to turn on addhook!
And i have problem with freeimage:
imagePath = "gfx/block.bmp"
x = 176
y = 1936
image(imagePath, x, y, 3)
edited 1×, last 25.08.17 07:24:38 pm

old Re: freehook and timer ask

Masea
Super User Off Offline

Quote
You need to name the images first in order to free them:
img = image(imagePath, x, y, 3)


What I just did is I named the image as "img", so if I'd like to free it, I'll use that name:
freeimage(img)


Because user DC made image functions as returning image's ID so whenever we call it via a variable, it gives the ID of an image.

An other example:
1
2
whatthefuckimage = image(imagePath, x, y, 3)
freeimage(whatthefuckimage)

And there are some other things that you should take care while using image function. You can find them in the forum as you actually could find this one either...

old Re: freehook and timer ask

tos12345678
User Off Offline

Quote
Okey its working thanks for help
I waiting on answer for last ask
E.g. Addhook startround
timer 10000 parse lua "use cameleon"
How do it?
edited 1×, last 25.08.17 10:16:22 pm

old Re: freehook and timer ask

tos12345678
User Off Offline

Quote
Solved
What is problem?
1
2
3
4
5
6
7
8
9
addhook("objectkill","objectkill_")
function objectkill_(id,player)
     if object(id,"type") == 5 and object(id,"tilex") == 60 then
          -- disable button
          freehook("use","camelon")
          -- reactivate after 10 seconds
          timer(10000,"parse","lua addhook('use', 'camelon')") 
     end
end

Was space near timer timer(10000,"parse","lua addhook('use', 'camelon')")
edited 2×, last 25.08.17 11:07:16 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview