Forum

> > CS2D > Scripts > destructible portal issue
Forums overviewCS2D overview Scripts overviewLog in to reply

English destructible portal issue

3 replies
To the start Previous 1 Next To the start

old destructible portal issue

Zurak
User Off Offline

Quote
portals that are able to be destroyed by the impact of a grenade :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function build(id,kind,x,y,mode,objectid)
		if kind == 23 then
			objectid = b_portal[id]
		end
		if kind == 22 then
			objectid = o_portal[id]
		end
		return 0
	end

	function projectile(id,weapon,x,y)
		if weapon == 51 then
			if object(o_portal[id],"tilex") == x and object(o_portal[id],"tiley") == y then
				killobject(o_portal)
			end
			if object(b_portal[id],"tilex") == x and object(o_portal[id],"tiley") == y then
				killobject(b_portal)
			end
		end
	end
error : nil value for object
main question would be is a portal considered a projectile or an object, seems like it would be both. then how will i be able to hook it?
inb4 no hook/variable set.

old Re: destructible portal issue

MikuAuahDark
User Off Offline

Quote
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
o_portal = {}
b_portal = {}
for id = 1,32 do
	b_portal[id] = 0
	o_portal[id] = 0
end

addhook("build","_build")
function _build(id,kind,x,y,mode,objectid)
	if kind == 23 then
		objectid = b_portal[id]
	end
	if kind == 22 then
 		objectid = o_portal[id]
	end
	return 0
end

addhook("projectile","_projectile")
function _projectile(id,weapon,x,y)
	if weapon == 51 then
		if object(o_portal[id],"tilex") == x and object(o_portal[id],"tiley") == y then
			killobject(o_portal)
		end
		if object(b_portal[id],"tilex") == x and object(o_portal[id],"tiley") == y then
			killobject(b_portal)
		end
	end
end

old Re: destructible portal issue

Zurak
User Off Offline

Quote
>.>
Quote
for id = 1,32 do
b_portal[id] = 0
o_portal[id] = 0
end

this is completely unnecessary, all it does is removes the error because now instead of nil its 0..


edit : i figured it out with just 1 function.
1
2
3
4
5
6
7
8
9
10
11
function projectile(id,weapon,x,y)
		if weapon == 51 then
			for oid = 1,#object(0,"table") do
				if object(oid,"type") == 22 or object(oid,"type") == 23 then
					if math.abs((y-object(oid,"y")) + (x-object(oid,"x"))) < 50 then
						killobject(oid)
					end
				end
			end
		end
	end
edited 1×, last 30.07.12 05:07:13 am

old Re: destructible portal issue

omg
User Off Offline

Quote
.................

couldnt u just set the hp of portals to something like 80? theyre destructible by default (ive accidentally done it before on normal hp, its just really high)

also ur current algorithm will allow HEs to destroy portals thru walls

upon further review, ur algorithm wont even work because oid is just a counter

upon unnecessarily further review, ur algorithms pattern for allowing a HE to destroy a portal is like graphing 1/x and -1/x and rotating it 45 degrees (aka its not even close to being accurate; what were u thinking? if a HE lands on (0,0) in cs2d, it can destroy a portal at tile 30,30 because 1000+-1000=0 (just guessing here) and 0<50)

instead of for oid = 1,#object(0,"table") do,
use for _,oid in pairs(object(0,"table")) do

also use this check:
1
2
3
4
5
6
7
8
9
10
11
12
function checkfreeline(xo,yo,xt,yt)
	local len=math.floor(math.sqrt((xo-xt)^2+(yo-yt)^2))
	local c=-math.atan2(xo-xt,yo-yt)
	local d=math.sin(c)
	local e=-math.cos(c)
	for k=0,len,16 do
		if tile(math.floor((xo+d*k)/32),math.floor((yo+e*k)/32),"wall") then
			return false
		end
	end
	return true
end

instead of using half of the distance formula, use the whole distance formula plz...
edited 2×, last 30.07.12 07:22:35 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview