..:D&G:.. Posted July 12, 2014 Posted July 12, 2014 Hello, I recently made a resource that changes the default car names into real ones. Here is the code: function findVehicleName() for _, theVehicle in pairs( getElementsByType( "vehicle" ) ) do local car = getVehicleID( theVehicle ) if (car==603) then return "Shelby" end if (car==474) then return "Mercedes E500" end if (car==411) then return "Lamborghini Veneno" end end end -- return " (".. getVehicleName(source) ..") " --end I don't know why, when I put that "findVehicleName" into other function, it always gets me only the Infernus (Lamborghini Veneno) instead of the right name. For example if I do something like: outputChatBox("(( This is a " .. findVehicleName(theVehicle) .. ". ))", thePlayer, 255, 195, 14) It will say it is a Lamborghini Veneno(Infernus) even though the car is a Merit or Bullet etc.. Anyone knows why? MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
Castillo Posted July 12, 2014 Posted July 12, 2014 Well, it's because you aren't using the vehicle element passed in the function arguments, you are looping all the vehicles and checking their models. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
ADCX Posted July 12, 2014 Posted July 12, 2014 CarNames = {[603] = "Shelby",[474] = "Mercedes E500", [411] = "Lamborghini Veneno"} function findVehicleName(theVehicle) return CarNames[getElementModel(theVehicle)] end My Skype: scriptmtasupport My Resources: http://www.scriptmta.co.nr - Cheap high-quality MTA resources by me and Kevin (ScriptMTA.co.nr)
..:D&G:.. Posted July 12, 2014 Author Posted July 12, 2014 Now I get "a nil value" when I use it in the other function... (The function uses onVehicleEnter event, before using findVehicleName, I used getVehicleName) MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
Max+ Posted July 12, 2014 Posted July 12, 2014 (edited) , Edited July 12, 2014 by Guest - New , Kill System - New, GameMode Intro - Leve / Exp System - New nametag showing style - New , Hud For Players - Skin Selection from SA-MP - Money System / Buy Weapons - Drop Weapons - New, Flood System - New , Group Assign - Gun license For Weapons - Random Rule System For Money
..:D&G:.. Posted July 12, 2014 Author Posted July 12, 2014 How do I make that server-side? MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
Max+ Posted July 12, 2014 Posted July 12, 2014 Change the event to addEventHandler ( 'onVehicleEnter', resourceRoot, - New , Kill System - New, GameMode Intro - Leve / Exp System - New nametag showing style - New , Hud For Players - Skin Selection from SA-MP - Money System / Buy Weapons - Drop Weapons - New, Flood System - New , Group Assign - Gun license For Weapons - Random Rule System For Money
..:D&G:.. Posted July 12, 2014 Author Posted July 12, 2014 The outputChatBox doesn't show anymore... And no errors MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
Max+ Posted July 12, 2014 Posted July 12, 2014 (edited) [quote name=..&G:..]The outputChatBox doesn't show anymore... And no errors Edited # addEventHandler ( 'onVehicleEnter' , resourceRoot, function ( ) for _, theVehicle in pairs( getElementsByType( "vehicle" ) ) do local Model = getElementModel ( theVehicle ) if ( Model == 603 ) then outputChatBox(" This is a Shelby " , source , 255, 255, 0 ) elseif ( Model == 474 ) then outputChatBox(" This is a Mercedes E500 " , source , 255, 255, 0 ) elseif ( Model == 411 ) then outputChatBox(" This is a Lamborghini Veneno " , source , 255, 255, 0 ) end end end ) --ServerSide , /debugscript 3 Edited July 12, 2014 by Guest - New , Kill System - New, GameMode Intro - Leve / Exp System - New nametag showing style - New , Hud For Players - Skin Selection from SA-MP - Money System / Buy Weapons - Drop Weapons - New, Flood System - New , Group Assign - Gun license For Weapons - Random Rule System For Money
Castillo Posted July 12, 2014 Posted July 12, 2014 That doesn't make any sense. It'll just spam the chat box with all the vehicle names, also, the loop is wrong, that sort of table can't be looped with "ipairs". San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Max+ Posted July 12, 2014 Posted July 12, 2014 That doesn't make any sense.It'll just spam the chat box with all the vehicle names, also, the loop is wrong, that sort of table can't be looped with "ipairs". What's the correct ? Becuase im , not very Good , with tabels , - New , Kill System - New, GameMode Intro - Leve / Exp System - New nametag showing style - New , Hud For Players - Skin Selection from SA-MP - Money System / Buy Weapons - Drop Weapons - New, Flood System - New , Group Assign - Gun license For Weapons - Random Rule System For Money
..:D&G:.. Posted July 12, 2014 Author Posted July 12, 2014 Doesn't work, and no errors... and tbh, I am not a very good scripter, but that function doesn't look right.. MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
Max+ Posted July 12, 2014 Posted July 12, 2014 [quote name=..&G:..]Doesn't work, and no errors... and tbh, I am not a very good scripter, but that function doesn't look right.. OK , Post Edited , Try Now , - New , Kill System - New, GameMode Intro - Leve / Exp System - New nametag showing style - New , Hud For Players - Skin Selection from SA-MP - Money System / Buy Weapons - Drop Weapons - New, Flood System - New , Group Assign - Gun license For Weapons - Random Rule System For Money
..:D&G:.. Posted July 12, 2014 Author Posted July 12, 2014 Eh.. f*ck it, I am quiting this script, just doesn't want to work I wanted to reopen my old roleplay server but it seems that the world doesn't want me to reopen it Thanks for help anywa! MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
Max+ Posted July 12, 2014 Posted July 12, 2014 [quote name=..&G:..]Eh.. f*ck it, I am quiting this script, just doesn't want to work I wanted to reopen my old roleplay server but it seems that the world doesn't want me to reopen it Thanks for help anywa! did you try the new post of mine ? what erros does it shows ? - New , Kill System - New, GameMode Intro - Leve / Exp System - New nametag showing style - New , Hud For Players - Skin Selection from SA-MP - Money System / Buy Weapons - Drop Weapons - New, Flood System - New , Group Assign - Gun license For Weapons - Random Rule System For Money
..:D&G:.. Posted July 13, 2014 Author Posted July 13, 2014 Yes I tried, and it still doesn't show nothing, not even an error... MTA:Rust Pre-Alpha Build v.0.3: https://forum.mtasa.com/viewtopic.php?f=114&t=97848 2Pac: ''Only God can judge me!''
Max+ Posted July 13, 2014 Posted July 13, 2014 [quote name=..&G:..]Yes I tried, and it still doesn't show nothing, not even an error... Hope this works , CarNames = {[603] = "Shelby",[474] = "Mercedes E500", [411] = "Lamborghini Veneno"} addEventHandler( 'onVehicleEnter', resourceRoot, function ( ) outputChatBox("You have entered " .. findVehicleName(getElementModel(source))) end ) function findVehicleName(theVehicle) return CarNames[theVehicle] end --ServerSide , - New , Kill System - New, GameMode Intro - Leve / Exp System - New nametag showing style - New , Hud For Players - Skin Selection from SA-MP - Money System / Buy Weapons - Drop Weapons - New, Flood System - New , Group Assign - Gun license For Weapons - Random Rule System For Money
Dealman Posted July 13, 2014 Posted July 13, 2014 How exactly do you want to use this...? It would help significantly to write it for you... Edit: Here's an example of how you can do it, with the script below you can execute a command like this one; "/cvn 411" - this will check if it exists in the table with custom names - if not, it will get the default vehicle name. Example, 579 will return "Huntley". I just wrote this up out of my head, so there might be some mistake somewhere, but the table check should work. Also I'm not sure what the results are if you try to check an ID like 6000. Assuming it will return false, or nil. Client-Side; local vehicleNames = { [411] = "Lamborghini Veneno", [474] = "Mercedes E500", [603] = "Shelby" }; function findVehicleName(theVehicleID) if(type(vehicleNames[theVehicleID]) == "string") then return vehicleNames[theVehicleID]; else return getVehicleNameFromModel(theVehicleID); end end function onClientCheckVehicleName_CMD(theCMD, arg1) if(arg1 ~= nil) then local ID = tonumber(arg1); local theName = findVehicleName(ID); outputChatBox(tostring(theName)); end end addCommandHandler("CVN", onClientCheckVehicleName_CMD, false, false); If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.
ADCX Posted July 13, 2014 Posted July 13, 2014 CarNames = {[603] = "Shelby",[474] = "Mercedes E500", [411] = "Lamborghini Veneno"} function findVehicleName(theVehicle) if (type(CarNames[getElementModel(theVehicle)]) == "string") then return CarNames[getElementModel(theVehicle)] else return getVehicleNameFromModel(getElementModel(theVehicle)) end end function VehicleEnter(Player) outputChatBox("You entered the " .. findVehicleName(source) .. "!",Player) end addEventHandler("onVehicleEnter",getRootElement(),VehicleEnter) Just try this, if it doesn't work, you are doing something wrong. My Skype: scriptmtasupport My Resources: http://www.scriptmta.co.nr - Cheap high-quality MTA resources by me and Kevin (ScriptMTA.co.nr)
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