Markx Posted March 23, 2020 Share Posted March 23, 2020 Hi, I'm having a problem with this small part of my code, for some reason I can't get a "Hello" answer here, no matter what. function PlateText(thePlayer) local Vehicle = getPedOccupiedVehicle(thePlayer) if Vehicle then outputChatBox("Hi") else outputChatBox("bye") end end Whenever I try, it is always the answer "Bye" that is presented, I even tried with the example of the wiki and it also did not return the answer to me when I was in the vehicle. https://wiki.multitheftauto.com/wiki/GetPedOccupiedVehicle function showVehicleName ( thePlayer ) local theVehicle = getPedOccupiedVehicle ( thePlayer ) if theVehicle then outputChatBox ( "Name of the Vehicle: " .. getVehicleName ( theVehicle ), thePlayer ) else outputChatBox ( "You do not have a Vehicle!", thePlayer, 255, 0, 0, true ) end end addCommandHandler ( "getcarname", showVehicleName ) Could someone help me here and tell me what's going on? Link to comment
Moderators Patrick Posted March 23, 2020 Moderators Share Posted March 23, 2020 (edited) I think you try to use this code on client side, but you need to use on server side, because of addCommandHandler. On server side, addCommandHandler pass the following arguments to attached function: PLAYERELEMENT, COMMANDNAME, ... But on client side, its not pass PLAYERELEMENT, because its can be only localPlayer. Looks: COMMANDNAME, ... Wiki: addCommandHandler How to use on client side: -- CLIENT SIDE function PlateText() local Vehicle = getPedOccupiedVehicle(localPlayer) if Vehicle then outputChatBox("Hi") else outputChatBox("bye") end end addCommandHandler("something", PlateText) Edited March 23, 2020 by Patrick 1 Link to comment
Markx Posted March 23, 2020 Author Share Posted March 23, 2020 1 hour ago, Patrick said: I think you try to use this code on client side, but you need to use on server side, because of addCommandHandler. On server side, addCommandHandler pass the following arguments to attached function: PLAYERELEMENT, COMMANDNAME, ... But on client side, its not pass PLAYERELEMENT, because its can be only localPlayer. Looks: COMMANDNAME, ... Oh... I understand now, I thought that being a shared function I could use it equally on the client/server side. Thanks for the help Patrick, I was really confused about why it didn't work. 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