Jump to content

Health Help


Recommended Posts

Okay I made a script that is supposed to give a player back his health when he gets damaged, but it isn't working! :(

The files are below:

hp.lua

--add an event handler for the onPlayerDamage event
function hp ( attacker, weapon, bodypart, loss ) --when a player is damaged
if (isObjectInACLGroup ("user."..getAccountName(getPlayerAccount(source)),aclGetGroup("Admin"))) then
setElementHealth(source, getElementHealth(source)+loss)
if (getElementType( attacker ) == "player" then
setElementHealth(attacker, getElementHealth(source)-loss)
end
end
end
addEventHandler ( "onPlayerDamage", getRootElement (), hp )

meta.xml

<meta>
 
<info author="Cecil G. Bowen" type="script" version="1.0" description="Infinite Health"/>
 
<script src="hp.lua" type="server"/>
 
</meta>

Thanks in advance.

Link to comment
function hp ( attacker, weapon, bodypart, loss ) --when a player is damaged
if (isObjectInACLGroup ("user."..getAccountName(getPlayerAccount(source)),aclGetGroup("Admin"))) then
setElementHealth(source, getElementHealth(source)+loss)
if getElementType( attacker ) == "player" then -- Here was a unneeded "(" after "if".
setElementHealth(attacker, getElementHealth(source)-loss)
end
end
end

Link to comment

@ Ca11um: No he can't. He want's to check if the hitted player is an admin, and that are some serverside functions. It's possible to use triggerServerEvent for that, but since this is about onPlayerDamage, it would cause a lot of bandwidth usage. It's better to prevent that.

But, the onPlayerDamage event can't be canceled to prevent the hitted player for losing health. And, if the admin in your script has less health than the loss will be, the admin will still die. I recommend the following script for you:

function preventAdminShooting ( target ) -- The source here will be the player who is aiming
if getElementType ( target ) == "player" then -- If the targetted element is a player
if ( isObjectInACLGroup ( "user."..getAccountName ( getPlayerAccount ( target ) ), aclGetGroup ( "Admin" ) ) ) then -- If that player is an admin
toggleControl ( source, "fire", false ) -- We will disable his fire key
end
else
toggleControl ( source, "fire", true ) -- But when he aims to someone else, we enable it.
--We do this outside the check for the admin, otherwise the player can't shoot anymore when aimin at something else than a player 
end
end
addEventHandler ( "onPlayerTarget", getRootElement(), preventAdminShooting ) -- Adding the event handler ofcourse

Link to comment

Than you can always use the onPlayerDamage event. You can prevent shooting rocketlaunchers by having a bit more complicated script, but if some other player stands next to an admin, he wont get hurt either. So I would stick to the two scripts we made now: The onPlayerTarget event, and the onPlayerDamage event. If you don't care about that player that stands next to the admin, let me know, and I'll make an example script for you ;)

Link to comment

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