Forum

> > CS2D > Scripts > How to hurt player without explosion (radius) ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to hurt player without explosion (radius) ?

12 replies
To the start Previous 1 Next To the start

old How to hurt player without explosion (radius) ?

KenVo
User Off Offline

Quote
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!

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

EngiN33R
Moderator Off Offline

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

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

KenVo
User Off Offline

Quote
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,

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

KenVo
User Off Offline

Quote
Sunny Autumn has written
KenVo has written
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
Quote
Because it's a table element? But I'm not sure about that either.

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

Flacko
User Off Offline

Quote
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
edited 1×, last 30.03.11 11:29:03 pm

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

DannyDeth
User Off Offline

Quote
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
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview