Jump to content

[Question] Enabling/disabling player damage


kieran

Recommended Posts

Hello, I am working on a DM zone, I was wondering how I could turn damage on/off on a marker hit as the zone is in an interior, here is what I have so far.  (onPlayerWasted will be added once I know how to disable/enable damage.)

--server side script
function DM_Zone(thePlayer)
    if (source == DMOut and getElementType(thePlayer) == "player") then
        setElementPosition(thePlayer, 154.69999694824, 381.70001220703, 905.70001220703)
        setElementFrozen(thePlayer,false)
        setTimer(setElementFrozen, 1000, 1, thePlayer, false)
		getElementPosition(thePlayer, 129.30000305176, 386, 859.20001220703)
        giveWeapon ( thePlayer, 31, 250 ,true )
	elseif (source == DMInt and getElementType(thePlayer) == "player") then
        setElementPosition(thePlayer, 143.390625, 1875.515625, 17.843418121338)
        setElementFrozen(thePlayer,false)
        setTimer(setElementFrozen, 1000, 1, thePlayer, false)
		takeWeapon ( thePlayer, 31 )
    end
end

addEventHandler("onMarkerHit", root, DM_Zone)

it's all working :) just need to know how to correctly use onClientPlayerDamage / onPlayerDamage on marker hits, it is the only thing I've been struggling with.

Link to comment

If i were you, i would create a DM Zone with createColRectangle then attach an eventHandler to it. Give us more info about the DM Zone behaviour. When you get inside, weapons are given to you and damage is enabled or viceversa?

Edited by Chaziz
  • Like 1
Link to comment
addEventHandler ( "onClientPlayerDamage", root,
    function ( attacker, weapon, bodypart, loss )
            if (attacker ) and ( getElementType( attacker ) == "ped" ) then return end
                cancelEvent ()
            end

)

I didn't understand what do you mean exactly but may this help you

You can add a team or group or Element Data

if (getPlayerTeam(source, getTeamFromName("TeamName")) then

 

Edited by xMKHx
Link to comment

I think you would be better off using onClientPlayerDamage since it runs on the client side

--server side script
function DM_Zone(thePlayer)
    if (source == DMOut and getElementType(thePlayer) == "player") then
        setElementPosition(thePlayer, 154.69999694824, 381.70001220703, 905.70001220703)
        setElementFrozen(thePlayer,false)
        setTimer(setElementFrozen, 1000, 1, thePlayer, false)
		getElementPosition(thePlayer, 129.30000305176, 386, 859.20001220703)
        giveWeapon ( thePlayer, 31, 250 ,true )
    	setElementData( thePlayer, "inDMZone", true )
	elseif (source == DMInt and getElementType(thePlayer) == "player") then
        setElementPosition(thePlayer, 143.390625, 1875.515625, 17.843418121338)
        setElementFrozen(thePlayer,false)
        setTimer(setElementFrozen, 1000, 1, thePlayer, false)
		takeWeapon ( thePlayer, 31 )
    	setElementData( thePlayer, "inDMZone", false)
    end
end

addEventHandler("onMarkerHit", root, DM_Zone)


----- client
addEventHandler("onClientPlayerDamage", root, function(att)
    if getElementData(source, "inDMZone") and att and getElementType(att) == "player" then
      cancelEvent()
    end
end)

 

  • Like 1
Link to comment

Not working @pa3ck, My interior is server side and tried to put the client side script in, but doesn't like it.

16 hours ago, Chaziz said:

If i were you, i would create a DM Zone with createColRectangle then attach an eventHandler to it. Give us more info about the DM Zone behaviour. When you get inside, weapons are given to you and damage is enabled or viceversa?

I was going to do a col shape, but that's effort haha, was just wanting it to be, when a player hits first marker, event is triggered/cancelled to allow damage (The outside marker) and when player hits second (interior 0 marker) then the opposite will happens, I can always try put it in a col later :P 

Hope that make sense... 

Edited by kieran
Link to comment

Okay, I just went for col idea and the result was this..

Server Side:.

colarea = createColCuboid ( 108.6396484375, 372.48828125, 855, 40, 52, 55)
colradar = createRadarArea ( 108.6396484375, 372.48828125, 40, 52, 255, 0, 0, 255)
function DME ( thePlayer, matchingDimension )
        giveWeapon ( thePlayer, 31, 250 ,true )
		outputChatBox("You have entered the DM area, damage is active and you have been given weapons.", player, 255, 0, 0)
   		setElementData( thePlayer, "inDMZone", true )
end
addEventHandler ( "onColShapeHit", colarea, DME )

function DML ( thePlayer, matchingDimension )
		takeWeapon ( thePlayer, 31 )
		outputChatBox("You have left the DM area.", player, 0, 255, 0)
		setElementData( thePlayer, "inDMZone", false )
end
addEventHandler ( "onColShapeLeave", colarea, DML )

Client Side:

addEventHandler("onClientPlayerDamage", root, function(att)
    if getElementData(source, "inDMZone") and att and getElementType(att) == "player" then
      cancelEvent()
    end
end)

Unsure if this will work...  But thanks for help guys :D I made progress if nothing else.

 

Feel free to test it!  just set "colarea = createColCuboid ( 108.6396484375, 372.48828125, 855, 40, 52, 55)" to "colarea = createColCuboid ( 108.6396484375, 372.48828125, <Z position here>, 40, 52, 55)" 

Edited by kieran
In case someone stumbles on it and can't create cols yet.
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...