[Question] Assigning data to object, ped, vehicle, etc


#1

Hi there,

I’ve recently got into the FiveM community, I come from MTA to begin with so I got pretty good LUA experience. I’m currently looking for a function or a way to assign data or variables to an object, ped, vehicle and so on. For example, let’s say I want to spawn a vehicle in-game but I want the vehicle to be detected as spawned by me, in which I want to assign such data to the element in which could be used by the scripts at any other point.

Is this possible, and if so, how would I go about doing this, I’ve looked around the wiki and the forums but I can’t really find any useful information about it, any help is greatly appriciated.


#2

Well there are a couple of ways to really do this this but I would first

SAVING VEHICLES

– CLIENT –

  1. Spawn the vehicle.
  2. Get vehicle network id.
  3. Trigger a server event to pass that network id to the server.

– SERVER –

  1. Create a table to store the data
  2. Register a server event to recieve the network id
  3. When even is triggered insert into the table some data

{plyid = 1, vehid = 237573}

GETTING PERSON WHO SPAWNED THE VEHICLE

– CLIENT –

  1. Get vehicle net id
  2. trigger server event and pass net id to server

– SERVER –

  1. Make a function to loop through the table where the vehicles are stored.
  2. Register server event to recieve the vehicle spawner request.
  3. Trigger that function to where if it finds a matching netid then return the plyid
  4. Send a message to the client who requests the player who spawned it?

#3

Thanks, I was kinda assuming that I would have to store it in a table since I was unable to find such a function, but this clears it up a lot more than I expected. Thanks for the help!