Jump to content

onVehicleStartEnter() is triggered only once..


xit

Recommended Posts

When trying to enter a vehicle as passenger and the event has been cancelled for it before, the event is not triggered anymore and you are unable to enter the vehicle as passenger even if the event doesn't get cancelled the next time. This happens only when trying to enter a vehicle as passenger, entering driving seat does trigger the event everytime and trying to enter another vehicle as passenger works just fine.

My code is as follows:

function onVehicleStartEnter(enteringPlayer, seat, jacked) 
    outputChatBox("trying to enter vehicle...") -- for debugging 
     
    if (getElementData(source, "locked") and getElementData(source, "locker") ~= enteringPlayer) then 
        outputChatBox(" but it's locked") -- for debugging 
         
        cancelEvent() 
    end 
end 
addEventHandler("onVehicleStartEnter", getRootElement(), onVehicleStartEnter) 

Have I done something wrong, or is something broken in MTA?

Thanks.

Excuse me for my bad english, I hope you understand what I mean anyway. :)

Edited by Guest
Link to comment

Hi,

Thanks for your report. This seems to be a problem in MTA indeed. It has been reported to the developers.

In the meantime, take a look at setVehicleLocked as an alternative for locking vehicles (you can use the function client side for letting some players enter and others not).

Link to comment

Remember not call function and event names the same thing, as Lua may confuse them. Here, you've got onVehicleStartEnter as the function name and the event name.

I've also noticed similar problems with the cancelEvent() for this event. It only is triggered once, as previously mentioned.

Link to comment
Remember not call function and event names the same thing, as Lua may confuse them.

Incorrect. The wiki pages simply mean that it may be confusing for the *scripter*. However, if you don't find it confusing as a scripter, there is no problem at all with giving the handler function the same name as the event. :)

Link to comment
Remember not call function and event names the same thing, as Lua may confuse them.

Incorrect. The wiki pages simply mean that it may be confusing for the *scripter*. However, if you don't find it confusing as a scripter, there is no problem at all with giving the handler function the same name as the event. :)

It doesn't say "... as you may be confued", it says "Lua may confuse them"

- Lua - it's not scripter

- may - "may confuse" not "will confuse", may but doesn't have to

- them - functions and events, not scripters

You can call them the same, but you've been warned it may confuse the Lua.

The problem described above may be a bug in MTA itself.

Link to comment
It doesn't say "... as you may be confued", it says "Lua may confuse them"

- Lua - it's not scripter

- may - "may confuse" not "will confuse", may but doesn't have to

- them - functions and events, not scripters

You can call them the same, but you've been warned it may confuse the Lua.

The problem described above may be a bug in MTA itself.

Where does it say that? If I look at the addEventHandler documentation it says in the note "may lead to confusion", it says nothing about Lua. If there's some other doc page that does say it may confuse Lua, please tell me which one so I can correct it. :)

The "problem" as you call it does not exist, neither in Lua or in MTA.

Link to comment
  • 2 months later...
It doesn't say "... as you may be confued", it says "Lua may confuse them"

- Lua - it's not scripter

- may - "may confuse" not "will confuse", may but doesn't have to

- them - functions and events, not scripters

You can call them the same, but you've been warned it may confuse the Lua.

The problem described above may be a bug in MTA itself.

Where does it say that? If I look at the addEventHandler documentation it says in the note "may lead to confusion", it says nothing about Lua. If there's some other doc page that does say it may confuse Lua, please tell me which one so I can correct it. :)

The "problem" as you call it does not exist, neither in Lua or in MTA.

arc_, you just picked an old post :) I've tested and made sure nothing's wrong with using func's name same as events' names.

Link to comment

if (getElementData(source, "locked") and getElementData(source, "locker") ~= enteringPlayer) then 

i'm sure it should be like this:

if (getElementData(source, "locked")) and (getElementData(source, "locker") ~= enteringPlayer) then 

if you would say that doesn't make a difference, then i think your wrong cause i have had some problems using "and" and using it like you have usually doesn't work for me, donno why :S

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