Jump to content

addEventHandler [HELP]


Recommended Posts

idk if i get you but are you looking for this?

local functionEnabled = false 
  
function vehicleEntry() 
    if ( functionEnabled =~ false ) then 
        outputChatBox("I picket a car!", source) -- or triggerEvent or whatever you want. 
        return true; 
    end 
    return false; 
end 
addEventHandler ("onPlayerVehicleEnter", root, vehicleEntry) 
  
addCommandHandler("enablefunction", function(player,cmd) -- it gonna activate that function who is disabled. 
    functionEnabled = not functionEnabled; 
end) 

Link to comment
Can you post any code?
---on resource start i want damageproof disabled as default. 
function carGodMode(playerSource) 
---i have my functions here which i cant post 
end 
  
function carNoGodMode(playerSource) 
---i have my functions here which i cant post 
end 
  
function vehicleEntry (playerSource) 
if function carGodMode then 
    setVehicleDamageProof(getPedOccupiedVehicle(playerSource),true) 
elseif function carNoGodMode then 
    setVehicleDamageProof(getPedOccupiedVehicle(playerSource),false) 
end 
addEventHandler ("onVehicleEnter", root, vehicleEntry) 

Link to comment

Well functions are not boolean values by the way you should change carGodMod and carNoGodMod to bool not function like

  
carGodMod = true 
  

when you need to enable the god mod and set it to false when you need to disable it

Link to comment
  • Moderators
function carGodMode(vehicle,playerSource) 
    ---i have my functions here which i cant post 
  
    -- example = 
    if true then 
        return true 
    end 
    return false 
    ------------ 
  
end 
      
function carNoGodMode(vehicle,playerSource) 
    ---i have my functions here which i cant post 
  
    -- example = 
    if true then 
        return true 
    end 
    return false 
    ------------ 
  
end 
      
function vehicleEntry (playerSource) 
    if carGodMode(source,playerSource) then 
        setVehicleDamageProof(source,true) 
    elseif carNoGodMode(source,playerSource) then 
        setVehicleDamageProof(source,false) 
    end 
end 
addEventHandler ("onVehicleEnter", root, vehicleEntry) 

Link to comment
---look on resource start, i want it to be normal onVehicleEnter damage proof is not enabled 
---But when this function (random1) is Enabled, then I want damage proof enabled onVehicleEnter. 
  
function random1(playerSource) 
---damageproof onVehicleEnter should be automatically enabled when this function is enabled 
---note that there are some other functions other than for cars which i cannot post 
end 
  
function random2(playerSource) 
---damageproof onVehicleEnter should be automatically disabled when this function is enabled 
---note that there are some other functions other than for cars which i cannot post 
end 
  
function vehicleEntry (playerSource) 
    setVehicleDamageProof(getPedOccupiedVehicle(playerSource),true) 
addEventHandler ("onVehicleEnter", root, vehicleEntry) 
  
---Dont worry about how I set (random1) and (random2) functions enabled.. just help me  

Link to comment
  • Moderators

Is the system working per player or global?

This is per player:

local damageProofPlayers = {} 
  
function random1(playerSource) 
    damageProofPlayers[playerSource] = true 
    local vehicle = getPedOccupiedVehicle(playerSource) 
    if vehicle then 
        setVehicleDamageProof(vehicle,true) 
    end 
end 
  
function random2(playerSource) 
    damageProofPlayers[playerSource] = nil 
    local vehicle = getPedOccupiedVehicle(playerSource) 
    if vehicle then 
        setVehicleDamageProof(vehicle,false) 
    end 
end 
  
addEventHandler("onPlayerQuit",root, -- clean memory 
function () 
    if damageProofPlayers[source] then 
        damageProofPlayers[source] = nil 
    end 
end) 
  
function vehicleEntry (playerSource) 
    if damageProofPlayers[playerSource] then 
            setVehicleDamageProof(source,true) 
    end 
addEventHandler ("onVehicleEnter", root, vehicleEntry) 

Link to comment

This was the code i were using before:

function random1(playerSource) 
addEventHandler ("onVehicleEnter", root, vehicleEntry) 
end 
  
function random2(playerSource) 
removeEventHandler ("onVehicleEnter", root, vehicleEntry) 
end 
  
function vehicleEntry (playerSource) 
    setVehicleDamageProof(getPedOccupiedVehicle(playerSource),true) 
end 

but the problem is when the function (random1) is enabled second time, I get an error:

  • Bad usage @ 'addEventHandler' ['onVehicleEnter' with this function is already handled]

So to avoid it I want to find another way on event handling.

Link to comment
np.

I hope you learned something from it.

Sure :) ! But a small doubt.

function vehicleEntry (playerSource) 
    if not getVehicleOccupant(source, 0) then 
    return 
    elseif damageProofPlayers[playerSource] then 
            setVehicleDamageProof(source,true) 
    end 
end  
addEventHandler ("onVehicleEnter", root, vehicleEntry) 
  

If a guy enabled cargodmode and enter others vehicle as passenger, i want to cancel that function from happening

can you solve it pls.

Link to comment
If a guy enabled cargodmode and enter others vehicle as passenger, i want to cancel that function from happening

can you solve it pls.

You need to check the player seat ,

try this

function vehicleEntry (playerSource,seat) 
    if seat == 0 then  
        if damageProofPlayers[playerSource] then 
        setVehicleDamageProof(source,true) 
        end 
    end  
end  
addEventHandler ("onVehicleEnter", root, vehicleEntry) 

Link to comment
If a guy enabled cargodmode and enter others vehicle as passenger, i want to cancel that function from happening

can you solve it pls.

You need to check the player seat ,

try this

function vehicleEntry (playerSource,seat) 
    if seat == 0 then  
        if damageProofPlayers[playerSource] then 
        setVehicleDamageProof(source,true) 
        end 
    end  
end  
addEventHandler ("onVehicleEnter", root, vehicleEntry) 

Doesnt work!

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