Jump to content

How to do that?


MiniGoveya

Recommended Posts

Posted

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.

Posted

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 ) 
  

Posted

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?

Posted
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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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.

Posted

restart server.

be sure to put resource in right folder

/server/mods/deathmatch/resources

(some ppl skips "server" folder)

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

Archivo WinRAR

and under:

Archivo WinRAR ZIP

suggests that you packed your resoure as RAR while it should be packed as ZIP :)

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

HAHAAHAHHAHAHAHAHHA xDDDD

Thank you so much man ! hahaha xD Stupid Error xD

Thanks :)

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

P.S: I've RACE Server

Posted

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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted
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

logo_left.png
Posted

Ahh, one very big reminder that, rar is NOT supported, so yeah you need .zip, I also stuck at that problem a while ago. :mrgreen:

XX3 is gone. This is my new name. :3

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