Jump to content

addEventHandler element problem


Recommended Posts

1st of all, everything is in the server side.

I have a problem with my addEventHandler in my function:

vehicle = {} 
function createVeh(modelName, x, y, z) 
    player = getPlayerName(source) 
    vehicle[player] = createVehicle(modelName, x, y, z) 
    addEventHandler("onVehicleEnter", vehicle[player], function() triggerClientEvent(source, "enterVehicle", source) end) 
end 

Some reasons this doesn't work.

The triggerClientEvent works, if I put it in alone, without the addEventHandler.

I think that the addEventHandler doesn't like my vehicle variable as element, and the element is getting created by the createVehicle properly, so I don't have any idea what is the problem here. Or if my solution of this problem is stupid, can you tell me a better solution?

The problem I want to solve is, when the player hits the specified marker, the server creates a vehicle for him, and stores the element in the vehicle[player] (where player variable is the name of the player, because the source is a changing thing, if you relog), and after that I want to use the vehicle[player] (contains a vehicle element) to create / delete addEventHandlers, like in my code.

Thanks in advance!

Link to comment
vehicle = {} 
function createVeh(modelName, x, y, z) 
    player = getPlayerName(source) 
    vehicle[player] = createVehicle(modelName, x, y, z) 
    addEventHandler("onVehicleEnter", vehicle[player], function(p) triggerClientEvent(p, "enterVehicle", p) end) 
end 

Link to comment
vehicle = {} 
function createVeh(modelName, x, y, z) 
    player = getPlayerName(source) 
    vehicle[player] = createVehicle(modelName, x, y, z) 
    addEventHandler("onVehicleEnter", vehicle[player], function(p) triggerClientEvent(p, "enterVehicle", p) end) 
end 

It worked, thanks!!

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