Jump to content

How to do that?


MiniGoveya

Recommended Posts

Good evening, this time come with a question about scripting from the 0.

My question is:

How I can I create a command to give any vehicle?

Something like /givecar minigoveya hunter

However, it would all MTA vehicles.

Can you tell me how can i create that? or, if you can create?

I await your reply eagerly.

Until then, see you soon around here.

Link to comment

Click Here

you can see there, there are already maked what you want! ( example 3 )

so the code :

  
local distance = 5 --units 
  
-- define our handler (we'll take a variable number of parameters where the name goes, because there are vehicle names with more than one word) 
function consoleCreateVehicle ( sourcePlayer, commandName, ... ) 
   -- if a player triggered it, not the admin, 
   if ( sourcePlayer ) then 
      -- calculate the position of the vehicle based on the player's position and rotation: 
      local x, y, z = getElementPosition ( sourcePlayer ) -- get the player's position 
      local rotZ = getPedRotation ( sourcePlayer ) -- get the player's rotation around the Z axis in degrees 
      x = x + ( ( math.cos ( math.rad ( rotZ ) ) ) * distance ) -- calculate the X position of the vehicle 
      y = y + ( ( math.sin ( math.rad ( rotZ ) ) ) * distance ) -- calculate the Y position of the vehicle 
  
      -- get the complete vehicle name by joining all passed parameters using Lua function table.concat 
      local vehicleName = table.concat({...}, " ") 
      -- get the vehicle's model ID from the name 
      local vehicleID = getVehicleModelFromName ( vehicleName ) 
      -- if vehicle ID is valid, 
      if vehicleID then 
            -- create the vehicle using the information gathered above: 
            local newVehicle = createVehicle ( vehicleID, x, y, z, 0, 0, rotZ ) 
            -- if vehicle creation failed, give the player a message 
            if not newVehicle then 
               outputConsole ( "Failed to create vehicle.", sourcePlayer ) 
            end 
      end 
   end 
end 
  
-- Attach the 'consoleCreateVehicle' function to the "createvehicle" command 
addCommandHandler ( "createvehicle", consoleCreateVehicle ) 
  

Link to comment

Ok, try putting the same code as here:

local distance = 5 
  
function giveCar ( sourcePlayer, command ) 
  
    if hasObjectPermissionTo (thePlayer, "command.banserial") == true then 
      local x, y, z = getElementPosition ( sourcePlayer )  
      local rotZ = getPedRotation ( sourcePlayer )  
      x = x + ( ( math.cos ( math.rad ( rotZ ) ) 
      y = y + ( ( math.sin ( math.rad ( rotZ ) ) 
  
      local vehicleName = table.concat({...}, " ") 
      local vehicleID = getVehicleModelFromName ( vehicleName ) 
      if vehicleID then 
            local newVehicle = createVehicle ( vehicleID, x, y, z, 0, 0, rotZ ) 
            if not newVehicle then 
               outputConsole ( "Failed to create vehicle.", sourcePlayer ) 
            end 
      end 
   end 
end 
  
addCommandHandler ( "givecar", giveCar ) 

The only thing that changed were the comments and modify the command to run the script.

but this happen:

errorcde.jpg

What i did wrong?

Link to comment
local distance = 5 
  
function giveCar ( thePlayer, command, ... ) 
if hasObjectPermissionTo (thePlayer, "command.banserial") == true then 
local x, y, z = getElementPosition ( thePlayer ) 
local rotZ = getPedRotation ( thePlayer ) 
local vehicleName = table.concat({...}, " ") 
local vehicleID = getVehicleModelFromName ( vehicleName ) 
if vehicleID then 
local newVehicle = createVehicle ( vehicleID, x, y, z, 0, 0, rotZ ) 
warpPedIntoVehicle(thePlayer,newVehicle) 
if not newVehicle then 
outputConsole ( "Failed to create vehicle.", thePlayer ) 
      end 
    end 
  end 
end 
addCommandHandler ( "givecar", giveCar ) 

dunno if that is what you want, it gives you a car if you put /givecar example infernus

Link to comment

Solid Ok, I appreciate your help, but such a rare thing, the script does not work.

This time I put the script as you told me, but this is what happens:

errorj.jpg

Then, the script is as follows:

givecar.lua

local distance = 5 
  
function giveCar ( thePlayer, command, ... ) 
if hasObjectPermissionTo (thePlayer, "command.banserial") == true then 
local x, y, z = getElementPosition ( thePlayer ) 
local rotZ = getPedRotation ( thePlayer ) 
local vehicleName = table.concat({...}, " ") 
local vehicleID = getVehicleModelFromName ( vehicleName ) 
if vehicleID then 
local newVehicle = createVehicle ( vehicleID, x, y, z, 0, 0, rotZ ) 
warpPedIntoVehicle(thePlayer,newVehicle) 
if not newVehicle then 
outputConsole ( "Failed to create vehicle.", thePlayer ) 
      end 
    end 
  end 
end 
addCommandHandler ( "givecar", giveCar ) 

Then the meta.xml is as follows:

meta.xml

<meta> 
    <info author="minigoveya" type="server" version="1.0.0" /> 
    <script src="givecar.lua" type="script" /> 
</meta> 
  

what did wrong?

P.S: Excuse me, you and everyone who helped and are helping me, for her persistence and my questions.

Link to comment
You want to make it admin command or free for all?

I don't know why you want this in race - everybody will use infernus..

Also i don't understand what you mean:

That dont get another vehicle if i give me car and too do not get nitro, repair anything :S

he means that if he give himself a car it isnt repaired + nitro :roll:

for minigoveya use

https://wiki.multitheftauto.com/wiki/FixVehicle and https://wiki.multitheftauto.com/wiki/AddVehicleUpgrade

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