Jump to content

No damage within marker


goofie88

Recommended Posts

Posted

Hello everyone I have a question, how to make so theres no damage when a player enters a marker? I was confused because onPlayerDamage and onMarkerHit are 2 different events how could I combine them?

Posted
isElementWithinMarker 

So

theMarker = createMarker(x, y, z, "cylinder") 
addEventHandler("onClientPlayerDamage", root, 
function(attacker, weapon, bodypart, loss) 
if (isElementWithinMarker(source, theMarker)) then 
cancelEvent() 
end 
end 
) 

Posted
Yes it worked when client side but I have my marker in server side and everything is based on server side so actually it didnt really work
addEventHandler("onClientPlayerDamage", root, 
function(attacker, weapon, bodypart, loss) 
if (isElementWithinMarker(source, theMarker)) then 
cancelEvent() 
end 
end 
) 

Line 4 --> Replace theMarker with your marker name .

-- Server 
addEventHandler( "onMarkerHit", root, 
    function ( player ) 
        if ( getElementType ( player ) == "player" ) then 
            triggerClientEvent( "onClientPlayerDamage", getRootElement( ), player ) 
        end 
    end 
) 

Line 2 --> Replace root with your marker name .

Posted
Yes it worked when client side but I have my marker in server side and everything is based on server side so actually it didnt really work
addEventHandler("onClientPlayerDamage", root, 
function(attacker, weapon, bodypart, loss) 
if (isElementWithinMarker(source, theMarker)) then 
cancelEvent() 
end 
end 
) 

Line 4 --> Replace theMarker with your marker name .

-- Server 
addEventHandler( "onMarkerHit", root, 
    function ( player ) 
        if ( getElementType ( player ) == "player" ) then 
            triggerClientEvent( "onClientPlayerDamage", getRootElement( ), player ) 
        end 
    end 
) 

Line 2 --> Replace root with your marker name .

Wrong,The code is not complete .

Posted

Wrong,The code is not complete .

Then fix it, And show me my errors please :D

isElementWithinMarker(source,theMarker)

you use it on the client side and the marker isn,t on the client side you will get BadArg if you do it :P .

Posted

Thanks for trying to help me Mr.ALM but everyone within marker is still vulnerable to damage even when i replaced source to localPlayer in client side script

Posted

I had some errors like Mr.Pres[T]ege said, That why it didn't work :{

But i tried to fix it and i came up with this code :P :

-- Server : 
  
marker = creatMarker( X, Y, Z, "cylinder" ) 
  
addEventHandler( "onMarkerHit", marker,  
    function ( player ) 
        if ( getElementType ( player ) == "player" ) then 
            if isElementWithinMarker ( player, marker ) then 
                triggerClientEvent( "onClientPlayerDamage", getRootElement( ), player ) 
            end 
        end 
    end 
) 
  
-- Client : 
  
addEventHandler( "onClientPlayerDamage", root, 
    function ( player ) 
        cancelEvent ( ) 
    end 
) 

fix any errors please ..

Posted
-- Server : 
  
marker = creatMarker( X, Y, Z, "cylinder" ) 
  
addEventHandler( "onMarkerHit", marker, 
    function ( player ) 
        if ( getElementType ( player ) == "player" ) then 
            if isElementWithinMarker ( player, marker ) then 
                triggerClientEvent( "onClientPlayerDamage", getRootElement( ), player ) 
            else 
                cancelEvent( "onClientPlayerDamage", true ) 
            end 
        end 
    end 
) 
  
  
-- Client : 
  
addEventHandler( "onClientPlayerDamage", root, 
    function ( player ) 
        cancelEvent ( ) 
    end 
) 
  

Posted
-- Server : 
  
marker = creatMarker( X, Y, Z, "cylinder" ) 
  
addEventHandler( "onMarkerHit", marker, 
    function ( player ) 
        if ( getElementType ( player ) == "player" ) then 
            if isElementWithinMarker ( player, marker ) then 
                triggerClientEvent( "onClientPlayerDamage", getRootElement( ), player ) 
            end 
        end 
    end 
) 
  
addEventHandler( "onMarkerLeave", marker, 
    function ( player ) 
        if ( getElementType ( player ) == "player" ) then 
            cancelEvent( "onClientPlayerDamage", true )  
        end 
    end 
) 
  
-- Client : 
  
addEventHandler( "onClientPlayerDamage", root, 
    function ( player ) 
        cancelEvent ( ) 
    end 
) 

Posted

Confuses me why you guys dont do it all serversided? Giving the element a data when he hits the marker and when he leave the marker removes it. Use onPlayerDamage and getElementData to check if the player should be hurt or not, if not then cancelEvent()

Done.

Posted
Confuses me why you guys dont do it all serversided? Giving the element a data when he hits the marker and when he leave the marker removes it. Use onPlayerDamage and getElementData to check if the player should be hurt or not, if not then cancelEvent()

Done.

Because i have been told that you can't cancel onPlayerDamage event .

But if you meant any other way, Then make your code and lay it for us so we can learn :D

Posted
Confuses me why you guys dont do it all serversided? Giving the element a data when he hits the marker and when he leave the marker removes it. Use onPlayerDamage and getElementData to check if the player should be hurt or not, if not then cancelEvent()

Done.

Because i have been told that you can't cancel onPlayerDamage event .

But if you meant any other way, Then make your code and lay it for us so we can learn :D

  
marker = createMarker(x,y,z,"cylinder") 
  
function hitMarker(hitElement) 
if getElementType(hitElement) == "player" then 
setElementData(hitElement, "godmode", true) 
  
end 
end 
addEventHandler('onMarkerHit', marker, hitMarker) 
  
function leaveMarker(hitElement) 
if getElementType(hitElement) == "player" then 
removeElementData(hitElement, "godmode") 
  
end 
end 
addEventHandler('onMarkerLeave', marker, leaveMarker) 
  
  
  
client:: 
  
function onDamage() 
if getElementData(source, "godmode") then 
cancelEvent() 
end 
end 
addEventHandler('onClientPlayerDamage', getLocalPlayer, onDamage) 
  
  

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