..:D&G:.. Posted July 12, 2014 Share 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? Link to comment
Castillo Posted July 12, 2014 Share 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. Link to comment
ADCX Posted July 12, 2014 Share Posted July 12, 2014 CarNames = {[603] = "Shelby",[474] = "Mercedes E500", [411] = "Lamborghini Veneno"} function findVehicleName(theVehicle) return CarNames[getElementModel(theVehicle)] end Link to comment
..:D&G:.. Posted July 12, 2014 Author Share 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) Link to comment
Max+ Posted July 12, 2014 Share Posted July 12, 2014 (edited) , Edited July 12, 2014 by Guest Link to comment
..:D&G:.. Posted July 12, 2014 Author Share Posted July 12, 2014 How do I make that server-side? Link to comment
Max+ Posted July 12, 2014 Share Posted July 12, 2014 Change the event to addEventHandler ( 'onVehicleEnter', resourceRoot, Link to comment
..:D&G:.. Posted July 12, 2014 Author Share Posted July 12, 2014 The outputChatBox doesn't show anymore... And no errors Link to comment
Max+ Posted July 12, 2014 Share 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 Link to comment
Castillo Posted July 12, 2014 Share 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". Link to comment
Max+ Posted July 12, 2014 Share 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 , Link to comment
..:D&G:.. Posted July 12, 2014 Author Share 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.. Link to comment
Max+ Posted July 12, 2014 Share 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 , Link to comment
..:D&G:.. Posted July 12, 2014 Author Share 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! Link to comment
Max+ Posted July 12, 2014 Share 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 ? Link to comment
..:D&G:.. Posted July 13, 2014 Author Share Posted July 13, 2014 Yes I tried, and it still doesn't show nothing, not even an error... Link to comment
Max+ Posted July 13, 2014 Share 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 , Link to comment
Dealman Posted July 13, 2014 Share 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); Link to comment
ADCX Posted July 13, 2014 Share 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. 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