Jump to content

onVehicleStartEnter() is triggered only once..


xit

Recommended Posts

Posted (edited)

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
Posted

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

Posted

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.

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

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

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

  • 2 months later...
Posted

I just worked on a lock system using this sort of thing and it doesnt let me enter any car after cancelEvent has happened. Is there any expected time for the function to be fixed ?

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

Posted

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

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