Jump to content

[Help]getPedOccupiedVehicle


Markx

Recommended Posts

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

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 by Patrick
  • Thanks 1
Link to comment
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

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