MiniGoveya Posted September 25, 2010 Share Posted September 25, 2010 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
CowTurbo Posted September 25, 2010 Share Posted September 25, 2010 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
MiniGoveya Posted September 25, 2010 Author Share Posted September 25, 2010 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: What i did wrong? Link to comment
Castillo Posted September 25, 2010 Share Posted September 25, 2010 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
MiniGoveya Posted September 25, 2010 Author Share Posted September 25, 2010 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: 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
dzek (varez) Posted September 25, 2010 Share Posted September 25, 2010 restart server. be sure to put resource in right folder /server/mods/deathmatch/resources (some ppl skips "server" folder) Link to comment
MiniGoveya Posted September 25, 2010 Author Share Posted September 25, 2010 Thank you varez, but that's is there Look : Link to comment
dzek (varez) Posted September 25, 2010 Share Posted September 25, 2010 Archivo WinRAR and under: Archivo WinRAR ZIP suggests that you packed your resoure as RAR while it should be packed as ZIP Link to comment
MiniGoveya Posted September 26, 2010 Author Share Posted September 26, 2010 HAHAAHAHHAHAHAHAHHA xDDDD Thank you so much man ! hahaha Stupid Error Thanks EDIT: Man O_O That dont get another vehicle if i give me car and too do not get nitro, repair anything P.S: I've RACE Server Link to comment
dzek (varez) Posted September 26, 2010 Share Posted September 26, 2010 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: Quote That dont get another vehicle if i give me car and too do not get nitro, repair anything Link to comment
[DMC] Posted September 26, 2010 Share Posted September 26, 2010 varez said: 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: Quote That dont get another vehicle if i give me car and too do not get nitro, repair anything he means that if he give himself a car it isnt repaired + nitro for minigoveya use https://wiki.multitheftauto.com/wiki/FixVehicle and https://wiki.multitheftauto.com/wiki/AddVehicleUpgrade Link to comment
Xierra Posted September 26, 2010 Share Posted September 26, 2010 Ahh, one very big reminder that, rar is NOT supported, so yeah you need .zip, I also stuck at that problem a while ago. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now