Jump to content

Recommended Posts

Posted

Can anyone show me a simple script for making a player lose health if he's in a marker or something. I can't seem to get the player to lose health that way. Basically trying to go for a zone method like PUBG where you lose health over time in a circle.

Posted

Something like this should work:
 

local healthlossTime = 1000
local lastHealthLossTick = 0

function isPlayerInCircle(player, cx,cy,radius)
	local px,py = getElementPosition( player )
	return (getDistanceBetweenPoints2D( px, py, cx, cy ) <= radius)
end

local cx,cy,radius = 0,0,100

function checkPlayerCircleStatus()
	local currentTick = getTickCount()
	if (currentTick - lastHealthLossTick) > healthlossTime then
		if isPlayerInCircle(localPlayer, cx, cy, radius) then
			local health = getElementHealth( localPlayer )
			if health > 0 then
				setElementHealth( localPlayer, health-10 )
			end
			lastHealthLossTick = currentTick
		end
	end
end
addEventHandler( "onClientRender", root, checkPlayerCircleStatus )

For some explanation, this way doesn't use any markers, it uses "onClientRender" event to take 10 health from player every second when he's inside of circle that has center in point "cx,cy", and has radius of "radius". I haven't tested it, but it should work.

  • Thanks 1
Posted

Ah, I thought I'd have to use a ColShape which is what I was trying before. This was a lot more complex than I originally thought. lol

Nice. It works just as I wanted it to. Thanks. :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...