Jump to content

David1544

Members
  • Posts

    5
  • Joined

  • Last visited

Everything posted by David1544

  1. Yeah, maybe I was trying to do a bit much for a first script. Thank you so much for your help.
  2. Okay, when a player spawns a vehicle, it will delete the current one that it is in. Then, it assigns an unique ID to that vehicle when it is either spawned or when a player enters it. I tried to make some more changes after I posted that, which is actually broken. No errors get thrown out but the command /spawnvehicle (ID) doesn't work.
  3. EDIT: I fixed it by mashing my hands on my keyboard and this came out. EDIT 2: It loads but does not function function spawnPlayerVehicle (thePlayer, command, vehicleModel) local check isPedInVehicle(thePlayer) if isPedInVehicle == true then local x, y, z = getElementPosition(thePlayer) local theVehicle = getPedOccupiedVehicle(thePlayer) if theVehicle then destroyElement(theVehicle) createVehicle(tonumber(vehicleModel),x, y, z) else x = x + 3 createVehicle(tonumber(vehicleModel),x, y, z) setElementID ("theVehicle",player[i]) end end end addCommandHandler("spawnVehicle", spawnPlayerVehicle) function AssignVehicleID() local theVehicle = getPedOccupiedVehicle(thePlayer) local check isPedInVehicle(thePlayer) if isPedInVehicle == true then setElementID ("theVehicle", player[i]) else end end addEventHandler("onVehicleEnter", root, AssignVehicleID))
  4. I read over the wiki and the forums a bit more and was able to modify the script so it looks like this. It wont load because of the error "'=' expected near 'local' Line 9" though. Also, no offense taken, I expect my scripts to be crap until I get back up to speed on coding. --Assigns ID on vehicle spawn and deletes old vehicle function createVehicleForPlayer(thePlayer, command, vehicleModel) local x, y, z = getElementPosition(thePlayer) -- Gets player Position x = x + 3 -- Adds 3 to x-axis of player location local createdVehicle = createVehicle(tonumber(vehicleModel),x, y, z) -- Creates vehicle at player location +3 to x-axis i=1 -- A variable, I think I need it, not entirely sure getElementByID ( player[i] ) -- Gets ID of old car destroyElement -- Destroys old car local checkedPlayer = getPlayerFromName ( PlayerVehicle ) -- Checks if player is in vehicle if ( PlayerVehicle ) then if isPedInVehicle ( checkedplayer ) then -- Player is in vehicle setElementID ( player[i] ) -- Assigns ID to newly created vehicle else outputChatBox("Failed to create vehicle.", thePlayer) -- Player is not in vehicle end addCommandHandler("createvehicle", createVehicleForPlayer) -- Extra code removed until I can resolve the current issue.
  5. Hello, I'm here today to ask if anybody can say whether I am on the right track or not. The only experience I have in LUA is 2 years of Roblox LUA (yes you can laugh, but for being 12 years old at the time I thought I did a pretty good job). So, this is my first script in a while, what I'm trying to do is that when a player spawns or enters a new vehicle, it gets the old vehicle's ID (assuming the player had a previous vehicle) and deletes the old vehicle, then it will spawn (or the player enters) a vehicle and assign a new ID to it, with the ID being "(playername)1". I'm not asking for somebody to do all the work and fix this for me, I'm just asking for feedback. --Assigns ID on vehicle spawn and deletes old vehicle function createVehicleForPlayer(thePlayer, command, vehicleModel) local x, y, z = getElementPosition(thePlayer) --gets position of players x,y,z x = x + 3 local createdVehicle = createVehicle(tonumber(vehicleModel),x, y, z) i=1 getElementByID ( player[i] ) destroyElement getPedOccupiedVehicle ( player ) setElementID ( player[i] )else if (createdVehicle == false) then outputChatBox("Failed to create vehicle.", thePlayer) end addCommandHandler("createvehicle", createVehicleForPlayer) --Assigns ID on vehicle enter and deletes old vehicle function PlayerEntersVehicle getElementByID ( player[i] ) destroyElement setElementID ( player[i] ) addEventHandler("onVehicleEnter", PlayerEntersVehicle) Here's some output from the MTA Script Editor '=' expected near 'getPedOccupiedVehicle' - Line 9 '<eof>' expected near 'else' - Line 10 '(' expected near 'getElementByID' - Line 17 '=' expected near 'setElementID' - Line 19
×
×
  • Create New...