Jump to content

HELP Custom Car Names


Recommended Posts

Well, in the begin of the script i've got

local carname = { }

carname[506] = {"Austin Martin Z12 Zagato MD10"}

carname[560] = {"1993 Subaru Impreza"}

when I do

outputChatBox("(( This " .. tostring(carname) .. " belongs to " .. ownerName .. ". ))", thePlayer, 255, 195, 14)

it gives me those variables.

in the spoiler it says vehnameid which is the vehicles.sql. shows nil when I enter the car.

Link to comment

Oh i get it, that wont work, it was stated in another topic some time ago, using direct numbers as a variable in the table will determine a table position, and therefore, not work.

Therefore use something like this:

  
outputChatBox("(( This " .. tostring(carname."a"..getVehicleModel(source)[1]) .. " belongs to " .. ownerName .. ". ))", thePlayer, 255, 195, 14) 
--Remember to edit the table at the start of the script 
local carname = { } 
carname.a506 = {"Austin Martin Z12 Zagato MD10"} 
carname.a560 = {"1993 Subaru Impreza"} 
  

Also, you are returning a table in the carname, since the names are inside a table.

Link to comment

That didn't work though..

Still, thanks for trying.

That's what i've got to get the new name.

function getVehicleCustomNameAndIDFromModel(model) 
    local exists = 0 
    for k,v in pairs(carname) do 
        if k == model then 
            exists = 1 
        end 
    end 
    if exists == 1 then 
        local newvehnameid = math.random(1,#carname[model]) 
        return {carname[model][newvehnameid], newvehnameid} 
    else 
        return {getVehicleNameFromModel(model), 1} 
    end 
end 

Link to comment
  • Moderators

You said the function didn't work.... so I showed you it does work.

Never heard of runcode?

https://wiki.multitheftauto.com/wiki/Resource:Runcode

You can execute all kinds of code with it. (client/server)

Example:

/start runcode  
  
/srun player = getPlayerFromName("[HB]IIYAMA") 
/srun setElemenPosition(player,0,0,10) 
/srun setElementHealth(player,100) 
/srun setElementFrozen(player,true) 
/srun setElementFrozen(player,false) 

Je moet meer outputDebugString gebruiken om te zien wat er fout gaat. Ik kan eigenlijk het probleem van je in deze stukjes code niet vinden.

Link to comment
  • Moderators

I am not blind, I can see who wrote the topic.

function getVehicleCustomNameAndIDFromModel(model) 
    if model then 
        local carnameBuffered = carname[model] 
        if carnameBuffered then 
            local newvehnameid = math.random(1,#carnameBuffered) 
            return {carnameBuffered[newvehnameid] or getVehicleNameFromModel(model) or "", newvehnameid == 0 and 1 or newvehnameid} 
        else 
            return {getVehicleNameFromModel(model) or "", 1} 
        end 
    else 
        outputDebugString("ERROR: Invalid model") 
    end 
end 

Link to comment
That didn't work though.

Still thanks for taking the effort.

Then your problem is somewhere else.

Perhaps, yes, might have to make some clientside script aswell.

Not Really. Your error is as he said somewhere else. Any errors in debug?

PD: getting the vehicle name from model will return GTA:SA's one.

Link to comment
outputChatBox("(( This " .. tostring(carname[getElementModel(source)][1]) .. " belongs to " .. ownerName .. ". ))", thePlayer, 255, 195, 14) --use first value of the tabble carname[model] ( carname[model][1] ) 

OR:

local carname = { } 
carname[506] = "Austin Martin Z12 Zagato MD10" 
carname[560] = "1993 Subaru Impreza" --notice I moved the strings out of the tables { } 

with

outputChatBox("(( This " .. tostring(carname[getElementModel(source)]) .. " belongs to " .. ownerName .. ". ))", thePlayer, 255, 195, 14) 

Link to comment

That did work!

I got another problem

table.insert(content, {"   -  " ..(getElementData(source, "carname[model]") or getVehicleNameFromModel( getElementModel( source ) ))} ) 

I've tried some options neither did they work. I actually want the custom carname to show instead of the mta model

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...