kevin433 Posted February 24, 2010 Share Posted February 24, 2010 Hi, I'm trying to prevent the player from entering a vehicle if he's not the owner. The problem is that "getElementID" doesn't get the ID from the Vehicle. I'm using the function called "onClientVehicleStartEnter", I've read at the Wiki that the parameters are "thePlayer, seat, door" and that the source is the Vehicle the player enters. So I wonder why it's not getting the Vehicle ID. function checkvehicleowner(player) local vre = executeSQLSelect("Vehicles", "Owner", "CarID = '" .. getElementID(source) .."'") outputChatBox(vre[1].Owner) if(vre[1].Owner == getPlayerName(player)) then setVehicleLocked(source, false) outputChatBox(vre[1].Owner) else outputChatBox("Du bist nicht der besitzer diese fahrzeugs!", getLocalPlayer()) end end addEventHandler("onClientVehicleStartEnter", getRootElement(), checkvehicleowner) I see nothing wrong with this code, it's giving me no errors in the MTA:SE nor in the Console when I start to enter the vehicle. I also tested out how far the code proceeds with textmessages between the lines. It only goes to the line with "local vre = executeSQLSelect("Vehicles", "Owner", "CarID = '" .. getElementID(source) .."'")". Link to comment
Gamesnert Posted February 24, 2010 Share Posted February 24, 2010 The getElementID documentation states the problem with how you're using the function: This function gets the ID of an element. This is the "id" attribute of the element and is a string, NOT a number like a model ID, weapons ID or similar. This means it also doesn't return a vehicle ID. For this, you should use getElementModel. So what's getElementID for? It's for getting the ID defined in maps. With these IDs, you can get individual objects so you can move them etc. But as you want the vehicle ID, you need to use getElementModel. I recommend you to read the wiki a bit more thoroughly. Link to comment
kevin433 Posted February 24, 2010 Author Share Posted February 24, 2010 Yeah, I know about this. I've given every vehicle a ID in form of a string when they spawn, and that works. When I enter a vehicle with a Server-side function it tells me the ID. But it doesn't client-side Link to comment
Aibo Posted February 24, 2010 Share Posted February 24, 2010 well SQL functions obviously are server-side, since database is server-side you can also use setElementData (which is synchronized) to set vehicle owner when vehicle is spawned or bought by someone: setElementData(theVehicle, "vehicleowner", ownerName) and then you can access it client-side: if getElementData(theVehicle, "vehicleowner") == getPlayerName(player) then Link to comment
kevin433 Posted February 24, 2010 Author Share Posted February 24, 2010 Thank you xbost! Now it works! But now I'm having another problem. If I'm not the owner it doesn't cancel the event function checkvehicleowner(player) if(getElementData(source, "Owner") == getPlayerName(player)) then setVehicleLocked(source, false) outputChatBox(getElementData(source, "Owner")) else outputChatBox("Du bist nicht der besitzer diese fahrzeugs!", player) cancelEvent() end end addEventHandler("onClientVehicleStartEnter", getRootElement(), checkvehicleowner) Link to comment
Aibo Posted February 24, 2010 Share Posted February 24, 2010 outputChatBox("Du bist nicht der besitzer diese fahrzeugs!") you don't need player element here, since it's a client-side script: bool outputChatBox ( string text [, int r=255, int g=255, int b=255, bool colorCoded=false ]) Link to comment
kevin433 Posted February 24, 2010 Author Share Posted February 24, 2010 Forgot to read the Client-side syntax But it's still not cancelling Link to comment
kevin433 Posted February 24, 2010 Author Share Posted February 24, 2010 I got it! Just locked the vehicle when he is not the owner. 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