Forum

> > CS2D > Scripts > destructible portal issue
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch destructible portal issue

3 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt destructible portal issue

Zurak
User Off Offline

Zitieren
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.

alt Re: destructible portal issue

MikuAuahDark
User Off Offline

Zitieren
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

alt Re: destructible portal issue

Zurak
User Off Offline

Zitieren
>.>
Zitat
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
1× editiert, zuletzt 30.07.12 05:07:13

alt Re: destructible portal issue

omg
User Off Offline

Zitieren
.................

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...
2× editiert, zuletzt 30.07.12 07:22:35
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht