Jump to content

[HELP] Spawn vehicles.


Raxzen

Recommended Posts

 

Hi, I have been introducing to programming in Lua through MTA and I had some doubts to see if you can clarify, I hope this subforum is correct, it is a panel for spawning cars, and achieved basic functionality through the wiki, but I have a problem in which I hope you can help me

Client: 

  1. function generar_auto(boton,estado)
  2.     local fila,columna = guiGridListGetSelectedItem(grid_autos)
  3.     if fila and columna and fila ~= -1 and columna ~= -1 then
  4.       local selected = guiGridListGetItemData(grid_autos,fila,columna)
  5.       selected = tonumber(selected)
  6.       local rotz = getElementRotation(getLocalPlayer())
  7.       local x,y,z = getElementPosition(getLocalPlayer())
  8.       x = x + ( math.cos ( math.rad ( rotz+90 ) ) * 3)
  9.       y = y + ( math.sin ( math.rad ( rotz+90 ) ) * 3)
  10.       if selected and x and y and z then
  11.  
  12.         triggerServerEvent("onClientGenerarAuto",getRootElement(),selected,x,y,z)
  13.        
  14.       else
  15.         outputChatBox("No spawneo")
  16.       end
  17.     else
  18.      
  19.       outputChatBox("Error")
  20.     end
  21.  
  22. end

Server:

  1. function generar_auto(vehiculo,posx,posy,posz,player)
  2.   -- check all the arguments exist
  3.     if vehiculo and posx and posy and posz then
  4.     createVehicle(vehiculo,posx,posy,posz)
  5.     outputChatBox("Auto creado",source)
  6. end
  7.  
  8. end
 
This part of the code is what allows me to create the car and as I said everything is fine, it does, but I would like to put the user inside it directly, when using the warPedIntoVehicle on the server but it doesn't find the argument and it doesn't put it
 
The other is how I can limit the spawn of the cars to only 1, since if I keep clicking the button it follows me and keeps creating cars.
 
PS: I am using the wiki, exactly this link, it is the same code but with slight changes in variables: https://wiki.multitheftauto.com/wiki/Scripting_the_GUI_-_Tutorial_1
 
THANK YOU, I really sorry for mi english, I used google translate
Edited by Raxzen
Link to comment

--Edit those

--Client

15 hours ago, Raxzen said:

triggerServerEvent("onClientGenerarAuto",getRootElement(),selected,x,y,z, getLocalPlayer () )

--Server

 

15 hours ago, Raxzen said:
  • if vehiculo and posx and posy and posz then
  •     local veh = createVehicle(vehiculo,posx,posy,posz)
  •     warpPedIntoVehicle(player, veh) 
  •     outputChatBox("Auto creado",source)
  • end

 

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