Jump to content

[Help] Cancel Event


3B00DG4MER

Recommended Posts

Hello,today I've made script which if player within colshap Cancel Event of Damage and Wasted

All Things Works only Cancel Event

Please Reply Fast

function protect() 
if isElementWithinColShape ( localPlayer, CSSZ1 ) then 
local sWidth,sHeight = guiGetScreenSize() -- The variables 
dxDrawText("Protected Area Comp",sWidth*0.668, sHeight*0.952, sWidth*0.715, sHeight*0.997,tocolor(0,255,0,255),1.0,"pricedown","left","bottom",false,false,false) 
addEventHandler("onClientPedDamage", getRootElement(),function() 
cancelEvent() 
end) 
  
addEventHandler("onClientPedWasted", getRootElement(),function() 
cancelEvent() 
end) 
  
end 
end 
  
  
addEventHandler ( "onClientRender", root, protect ) 

Link to comment

Try using this, although, I didn't test it.

-- Server: 
-- create your colshape 
function onColEvent( p ) 
    if ( getElementType ( p ) == "vehicle" ) then 
        p = getVehicleOccupant ( p ) 
    end 
     
    if ( not isElement ( p ) ) then 
        return 
    end 
     
    if ( eventName == "onColShapeHit" ) then 
        setElementData ( p, "isClientInProtectedArea", true ) 
    else 
        setElementData ( p, "isClientInProtectedArea", false ) 
    end 
    triggerClientEvent ( p, "onClientProtectedAreaEventChange", p, eventName ) 
end 
addEventHandler ( "onColShapeHit", CSSZ1, onColEvent ) 
addEventHandler ( "onColShapeLeave", CSSZ1, onColEvent ) 
  
  
-- client 
addEventHandler ( "onClientPlayerDamage", root, function ( ) 
    if ( getElementData ( source, "isClientInProtectedArea" ) ) then 
        cancelEvent ( ) 
    end 
end ) 
  
addEvent ( "onClientProtectedAreaEventChange", true ) 
addEventHandler ( "onClientProtectedAreaEventChange", root, function ( e ) 
    if ( e == "onColShapeHit" and not isRender ) then 
        render = true 
        addEventHandler ( "onClientRender", root, onClientRender ) 
    elseif ( e == "onColShapeLeave" ) then 
        render = false 
    end 
end ) 
  
local isRender = false 
local sWidth,sHeight = guiGetScreenSize() 
function onClientRender ( ) 
    if ( not isRender ) then 
        removeEventHandler ( "onClientRender", root, onClientRender ) 
    end 
    dxDrawText("Protected Area Comp",sWidth*0.668, sHeight*0.952, sWidth*0.715, sHeight*0.997,tocolor(0,255,0,255),1.0,"pricedown","left","bottom",false,false,false) 
end 
  

Link to comment
Try using this, although, I didn't test it.
-- Server: 
-- create your colshape 
function onColEvent( p ) 
    if ( getElementType ( p ) == "vehicle" ) then 
        p = getVehicleOccupant ( p ) 
    end 
     
    if ( not isElement ( p ) ) then 
        return 
    end 
     
    if ( eventName == "onColShapeHit" ) then 
        setElementData ( p, "isClientInProtectedArea", true ) 
    else 
        setElementData ( p, "isClientInProtectedArea", false ) 
    end 
    triggerClientEvent ( p, "onClientProtectedAreaEventChange", p, eventName ) 
end 
addEventHandler ( "onColShapeHit", CSSZ1, onColEvent ) 
addEventHandler ( "onColShapeLeave", CSSZ1, onColEvent ) 
  
  
-- client 
addEventHandler ( "onClientPlayerDamage", root, function ( ) 
    if ( getElementData ( source, "isClientInProtectedArea" ) ) then 
        cancelEvent ( ) 
    end 
end ) 
  
addEvent ( "onClientProtectedAreaEventChange", true ) 
addEventHandler ( "onClientProtectedAreaEventChange", root, function ( e ) 
    if ( e == "onColShapeHit" and not isRender ) then 
        render = true 
        addEventHandler ( "onClientRender", root, onClientRender ) 
    elseif ( e == "onColShapeLeave" ) then 
        render = false 
    end 
end ) 
  
local isRender = false 
local sWidth,sHeight = guiGetScreenSize() 
function onClientRender ( ) 
    if ( not isRender ) then 
        removeEventHandler ( "onClientRender", root, onClientRender ) 
    end 
    dxDrawText("Protected Area Comp",sWidth*0.668, sHeight*0.952, sWidth*0.715, sHeight*0.997,tocolor(0,255,0,255),1.0,"pricedown","left","bottom",false,false,false) 
end 
  

There is Bug

When Col Shape Leave

Please Fix FAST

Link to comment
  • Moderators
    -- Server: 
    -- create your colshape 
    function onColEvent( p ) 
        if ( getElementType ( p ) == "vehicle" ) then 
            p = getVehicleOccupant ( p ) 
        end 
        
        if ( not isElement ( p ) ) then 
            return 
        end 
        
        if ( eventName == "onColShapeHit" ) then 
            setElementData ( p, "isClientInProtectedArea", true ) 
        else 
            setElementData ( p, "isClientInProtectedArea", false ) 
        end 
        triggerClientEvent ( p, "onClientProtectedAreaEventChange", p, eventName ) 
    end 
    addEventHandler ( "onColShapeHit", CSSZ1, onColEvent ) 
    addEventHandler ( "onColShapeLeave", CSSZ1, onColEvent ) 
      
      
    -- client 
    addEventHandler ( "onClientPlayerDamage", root, function ( ) 
        if ( getElementData ( source, "isClientInProtectedArea" ) ) then 
            cancelEvent ( ) 
        end 
    end ) 
      
    addEvent ( "onClientProtectedAreaEventChange", true ) 
    addEventHandler ( "onClientProtectedAreaEventChange", root, function ( e ) 
        if ( e == "onColShapeHit" and not isRender ) then 
           [color=#FF0000] render = true[/color] 
            addEventHandler ( "onClientRender", root, onClientRender ) 
        elseif ( e == "onColShapeLeave" ) then 
           [color=#FF0000] render = false[/color] 
        end 
    end ) 
      
    [color=#FF8000]local[/color] [color=#FF0000]isRender = false[/color] 
    local sWidth,sHeight = guiGetScreenSize() 
    function onClientRender ( ) 
        if ( not [color=#FF0000]isRender[/color] ) then 
            removeEventHandler ( "onClientRender", root, onClientRender ) 
        end 
        dxDrawText("Protected Area Comp",sWidth*0.668, sHeight*0.952, sWidth*0.715, sHeight*0.997,tocolor(0,255,0,255),1.0,"pricedown","left","bottom",false,false,false) 
    end 
      

It is obviously.

The names don't match and the variable should be on top of the code (local variables).

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