Jump to content

[HELP] NO REPEAT addEventHandler


Recommended Posts

Hello, Guys , somebody can help me with addEventHandler

when thePlayer get in the car ,the handler "onVehicleEnter" start , like this:

  
function inCar(thePlayer) 
-- Action 1 
  outputChatBox("Mesage!!!") 
end 
  
addEventHandler("onVehicleEnter" , getRootElement() , inCar) 
  

ok, that's work, but i want to make a diferent action, when the thePlayer get in the same car again!

thanks!

Link to comment

I'm tryng put this conditional in this block

  
carUsed = {} 
  
function inCar(thePlayer) 
if (carUsed[thePlayer]) then 
  outputChatBox("Mesage!!!") 
 carUsed[thePlayer] = false 
else 
 outputChatBox("Mesage 222") 
end 
 end 
addEventHandler("onVehicleEnter" , getRootElement() , inCar) 
  
  

When the player return to car , nothing happens, if I put the variable casUsed = false, block for everybody. not just to player

somebody???

thanks

Link to comment

Sorry if i have misread your code, don't understand you that much

When the player enters the vehicle, you can check if the vehicle has a element data. and if it does not, then you can set the element data and outputChatBox, and if it does have the element data, then you can do whatever you want.

Edited by Guest
Link to comment
is it?
addEventHandler("onClientVehicleEnter", getRootElement(),function() 
    outputChatBox("You enter in vehicle") 
end) 
  
  
addEventHandler("onClientVehicleExit", getRootElement(),function() 
    outputChatBox("You exit in vehicle") 
end) 

Look

https://community.multitheftauto.com/ind ... ls&id=9022

No, the handler "onCVehicleExit" do other things, I want to do diferent thngs' in "onVehicleEnter"

thanks for help

Link to comment
Sorry if i have misread your code, don't understand you that much

When the player enters the vehicle, you can check if the vehicle has a element data. and if it does not, then you can set the element data and outputChatBox, and if it does have the element data, then you can do whatever you want.

no problem, i'll try thanks

Link to comment

so this?

local carUsedCount = {} 
  
function inCar(thePlayer) 
if (carUsedCount[source]) then 
 carUsedCount[source] = carUsedCount[source] +1 
else 
carUsedCount[source] = 1 
end 
if (carUsedCount[source] == 1) then 
outputChatBox("First time to enter in this vehicle",thePlayer) 
end 
if (carUsedCount[source] == 2) then 
outputChatBox("Second time to enter in this vehicle",thePlayer) 
end 
 end 
addEventHandler("onVehicleEnter" ,root, inCar) 

Link to comment
if it is not, I do not know what you want ..

explain in detail, please

ok, thePlayer enters the vehicle for the first time and start the "onVehicleEnter" with message:

"The Player Enters the Car"

so, thePlayer out the vehicle and start "onVehicleExit" with message:

"The Player is outr"

ok, same thePlayer enters the vehicle again for second time, with message:

"The Player enters the Car Again"

you know, diferent messages "onVehicleEnter"

Thanks

Link to comment

serves this?

so this?
local carUsedCount = {} 
  
function inCar(thePlayer) 
if (carUsedCount[source]) then 
 carUsedCount[source] = carUsedCount[source] +1 
else 
carUsedCount[source] = 1 
end 
if (carUsedCount[source] == 1) then 
outputChatBox("First time to enter in this vehicle",thePlayer) 
end 
if (carUsedCount[source] == 2) then 
outputChatBox("Second time to enter in this vehicle",thePlayer) 
end 
 end 
addEventHandler("onVehicleEnter" ,root, inCar) 

Link to comment
so this?
local carUsedCount = {} 
  
function inCar(thePlayer) 
if (carUsedCount[source]) then 
 carUsedCount[source] = carUsedCount[source] +1 
else 
carUsedCount[source] = 1 
end 
if (carUsedCount[source] == 1) then 
outputChatBox("First time to enter in this vehicle",thePlayer) 
end 
if (carUsedCount[source] == 2) then 
outputChatBox("Second time to enter in this vehicle",thePlayer) 
end 
 end 
addEventHandler("onVehicleEnter" ,root, inCar) 

owwww

awesome!! Works perfectly

thank you very much

Link to comment
serves this?
so this?
local carUsedCount = {} 
  
function inCar(thePlayer) 
if (carUsedCount[source]) then 
 carUsedCount[source] = carUsedCount[source] +1 
else 
carUsedCount[source] = 1 
end 
if (carUsedCount[source] == 1) then 
outputChatBox("First time to enter in this vehicle",thePlayer) 
end 
if (carUsedCount[source] == 2) then 
outputChatBox("Second time to enter in this vehicle",thePlayer) 
end 
 end 
addEventHandler("onVehicleEnter" ,root, inCar) 

yes! thank you for your attention!

Link to comment

Add, message color

Add, Nick name in ChatBox

c3b786bef310906f5f753e058e6da479.png

Server.lua

local carUsedCount = {} 
  
function inCar(thePlayer) 
if (carUsedCount[source]) then 
 carUsedCount[source] = carUsedCount[source] +1 
else 
carUsedCount[source] = 1 
end 
if (carUsedCount[source] == 1) then 
  
outputChatBox("#ffffff"..getPlayerName( thePlayer ):gsub('#%x%x%x%x%x%x', '').. " #ff0000First time to enter in this vehicle",thePlayer, 255, 200, 0, true) 
end 
if (carUsedCount[source] == 2) then 
  
outputChatBox("#ffffff"..getPlayerName( thePlayer ):gsub('#%x%x%x%x%x%x', '').. " #ff0000Second time to enter in this vehicle",thePlayer, 255, 200, 0, true) 
end 
if (carUsedCount[source] == 3) then 
  
outputChatBox("#ffffff"..getPlayerName( thePlayer ):gsub('#%x%x%x%x%x%x', '').. " #ff0000Tree time to enter in this vehicle",thePlayer, 255, 200, 0, true) 
end 
 end 
addEventHandler("onVehicleEnter" ,root, inCar) 

Link to comment
Add, message color

Add, Nick name in ChatBox

c3b786bef310906f5f753e058e6da479.png

Server.lua

local carUsedCount = {} 
  
function inCar(thePlayer) 
if (carUsedCount[source]) then 
 carUsedCount[source] = carUsedCount[source] +1 
else 
carUsedCount[source] = 1 
end 
if (carUsedCount[source] == 1) then 
  
outputChatBox("#ffffff"..getPlayerName( thePlayer ):gsub('#%x%x%x%x%x%x', '').. " #ff0000First time to enter in this vehicle",thePlayer, 255, 200, 0, true) 
end 
if (carUsedCount[source] == 2) then 
  
outputChatBox("#ffffff"..getPlayerName( thePlayer ):gsub('#%x%x%x%x%x%x', '').. " #ff0000Second time to enter in this vehicle",thePlayer, 255, 200, 0, true) 
end 
if (carUsedCount[source] == 3) then 
  
outputChatBox("#ffffff"..getPlayerName( thePlayer ):gsub('#%x%x%x%x%x%x', '').. " #ff0000Tree time to enter in this vehicle",thePlayer, 255, 200, 0, true) 
end 
 end 
addEventHandler("onVehicleEnter" ,root, inCar) 

Great! Thank you very much. I'm using that, works perfectly

Link to comment

(manawydan )THAT?

local carUsedCount = {} 
  
function inCar(thePlayer) 
if (carUsedCount[source]) then 
 carUsedCount[source] = carUsedCount[source] +1 
else 
carUsedCount[source] = 1 
end 
if (carUsedCount[source] == 1) then 
  
outputChatBox("#ffffff"..getPlayerName( thePlayer ):gsub('#%x%x%x%x%x%x', '').. " #ff0000First time to enter in this vehicle",thePlayer, 255, 200, 0, true) 
end 
if (carUsedCount[source] == 2) then 
  
outputChatBox("#ffffff"..getPlayerName( thePlayer ):gsub('#%x%x%x%x%x%x', '').. " #ff0000Second time to enter in this vehicle",thePlayer, 255, 200, 0, true) 
end 
if (carUsedCount[source] == 3) then 
  
outputChatBox("#ffffff"..getPlayerName( thePlayer ):gsub('#%x%x%x%x%x%x', '').. " #ff0000Tree time to enter in this vehicle",thePlayer, 255, 200, 0, true) 
end 
 end 
addEventHandler("onVehicleEnter" ,root, inCar) 
  
-- that ? 
addEventHandler("onVehicleExplode",root, 
function() 
if(carUsedCount[source]) then 
carUsedCount[source] =nil 
end 
end) 

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