Phoenix-Roleplay Posted July 14, 2012 Posted July 14, 2012 Hello MTA, I have been trying to create a fully functional vehicle spawn system but it seems at line 52 I get the following error: ERROR: pf\s_main.lua:52: attempt to compare string with number I read somewhere that lua will convert numbers to strings and likewise. Anyways, here is the script function createVehicleCommand ( thePlayer, commandName, carName ) local x, y, z = getElementPosition ( thePlayer ) if tonumber(carName) ~= nil then if carName < 400 then outputChatBox("Invalid Vehicle", player, 255, 0, 0) elseif carName > 611 then outputChatBox("Invalid Vehicle", player, 255, 0, 0) else local carM = getVehicleName(carName) createVehicle(carName, x+5, y, z) outputChatBox("Your " .. getVehicleName(carM) .. " (#" .. carM .. ") was spawned with an ID of " .. vehicles.id, player, 0, 255, 0) vehicles.id = vehicles.id+1 end else local carModel = getVehicleModelFromName(carName) if not carModel then outputChatBox("That is not a valid car name") else createVehicle(carModel, x+5, y, z) outputChatBox("Your " .. getVehicleName(carModel) .. " (#" .. carModel .. ") was spawned with and ID of " .. vehicles.id, player, 0, 255, 0) vehicles.id = vehicles.id+1 end end end addCommandHandler("v", createVehicleCommand) Line 52: if carName < 400 then Sorry if the script is slightly poorly put together, I was in a rush when trying to make this part of it. All kinds of feedback are welcome on all of my posts.
Castillo Posted July 14, 2012 Posted July 14, 2012 Command arguments will be always a string, you have to convert it to a number. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Phoenix-Roleplay Posted July 14, 2012 Author Posted July 14, 2012 Right. How would I approach whilst keeping it able to detect if someone puts in a vehicle name? Sorry, I am not familiar with working with vehicles. All kinds of feedback are welcome on all of my posts.
Castillo Posted July 14, 2012 Posted July 14, 2012 local carName = tonumber ( carName ) if ( type ( carName ) == "number" ) then if ( carName < 400 or carName > 611 ) then outputChatBox ( "Invalid Vehicle", player, 255, 0, 0 ) else -- Your code end end San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Phoenix-Roleplay Posted July 14, 2012 Author Posted July 14, 2012 It appears that it jumps straight to "That is not a valid car name" All kinds of feedback are welcome on all of my posts.
Castillo Posted July 14, 2012 Posted July 14, 2012 Post your entire script. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Phoenix-Roleplay Posted July 14, 2012 Author Posted July 14, 2012 function createVehicleCommand ( thePlayer, commandName, carName ) local x, y, z = getElementPosition ( thePlayer ) if (type(carName) == "number") then if carName < 400 then outputChatBox("Invalid Vehicle", player, 255, 0, 0) elseif carName > 611 then outputChatBox("Invalid Vehicle", player, 255, 0, 0) else local carM = getVehicleName(carName) createVehicle(carName, x+5, y, z) outputChatBox("Your " .. getVehicleName(carM) .. " (#" .. carM .. ") was spawned with an ID of " .. vehicles.id, player, 0, 255, 0) vehicles.id = vehicles.id+1 end else local carModel = getVehicleModelFromName(carName) if not carModel then outputChatBox("That is not a valid car name") else createVehicle(carModel, x+5, y, z) outputChatBox("Your " .. getVehicleName(carModel) .. " (#" .. carModel .. ") was spawned with and ID of " .. vehicles.id, player, 0, 255, 0) vehicles.id = vehicles.id+1 end end end addCommandHandler("v", createVehicleCommand) All kinds of feedback are welcome on all of my posts.
Castillo Posted July 14, 2012 Posted July 14, 2012 function createVehicleCommand ( thePlayer, commandName, carName ) local x, y, z = getElementPosition ( thePlayer ) local carModel = tonumber ( carName ) if ( type ( carModel ) == "number" ) then if ( carModel < 400 or carModel > 611 ) then outputChatBox ( "Invalid Vehicle", player, 255, 0, 0 ) else createVehicle ( carModel, x + 5, y, z ) outputChatBox ( "Your " .. getVehicleName ( carModel ) .. " (#" .. carModel .. ") was spawned with an ID of " .. vehicles.id, player, 0, 255, 0 ) vehicles.id = ( vehicles.id + 1 ) end else local carModel = getVehicleModelFromName ( carName ) if ( not carModel ) then outputChatBox ( "That is not a valid car name", player, 255, 0, 0 ) else createVehicle ( carModel, x + 5, y, z ) outputChatBox ( "Your " .. getVehicleName ( carModel ) .. " (#" .. carModel .. ") was spawned with and ID of " .. vehicles.id, player, 0, 255, 0 ) vehicles.id = ( vehicles.id + 1 ) end end end addCommandHandler ( "v", createVehicleCommand ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Cadu12 Posted July 14, 2012 Posted July 14, 2012 (edited) function createVehicleCommand ( thePlayer, commandName, carName ) local x, y, z = getElementPosition ( thePlayer ) if (type(tonumber(carName)) == "number") then if tonumber(carName) > 400 and tonumber(carName) < 611 then outputChatBox("Invalid Vehicle", player, 255, 0, 0) else local id = getElementModel(carName) createVehicle(carName, x+5, y, z) outputChatBox("Your " .. getVehicleName(id) .. " (#" .. tonumber(carName) .. ") was spawned with an ID of " .. vehicles.id, player, 0, 255, 0) vehicles.id = vehicles.id+1 end else local carModel = getVehicleModelFromName(carName) if not carModel then outputChatBox("That is not a valid car name") else createVehicle(carModel, x+5, y, z) outputChatBox("Your " .. getVehicleName(carModel) .. " (#" .. carModel .. ") was spawned with and ID of " .. vehicles.id, player, 0, 255, 0) vehicles.id = vehicles.id+1 end end end addCommandHandler("v", createVehicleCommand) Edited July 14, 2012 by Guest Ingame nick: Cadu12
Jaysds1 Posted July 14, 2012 Posted July 14, 2012 function createVehicleCommand ( thePlayer, commandName, carName ) local x, y, z = getElementPosition ( thePlayer ) if (type(carName) == "number") then if tonumber(carName) > 400 and tonumber(carName) < 611 then outputChatBox("Invalid Vehicle", player, 255, 0, 0) else local carM = getVehicleName(carName) createVehicle(carName, x+5, y, z) outputChatBox("Your " .. getVehicleName(carM) .. " (#" .. carM .. ") was spawned with an ID of " .. vehicles.id, player, 0, 255, 0) vehicles.id = vehicles.id+1 end else local carModel = getVehicleModelFromName(carName) if not carModel then outputChatBox("That is not a valid car name") else createVehicle(carModel, x+5, y, z) outputChatBox("Your " .. getVehicleName(carModel) .. " (#" .. carModel .. ") was spawned with and ID of " .. vehicles.id, player, 0, 255, 0) vehicles.id = vehicles.id+1 end end end addCommandHandler("v", createVehicleCommand) There is no use of checking if "carName" type is a number, because it's going to come as a string. My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
Jaysds1 Posted July 14, 2012 Posted July 14, 2012 oh, sorry, I've never noticed. Anyways, Phoenix, Did it worked? My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
Phoenix-Roleplay Posted July 14, 2012 Author Posted July 14, 2012 Checking now! Sorry, was busy with halo reach :3 All kinds of feedback are welcome on all of my posts.
Jaysds1 Posted July 14, 2012 Posted July 14, 2012 , Halo Reach is :~ . My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
Phoenix-Roleplay Posted July 14, 2012 Author Posted July 14, 2012 Oh don't judge! I'm sorta a fan boy of Halo, grew up off that game lol Anyways, @Cadu, it does spawn the vehicle using either a number or name. But on both parts I get: WARNING: pf\s_main.lua:56: Bad argument @ `getVehicleName` WARNING: pf\s_main.lua:58: Bad argument @ `getVehicleName` ERROR: pf\s_main.lua:58: attempt to concatenate local `carM` (a boolean value) All kinds of feedback are welcome on all of my posts.
Castillo Posted July 14, 2012 Posted July 14, 2012 Instead of keeping just with one answer, check mine as well, it should work. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Jaysds1 Posted July 14, 2012 Posted July 14, 2012 , I wont post my code until he check's yours. My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
Phoenix-Roleplay Posted July 14, 2012 Author Posted July 14, 2012 I actually jumped over yours by mistake checking it now. All kinds of feedback are welcome on all of my posts.
Jaysds1 Posted July 14, 2012 Posted July 14, 2012 Try my code, I edited it. , calm down, Everyone, He's only one person My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
Phoenix-Roleplay Posted July 14, 2012 Author Posted July 14, 2012 @Castillo, yours works but fails to display the line where it says "Your vehicle was spawned.." @Cadu, same problems. EDIT: @jays, yes but I work like a million All kinds of feedback are welcome on all of my posts.
Jaysds1 Posted July 14, 2012 Posted July 14, 2012 try this: function createVehicleCommand ( thePlayer, commandName, carName ) local x, y, z = getElementPosition ( thePlayer ) if (type(tonumber(carName)) == "number") then if tonumber(carName) > 400 and tonumber(carName) < 611 then outputChatBox("Invalid Vehicle", player, 255, 0, 0) else local carM = getVehicleNameFromModel(carName) createVehicle(carName, x+5, y, z) outputChatBox("Your " .. carM .. " (#" .. carName .. ") was spawned with an ID of " .. vehicles.id, player, 0, 255, 0) vehicles.id = vehicles.id+1 end else local carModel = getVehicleModelFromName(carName) if not carModel then outputChatBox("That is not a valid car name") else createVehicle(carModel, x+5, y, z) outputChatBox("Your " .. getVehicleName(carModel) .. " (#" .. carModel .. ") was spawned with and ID of " .. vehicles.id, player, 0, 255, 0) vehicles.id = vehicles.id+1 end end end addCommandHandler("v", createVehicleCommand) My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
Phoenix-Roleplay Posted July 14, 2012 Author Posted July 14, 2012 @Jays, it seems using yours no matter what I get the "Your (#...) was spawned.." All kinds of feedback are welcome on all of my posts.
Castillo Posted July 14, 2012 Posted July 14, 2012 function createVehicleCommand ( thePlayer, commandName, carName ) local x, y, z = getElementPosition ( thePlayer ) local carModel = tonumber ( carName ) if ( type ( carModel ) == "number" ) then if ( carModel < 400 or carModel > 611 ) then outputChatBox ( "Invalid Vehicle", player, 255, 0, 0 ) else createVehicle ( carModel, x + 5, y, z ) outputChatBox ( "Your " .. getVehicleNameFromModel ( carModel ) .. " (#" .. carModel .. ") was spawned with an ID of " .. vehicles.id, player, 0, 255, 0 ) vehicles.id = ( vehicles.id + 1 ) end else local carModel = getVehicleModelFromName ( carName ) if ( not carModel ) then outputChatBox ( "That is not a valid car name", player, 255, 0, 0 ) else createVehicle ( carModel, x + 5, y, z ) outputChatBox ( "Your " .. getVehicleNameFromModel ( carModel ) .. " (#" .. carModel .. ") was spawned with and ID of " .. vehicles.id, player, 0, 255, 0 ) vehicles.id = ( vehicles.id + 1 ) end end end addCommandHandler ( "v", createVehicleCommand ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Jaysds1 Posted July 14, 2012 Posted July 14, 2012 (edited) ok, I tried something else, here: function createVehicleCommand ( thePlayer, _, carName ) local x, y, z = getElementPosition ( thePlayer ) local carModel = getVehicleModelFromName(carName) local carName = getVehicleNameFromModel(tonumber(carName)) if carModel then createVehicle(carModel, x+5, y, z) outputChatBox("Your " .. getVehicleNameFromModel(carModel) .. " (#" .. carModel .. ") was spawned with an ID of " .. vehicles.id, thePlayer, 0, 255, 0) elseif carName then local carM = getVehicleModelFromName(carName) createVehicle(carM, x+5, y, z) outputChatBox("Your " .. carName .. " (#" .. carM .. ") was spawned with and ID of " .. vehicles.id, thePlayer, 0, 255, 0) else outputChatBox("That is not a valid car name/model",thePlayer) end end addCommandHandler("v", createVehicleCommand) Edited July 14, 2012 by Guest My in-game name: Jaysds1 Retired CMG Scripter World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/
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