The main idea I have in my mind is to give player random amount of money for killing enemy which ranges from 600 to 800 (default 300 included). Hope you help me, thanks.
Forum




Need Example of "Kill" hook.
9 replies



The main idea I have in my mind is to give player random amount of money for killing enemy which ranges from 600 to 800 (default 300 included). Hope you help me, thanks.
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
addhook("kill", "money_kill") function money_kill(id, victim, weapon, x, y) 	msg(player(id,"name").. " killed " ..player(victim, "name").." with weapon ID "..weapon) 	msg(player(victim, "name") .. " was on coordinates: X:"..x.." Y:"..y) 	parse("setmoney "..id.." "..player(id, "money")+math.random(1,600)) end
edited 1×, last 23.02.13 11:13:28 pm
EDIT : It appears it's not working...
The message things work correctly but I do not get any bonus gold at all..


So it basically gives 1-600 extra money to the killer right now.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
--------------------------- --- BUILDINGS MENU 1st ---- --------------------------- addhook("menu","Buildings") function Buildings(id,title,button) sx = player(id,"x") sy = player(id,"y") st = player(id,"team") 	if title=="Make Buildings" then 	 if button==1 then 	 if (player(id,"health")>0 and player(id,"team")>0) then 		if not entity((sx/32)+1,(sy/32)+1,"exists") then 		parse("spawnobject 1 "..((sx/32)-1).." "..((sy/32)+1).." 0 0 "..st.." "..id) -- Left Corner Top 			parse("spawnobject 1 "..((sx/32)-1).." "..((sy/32)-1).." 0 0 "..st.." "..id) -- Left Corner Bot 			parse("spawnobject 1 "..((sx/32)+1).." "..((sy/32)+1).." 0 0 "..st.." "..id) -- Right Corner Top 			parse("spawnobject 1 "..((sx/32)+1).." "..((sy/32)-1).." 0 0 "..st.." "..id) -- Right Corner Bot 			parse("spawnobject 6 "..((sx/32)-1).." "..((sy/32)).." 0 0 "..st.." "..id) -- Player Position X - 1 			parse("spawnobject 6 "..((sx/32)).." "..((sy/32)-1).." 0 0 "..st.." "..id) -- Player Position Y - 1 			parse("spawnobject 6 "..((sx/32)+1).." "..((sy/32)).." 0 0 "..st.." "..id) -- Player Position X + 1 			parse("spawnobject 6 "..((sx/32)).." "..((sy/32)+1).." 0 0 "..st.." "..id) -- Player Position Y + 1 			parse("spawnobject 6 "..((sx/32)).." "..((sy/32)+).." 0 0 "..st.." "..id) -- Where Player is Standing 	end 	 end 	 end
Don't mind the missing IFs because it's just a part of whole menu (only button one particulary) I'd really wish to be able to have something to help me shorten this. At MOST it would be a total of 49 entities (49 buildings) so I'd have to write this so many times
1
if not entity((sx/32)+1,(sy/32)+1,"exists")

1
if not entity((sx/32)+1,(sy/32)+1,"exists") then

I would make a table with predefined coordinates and then check everyone of them and place the building if there's no entity.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
coordinates = { 	x={}, 	y={} } function add_coordinates(x,y) 	coordinates.x[ (#coordinates.x+1) ] = x --add to the table as the last entry 	coordinates.y[ (#coordinates.y+1) ] = y end add_coordinates(-1,-1) add_coordinates(1,1) add_coordinates(1,-1) add_coordinates(-1,0) add_coordinates(0,-1) add_coordinates(1,0) add_coordinates(0,1) add_coordinates(0,0) --... many, many lines of code later local sTileX = player(id,"tilex") local sTileY = player(id,"tiley") for i=1,3 do 	if not entity(sTileX + coordinates.x[i], sTileY + coordinates.y[i], "exists") then 		parse("spawnobject 1 "..sTileX + coordinates.x[i].." "..sTileY + coordinates.y[i].." 0 0 "..st.." "..id) 	end end for i=4,9 do --because 1-3 are occupied 	if not entity(sTileX + coordinates.x[i], sTileY + coordinates.y[i], "exists") then 		parse("spawnobject 6 "..sTileX + coordinates.x[i].." "..sTileY + coordinates.y[i].." 0 0 "..st.." "..id) 	end end
3)
1
2
3
2
3
local sx = player(id,"x") local sy = player(id,"y") local st = player(id,"team")
ALWAYS, make variables you will only use in the current function as local ones. It's faster, it doesn't create trash.
edited 1×, last 24.02.13 12:23:37 am



Honestly. I read the whole code you pasted and understood somewhat 1-4 and all others after 21... What is that "[ (#coordinates.x+1) ] = x" ??? And what it does..?

1) No, every building will appear as long as you're not trying to build it on an entity or wall
2) Yep. Forgot the two "end"
3) You have to hardcode it. It means, you add 3 different positions with add_coordinates() as first, then you will need a for i=1,3 to get the first three coordinates. If you add more, you need an another for loop to add them
1
2
3
4
2
3
4
-- added 11 coordinates to table for i=1,3 do 	print(coordinates.x[i] .." "..coordinates.y[i]) --print the first 3 added positions end
4) Nothing's bad about. It just adds the entries to table in a different way. Just skip this part.

In my last reply all you have to do is to execute lines 21-33.
I just have to paste those lines in my code to check if there's an entity at one tile away from me ? Still very hard for me to understand

http://pastebin.com/yyS1j8Ls
After you load it, write in console:
lua build_all(1,"turrets")
and
lua build_all(1,"gates")



