Game⚠Breakerツ Posted May 11, 2015 Share Posted May 11, 2015 Hi. How to trigger event only when a function is enabled. Link to comment
darhal Posted May 11, 2015 Share Posted May 11, 2015 explain more please to trigger event use triggerEvent Link to comment
Game⚠Breakerツ Posted May 11, 2015 Author Share Posted May 11, 2015 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. Link to comment
Enargy, Posted May 11, 2015 Share Posted May 11, 2015 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
Game⚠Breakerツ Posted May 11, 2015 Author Share Posted May 11, 2015 I will make it simple, addEventHandler only when other function is enabled, else if that function is disabled cancel that event. And when the resource start I want it to be false. Link to comment
Game⚠Breakerツ Posted May 12, 2015 Author Share Posted May 12, 2015 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
darhal Posted May 12, 2015 Share Posted May 12, 2015 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
Game⚠Breakerツ Posted May 12, 2015 Author Share Posted May 12, 2015 Can you fill it in that lua, pls. Link to comment
Moderators IIYAMA Posted May 12, 2015 Moderators Share Posted May 12, 2015 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
Game⚠Breakerツ Posted May 12, 2015 Author Share Posted May 12, 2015 ---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 IIYAMA Posted May 12, 2015 Moderators Share Posted May 12, 2015 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
Game⚠Breakerツ Posted May 12, 2015 Author Share Posted May 12, 2015 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
Moderators IIYAMA Posted May 12, 2015 Moderators Share Posted May 12, 2015 See my last post. Link to comment
Game⚠Breakerツ Posted May 12, 2015 Author Share Posted May 12, 2015 See my last post. Awsome friend it works! I am so glad that you did it for me Link to comment
Moderators IIYAMA Posted May 12, 2015 Moderators Share Posted May 12, 2015 np. I hope you learned something from it. Link to comment
Game⚠Breakerツ Posted May 12, 2015 Author Share Posted May 12, 2015 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
Walid Posted May 12, 2015 Share Posted May 12, 2015 If a guy enabled cargodmode and enter others vehicle as passenger, i want to cancel that function from happeningcan 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
Game⚠Breakerツ Posted May 12, 2015 Author Share Posted May 12, 2015 If a guy enabled cargodmode and enter others vehicle as passenger, i want to cancel that function from happeningcan 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
Walid Posted May 12, 2015 Share Posted May 12, 2015 Doesnt work! Post full code here i need to check sth. Link to comment
Game⚠Breakerツ Posted May 12, 2015 Author Share Posted May 12, 2015 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 Link to comment
Walid Posted May 12, 2015 Share Posted May 12, 2015 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 you are welcome. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now