Forum

> > CS2D > Scripts > Spawn BarbWires and Replace
Forums overviewCS2D overview Scripts overviewLog in to reply

English Spawn BarbWires and Replace

3 replies
To the start Previous 1 Next To the start

old Spawn BarbWires and Replace

Jynxxx
User Off Offline

Quote
In this code i was trying to spawn a barbwire on the trigger_use, everything works but i want to remove the barbwire from the tile it is on and replace it with a new one. Please Help me, Thank You.

1
2
3
4
5
6
7
8
addhook("usebutton","barbiredwire")
function barbiredwire(id,x,y)
	if entity(x,y,"name")=="barb" then
		it = player(id,"team")
		parse("killobject "..id")
		parse("spawnobject 2 "..x.." "..y.." 0 0 "..it.." "..id)
	end
end

old Re: Spawn BarbWires and Replace

MikuAuahDark
User Off Offline

Quote
you don't need lua script to do this!
just do this in editor:
Put Trigger_Use, name: <empty> trigger: wire
then put Env_Building, name: wire building: 2 - BarbedWire
and it's done!

old Re: Spawn BarbWires and Replace

White_12E_456_789
BANNED Off Offline

Quote
@user MikuAuahDark: yeah But if the button is inside you will press it right if you start it in the trigger it will go INVISIBLE right. thats why we need lua script so if the building is start then press the button and then the building will not go VISIBLE!!

old Re: Spawn BarbWires and Replace

Jynxxx
User Off Offline

Quote
ok i got it ill post it here to save everyone the trouble
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
addhook("usebutton","barbiredwire")
function barbiredwire(id,x,y)
if entity(x,y,"name")=="barb" then
		for _,p in ipairs(object(0,"table")) do
			if object(p,"tilex") == x and object(p,"tiley") == y then
				parse("killobject "..p)
			end
		end
		parse("spawnobject 2 "..x.." "..y)
	end
end


addhook("movetile","Barbed_knockBack")
function Barbed_knockBack(id,x,y)
	local state = true
	for _,p in ipairs(object(0,"table")) do
		if object(p,"tilex") == x and object(p,"tiley") == y and object(p,"typename") == "Barbed Wire" then
			parse("setpos "..id.." "..((KnockBackPos[id][1]*32)+16).." "..((KnockBackPos[id][2]*32)+16))
			state = false
		end
	end	
	if state then
		KnockBackPos[id] = {x,y}
	end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview