Help create script.When the health zombies is below 30%, he teleports to the player who attacked him and explodes!
Forum
Scripts
Zombie script
Zombie script
21 repliesHelp create script.When the health zombies is below 30%, he teleports to the player who attacked him and explodes!
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
function __hit(id, s)
	-- check if player is zombie and if health is below 30
	if ( player(id, "team") == 1 and player(id, "health") < 30 ) then
		-- get source player's pos
		local x, y = player(s, "x"), player(s, "y")
		-- teleport zombie
		parse("setpos "..id.." "..x.." "..y)
		-- explosion
		parse("explosion "..x.." "..y.." 100 50 "..id)
	end
end
addhook("hit", "__hit")
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
function __hit(id, s)
-- check if player is zombie and if health is below 30
if ( player(id, "team") == 1 and player(id, "health") < 30 and player(id, "name") == "LOL" ) then
-- get source player's pos
local x, y = player(s, "x"), player(s, "y")
-- teleport zombie
parse("setpos "..id.." "..x.." "..y)
-- explosion
parse("explosion "..x.." "..y.." 100 50 "..id)
end
end
addhook("hit", "__hit")
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
function __hit(id, s)
-- check if player is zombie and if health is below 30
if ( player(id, "team") == 1 and player(id, "health") < 30 and player(id, "bot") ) then
-- get source player's pos
local x, y = player(s, "x"), player(s, "y")
-- teleport zombie
parse("setpos "..id.." "..x.." "..y)
-- explosion
parse("explosion "..x.." "..y.." 100 50 "..id)
end
end
addhook("hit", "__hit")
At
archmage reply: you must check if player exists, otherwise cs2d would get position of not existing player, what lead to bugs. (teleport to random position for example). Help create script.When a player moves on the tile # 20, the image is removed, but when to leave the tile # 20, the image is back!
Autumn has writtenWhen a player moves on the tile # 20, the image is removed, but when to leave the tile # 20, the image is back!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
imgs={}
for id = 1,32 do
imgs[id]=0
end
addhook("movetile","_movetile")
function movetile(id,tx,ty)
	if tile(tx,ty,"frame")~=20 then
		if imgs[id]==0 then
			imgs[id]=image("imagepath",1,0,132+id)
		end
	elseif tile(tx,ty,"frame")==20 then
		if imgs[id]>0 then
			freeimage(imgs[id])
			imgs[id]=0
		end
	end
end
LUA ERROR: attempt to call a nil value
1
function _movetile(id,tx,ty)
Avo has writtenNope. You just can chceck if player name´s first 3 chars are "LoL". Changing name during game is not a good idea.
How so?
1
parse("setname "..botid.." LOL")
That will change the name of the bot, provided you replace botid with an actual variable. Not much voodoo involved, and it won't break the game.
Oh, and please, create a new thread for each question with a title describing the question itself. It will be better for everyone that way.
7749 has written
Not much voodoo involved, and it won't break the game.
Voodoo, I lol'd.
EngiN33R, yes, creating new threads is better to find in forum answer for question, asked some time ago. 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
imgs={}
for id = 1,32 do
imgs[id]=0
end
addhook("movetile","_movetile")
function _movetile(id,tx,ty)
if tile(tx,ty,"frame")~=20 then
if imgs[id]==0 then
imgs[id]=image("imagepath",1,0,132+id)
end
elseif tile(tx,ty,"frame")==20 then
if imgs[id]>0 then
freeimage(imgs[id])
imgs[id]=0
end
end
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
imgs={}
for id = 1,32 do
imgs[id]=0
end
tilepenghilang = {114,85}
addhook("movetile","_movetile")
function _movetile(id,tx,ty)
	for _, tiles in pairs(tilepenghilang) do
		if tile(tx,ty,"frame")~=tiles then
			if imgs[id]==0 then
				imgs[id]=image("imagepath",1,0,132+id)
			end
		elseif tile(tx,ty,"frame")==tiles then
			if imgs[id]>0 then
				freeimage(imgs[id])
				imgs[id]=0
			end
		end
	end
end
EDIT: Fixed bugs
edited 1×, last 17.07.12 11:52:15 am
1 
Offline