Jump to content

HELP Custom Car Names


Recommended Posts

Posted

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.

Posted

use

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

Posted

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.

Posted

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 

Posted
GetVehicleModel function exists?

I don't think so, use getElementModel.

yep...

Try:

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

  • Moderators
Posted

Function works:

/srun getVehicleNameFromModel(470)

Command results: Patriot [string]

I recommend in case of wrong model:

return {getVehicleNameFromModel(model) or "", 1} 

  • Moderators
Posted

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.

Posted

Heh, the only thing I wanted was that it actually showed the custom car

> Example: This 1993 Sabaru Impreza Belongs to Brian O'Donnald.

Since I forgot what I had to do, I made this topic..

  • Moderators
Posted

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 

  • Moderators
Posted
That didn't work though.

Still thanks for taking the effort.

Then your problem is somewhere else.

Posted
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.

  • Moderators
Posted

Example why you get this error:

theError =  {}  .. "" 

attempt to concatenate a table value

Posted
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) 

Posted

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

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...