Killerhamster10 Posted June 23, 2010 Share Posted June 23, 2010 Hey, I have a big problem. I wanted to make a function which checks something and if it is wrong it will cancel a event. This is my code: function enterVehicle (theVehicle) local id = getElementModel (theVehicle) if normalcars[getElementModel (theVehicle)] then if (getAccountData (getPlayerAccount (source), "License-A") == "false") then --removePedFromVehicle ( source ) outputChatBox ( "You're not allowed to drive this car! Buy a license at the office!", source,255,0,0 ) cancelEvent() elseif (getAccountData (getPlayerAccount (source), "License-A") == "true") then outputChatBox ( "You're allowed to drive this car!", source) end end if aircrafts[getElementModel (theVehicle)] then if (getAccountData (getPlayerAccount (source), "License-B") == "false") then --removePedFromVehicle (source) outputChatBox ( "You're not allowed to fly this aircraft! Buy a license at the office!", source,255,0,0 ) cancelEvent() elseif (getAccountData (getPlayerAccount (source), "License-B") == "true") then outputChatBox ( "You're allowed to fly this aircraft!", source ) end end if military[getElementModel (theVehicle)] then if (getAccountData (getPlayerAccount (source), "License-C") == "false") then --removePedFromVehicle (source) outputChatBox ( "You're not allowed to use military vehicles or aircrafts! Buy a license at the office!", source,255,0,0 ) cancelEvent() elseif (getAccountData (getPlayerAccount (source), "License-C") == "true") then outputChatBox ( "You're allowed to use military vehicles or aircrafts!", source ) end end end addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle ) But it doesn't cancel the event... Can someone help me? Sorry for my english Greetings Link to comment
MaddDogg Posted June 23, 2010 Share Posted June 23, 2010 Have a look at this: https://wiki.multitheftauto.com/wiki/OnVehicleStartEnter The source is not the player.. Link to comment
kevin433 Posted July 1, 2010 Share Posted July 1, 2010 Try this (Not tested, but I think it should work): function enterVehicle (player) local id = getElementModel (source) if normalcars[getElementModel (source)] then if (getAccountData (getPlayerAccount (player), "License-A") == "false") then --removePedFromVehicle ( player) outputChatBox ( "You're not allowed to drive this car! Buy a license at the office!", player,255,0,0 ) cancelEvent() elseif (getAccountData (getPlayerAccount (player), "License-A") == "true") then outputChatBox ( "You're allowed to drive this car!", player) end elseif aircrafts[getElementModel (source)] then if (getAccountData (getPlayerAccount (player), "License-B") == "false") then --removePedFromVehicle (player) outputChatBox ( "You're not allowed to fly this aircraft! Buy a license at the office!", player,255,0,0 ) cancelEvent() elseif (getAccountData (getPlayerAccount (player), "License-B") == "true") then outputChatBox ( "You're allowed to fly this aircraft!", player) end elseif military[getElementModel (source)] then if (getAccountData (getPlayerAccount (player), "License-C") == "false") then --removePedFromVehicle (player) outputChatBox ( "You're not allowed to use military vehicles or aircrafts! Buy a license at the office!", player,255,0,0 ) cancelEvent() elseif (getAccountData (getPlayerAccount (player), "License-C") == "true") then outputChatBox ( "You're allowed to use military vehicles or aircrafts!", player) end end end addEventHandler ( "onVehicleStartEnter", getRootElement(), enterVehicle ) As MaddDog said, source is not the player, but the vehicle which has been entered. 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