Forum

> > CS2D > Scripts > How to hurt player without explosion (radius) ?
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch How to hurt player without explosion (radius) ?

12 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt How to hurt player without explosion (radius) ?

KenVo
User Off Offline

Zitieren
Hi guys, I'm trying to make a script that hurt any player that stands next to me when I say "!hurt" but without an explosion. I tried this: (I'm learning lua)
1
2
3
4
5
6
function radiusdmg(, x, y, radiusx, radiusy)
	if not (radiusx and radiusy) then radiusx, radiusy = 320, 240 end
	local x1, y1, x2, y2 = x-radiusx, y-radiusy, x+radiusx, y+radiusy
	for _, v in ipairs(player(0, 'table')) do
		if player(v, 'x') >= x1 and player(v, 'x') <= x2 and player(v, 'y') >= y1 and player(v, 'y') <= y2 then
........I don't know what to write next

I'm making this script because I don't like the explosion and its "shaking screen". Anything you can do would be great!

alt Re: How to hurt player without explosion (radius) ?

EngiN33R
Moderator Off Offline

Zitieren
1
2
3
4
5
6
7
8
function radiusdmg(dmg, x, y, radiusx, radiusy)
     if not (radiusx and radiusy) then radiusx, radiusy = 320, 240 end
     local x1, y1, x2, y2 = x-radiusx, y-radiusy, x+radiusx, y+radiusy
     for _, v in pairs(player(0, 'table')) do
          if player(v, 'x') >= x1 and player(v, 'x') <= x2 and player(v, 'y') >= y1 and player(v, 'y') <= y2 then
		parse("sethealth "..v.." "..(player(id,"health")-dmg))
	end
end
Dunno, should work.

alt Re: How to hurt player without explosion (radius) ?

KenVo
User Off Offline

Zitieren
LUA ERROR: attempt to perform arithmetic on local 'x' (a nil value)

My function:
1
2
3
4
5
6
7
8
9
function radiusdmg(dmg, x, y, radiusx, radiusy)
	if not (radiusx and radiusy) then radiusx, radiusy = 320, 240 end
	local x1, y1, x2, y2 = x-radiusx, y-radiusy, x+radiusx, y+radiusy
	for _, v in pairs(player(0, 'table')) do
		if player(v, 'x') >= x1 and player(v, 'x') <= x2 and player(v, 'y') >= y1 and player(v, 'y') <= y2 then
          parse("sethealth "..v.." "..(player(id,"health")-dmg))
		end
	end
end

My command(not the whole script)
1
2
3
4
5
6
7
8
['hurt'] = function(id, p)
		if player(id,"exists") then
			if player(id, "health") > 0 then
				local dmg = 50
				radiusdmg(dmg, x, y, radiusx, radiusy)
			end
		end
	end,

alt Re: How to hurt player without explosion (radius) ?

KenVo
User Off Offline

Zitieren
Sunny Autumn hat geschrieben
KenVo hat geschrieben
1
end,

Why is there a comma there?



This is the answer, like what I said that wasn't the whole script and the command work fine but the thing is the function is not working
Zitat
Because it's a table element? But I'm not sure about that either.

alt Re: How to hurt player without explosion (radius) ?

Flacko
User Off Offline

Zitieren
OMG, you're calling some variables radiusx and radiusy (WTF) and you're using bounding boxes. If you don't name your variables properly you'll only get to confuse people...

Here's a function that should support both bounding box and circular detection

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function zonedmg(dmg, x,y, _x, _y)
	local D = function(id) --local function that returns the distance between a player id and the circle's center using pithagoras' shit
		return math.sqrt((player(id,"x")-x)^2 + (player(id,"y")-y)^2) < _x
	end
	if _y then --square
		D = function(id)
			return (player(id,"x") > x) and (player(id,"x") < _x) and (player(id,"y") > y) and (player(id,"y") < _y)
		end
	end
	for k,id in pairs(player(0,"tableliving")) do
		if D(id) then
			parse("sethealth "..id.." "..player(id,"health") - dmg)
		end
	end
end
1× editiert, zuletzt 30.03.11 23:29:03

alt Re: How to hurt player without explosion (radius) ?

DannyDeth
User Off Offline

Zitieren
Here's a simple way of doing it:
1
2
3
4
5
6
7
8
9
10
function radial_dmg(x,y,radius,damage)
	for _,#player(0,"tableliving"),1 do
		local distance = math.sqrt( ( player(i,"x") - x )^2 + ( player(i,"y") - y )^2
		if distance <= radius then
			parse("set_health "..i.." "..( player(i,"health") - damage ))
		else
			return
		end
	end
end
It's simple but it works fine
You call the function like so:
1
radial_dmg(x-position,y-position,radius,damage)

Hope it helped
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht