Jump to content

addEventHandler [HELP]


Recommended Posts

Posted

explain more please

to trigger event use

triggerEvent  

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted

No, when I use this:

addEventHandler ("onPlayerVehicleEnter", root, vehicleEntry) 

It automatically start the function vehicleEntry when resource started.

But i want this event(vehicleEntry function) to start only when other function started.

Hope you understand. :!:

Posted

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) 

Inactivo.

Posted

Can you post any code?

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

Posted
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) 

Posted

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

#include <iostream>

int main() {

    std::cout << "C++ is amazing <3" << std::endl;

    return 0;

}

I left MTA !... I m doing some tuts about (servers and scripting here) subscribe please

  • Moderators
Posted
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) 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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

  • Moderators
Posted

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) 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

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.

  • Moderators
Posted

np.

I hope you learned something from it.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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

Posted
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) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
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!

Posted

Doesnt work!

Post full code here i need to check sth.

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

Doesnt work!

Post full code here i need to check sth.

Fixed it, actually forgot to add that 2nd argument. Sorry and Thank you very much :D

you are welcome.

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

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