Jump to content

Change vehicle names


LagParty

Recommended Posts

Thanks 50p.

Here's my working code: (if anyone is interested)

Server side:

--read the xml file yadda yadda
local rootElement = getRootElement()
 
function cargarXml()
local i = 0
 
local xmlRoot = xmlLoadFile( "vehicles.xml" )
local xmlTag = xmlFindChild( xmlRoot, "group", i )
local xmlName = xmlNodeGetAttribute( xmlTag, "name" )
 
while xmlName ~= "Todos los cambiados" do
	xmlTag = xmlFindChild( xmlRoot, "group", i )
	xmlName = xmlNodeGetAttribute( xmlTag, "name" )
	i = i+1;
end
 
i = 0
 
--[[here we will save the important values,
    tablaid is a table with integers representing each of the replaced cars id's. 
    nombres is another table with strings representing the new names for those cars.]] 
 
tablaid = {}
nombres = {}
 
 
local xmlCars = xmlFindChild( xmlTag, "vehicle", i)
 
while xmlCars do 
table.insert( tablaid, tonumber(xmlNodeGetAttribute(xmlCars, "id")) )
table.insert( nombres, xmlNodeGetAttribute(xmlCars, "name") )
	i = i+1
	xmlCars = xmlFindChild( xmlTag, "vehicle", i)
end
 
xmlUnloadFile(xmlRoot)
 
end
addEventHandler("onResourceStart", rootElement, cargarXml)
 
--Here's the important part:
function entrar ( theVehicle )
showPlayerHudComponent ( source, "vehicle_name", true )
for i,v in ipairs(tablaid) do
if (v==getElementModel(theVehicle)) then
showPlayerHudComponent ( source, "vehicle_name", false )
		playerCarName = nombres[i]
triggerClientEvent( source, "MostrarNombre", rootElement, playerCarName )
end
end
end
addEventHandler ( "onPlayerVehicleEnter", rootElement, entrar )

Client side:

--get some important values and create some more
local rootElement = getRootElement()
local screenWidth, screenHeight = guiGetScreenSize()
local x = screenWidth*0.25
local y = screenHeight*0.95
local carName = "fail"
local i = 0
 
function createText ()
--smooth fade in/out
i = i+1
local alpha = 255
if i < 63 then 
	alpha = i*4
elseif i >= 190 then 
	alpha = (250-i)*4
end
 
--black border
dxDrawText( carName, x+1, y, screenWidth, screenHeight, tocolor ( 0, 0, 0, alpha ), 1.2, "bankgothic" )
dxDrawText( carName, x-1, y, screenWidth, screenHeight, tocolor ( 0, 0, 0, alpha ), 1.2, "bankgothic" )
dxDrawText( carName, x, y+1, screenWidth, screenHeight, tocolor ( 0, 0, 0, alpha ), 1.2, "bankgothic" )
dxDrawText( carName, x, y-1, screenWidth, screenHeight, tocolor ( 0, 0, 0, alpha ), 1.2, "bankgothic" )
--green text
dxDrawText( carName, x, y, screenWidth, screenHeight, tocolor ( 54, 104, 44, alpha ), 1.2, "bankgothic" )
 
--we don't want to see the text forever:
if i==250 then
removeEventHandler("onClientRender",rootElement, createText)
end
end
 
--called by the server:
function HandleText( var )
carName = var
i = 0
addEventHandler("onClientRender",rootElement, createText)
end
 
addEvent("MostrarNombre", true)
addEventHandler("MostrarNombre",rootElement, HandleText)

And here's my example xml file, i'm using these scripts with freeroam vehicles.xml

<catalog type="vehicle">
<group name="Vehiculos aereos">
<group name="Helicopteros">
<vehicle id="548" name="Cargobob" />
<vehicle id="425" name="Hunter" />
<vehicle id="417" name="Leviathan" />
<vehicle id="487" name="Maverick" />
<vehicle id="488" name="News Chopper" />
<vehicle id="497" name="Police Maverick" />
<vehicle id="563" name="Raindance" />
<vehicle id="447" name="Seasparrow" />
<vehicle id="469" name="Sparrow" />
</group>
<group name="Aviones y jets">
<vehicle id="592" name="Andromada" />
<vehicle id="577" name="AT-400" />
<vehicle id="511" name="Beagle" />
<vehicle id="512" name="Cropduster" />
<vehicle id="593" name="Dodo" />
<vehicle id="520" name="Hydra" />
<vehicle id="553" name="Nevada" />
<vehicle id="476" name="Rustler" />
<vehicle id="519" name="Shamal" />
<vehicle id="460" name="Skimmer" />
<vehicle id="513" name="Stuntplane" />
</group>
</group>
<group name="Motos y Bicicletas">
<group name="Motos">
<vehicle id="581" name="BF-400" />
<vehicle id="462" name="Faggio" />
<vehicle id="521" name="FCR-900" />
<vehicle id="463" name="Freeway" />
<vehicle id="523" name="HPV1000" />
<vehicle id="522" name="NRG-500" />
<vehicle id="461" name="PCJ-600" />
<vehicle id="448" name="Pizza Boy" />
<vehicle id="468" name="Sanchez" />
<vehicle id="586" name="Wayfarer" />
<vehicle id="471" name="Quadbike" />
</group>
<group name="Bicicletas">
<vehicle id="509" name="Bike" />
<vehicle id="481" name="BMX" />
<vehicle id="510" name="Mountain bike" />
</group>
</group>
<group name="Botes">
<vehicle id="472" name="Coastguard" />
<vehicle id="473" name="Dinghy" />
<vehicle id="493" name="Jetmax" />
<vehicle id="595" name="Launch" />
<vehicle id="484" name="Marquis" />
<vehicle id="430" name="Predator" />
<vehicle id="453" name="Reefer" />
<vehicle id="452" name="Speeder" />
<vehicle id="446" name="Squalo" />
<vehicle id="454" name="Tropic" />
</group>
<group name="Autos">
<group name="Deportivos">
<vehicle id="602" name="Alpha" />
<vehicle id="429" name="Banshee" />
<vehicle id="402" name="Buffalo" />
<vehicle id="541" name="Bullet" />
<vehicle id="415" name="Cheetah" />
<vehicle id="480" name="Comet" />
<vehicle id="562" name="Elegy" />
<vehicle id="587" name="Euros" />
<vehicle id="565" name="Flash" />
<vehicle id="411" name="Infernus" />
<vehicle id="559" name="Jester" />
<vehicle id="603" name="Phoenix" />
<vehicle id="560" name="Sultan" />
<vehicle id="506" name="Super GT" />
<vehicle id="451" name="Turismo" />
<vehicle id="558" name="Uranus" />
<vehicle id="555" name="Windsor" />
<vehicle id="477" name="ZR-350" />
</group>
<group name="Lowriders">
<vehicle id="536" name="Blade" />
<vehicle id="575" name="Broadway" />
<vehicle id="518" name="Buccaneer" />
<vehicle id="419" name="Esperanto" />
<vehicle id="534" name="Remington" />
<vehicle id="567" name="Savanna" />
<vehicle id="535" name="Slamvan" />
<vehicle id="576" name="Tornado" />
<vehicle id="412" name="Voodoo" />
</group>
<group name="2 Puertas">
<vehicle id="496" name="Blista Compact" />
<vehicle id="401" name="Bravura" />
<vehicle id="527" name="Cadrona" />
<vehicle id="542" name="Clover" />
<vehicle id="589" name="Club" />
<vehicle id="533" name="Feltzer" />
<vehicle id="526" name="Fortune" />
<vehicle id="474" name="Hermes" />
<vehicle id="545" name="Hustler" />
<vehicle id="517" name="Majestic" />
<vehicle id="410" name="Manana" />
<vehicle id="436" name="Previon" />
<vehicle id="475" name="Sabre" />
<vehicle id="439" name="Stallion" />
<vehicle id="549" name="Tampa" />
<vehicle id="491" name="Virgo" />
</group>
<group name="4 Puertas">
<vehicle id="445" name="Admiral" />
<vehicle id="438" name="Cabbie" />
<vehicle id="507" name="Elegant" />
<vehicle id="585" name="Emperor" />
<vehicle id="466" name="Glendale" />
<vehicle id="492" name="Greenwood" />
<vehicle id="546" name="Intruder" />
<vehicle id="551" name="Merit" />
<vehicle id="516" name="Nebula" />
<vehicle id="467" name="Oceanic" />
<vehicle id="426" name="Premier" />
<vehicle id="547" name="Primo" />
<vehicle id="405" name="Sentinel" />
<vehicle id="580" name="Stafford" />
<vehicle id="409" name="Stretch" />
<vehicle id="550" name="Sunrise" />
<vehicle id="566" name="Tahoma" />
<vehicle id="420" name="Taxi" />
<vehicle id="540" name="Vincent" />
<vehicle id="421" name="Washington" />
<vehicle id="529" name="Willard" />
</group>
</group>
<group name="Emergencias">
<vehicle id="416" name="Ambulance" />
<vehicle id="433" name="Barracks" />
<vehicle id="427" name="Enforcer" />
<vehicle id="490" name="FBI rancher" />
<vehicle id="528" name="FBI truck" />
<vehicle id="407" name="Fire truck" />
<vehicle id="544" name="Fire truck (ladder)" />
<vehicle id="596" name="Police car (LS)" />
<vehicle id="598" name="Police car (LV)" />
<vehicle id="597" name="Police car (SF)" />
<vehicle id="599" name="Police ranger" />
<vehicle id="432" name="Rhino" />
<vehicle id="601" name="S.W.A.T." />
</group>
<group name="Vehiculos pesados">
<group name="Industriales">
<vehicle id="524" name="Cement truck" />
<vehicle id="578" name="DFT-30" />
<vehicle id="486" name="Dozer" />
<vehicle id="406" name="Dumper" />
<vehicle id="573" name="Dune" />
<vehicle id="455" name="Flatbed" />
<vehicle id="530" name="Forklift" />
<vehicle id="403" name="Linerunner" />
<vehicle id="443" name="Packer" />
<vehicle id="515" name="Roadtrain" />
<vehicle id="574" name="Sweeper" />
<vehicle id="514" name="Tanker" />
<vehicle id="525" name="Towtruck" />
<vehicle id="408" name="Trashmaster" />
<vehicle id="552" name="Utility van" />
</group>
<group name="Acoples">
<vehicle id="606" name="Baggage trailer (covered)" />
<vehicle id="607" name="Baggage trailer (Uncovered)" />
<vehicle id="610" name="Farm trailer" />
<vehicle id="537" name="Freight train" />
<vehicle id="590" name="Freight train boxcar" />
<vehicle id="569" name="Freight train flatbed" />
<vehicle id="611" name="Street Clean trailer" />
<vehicle id="584" name="Gas trailer" />
<vehicle id="608" name="Trailer 1" />
<vehicle id="435" name="Trailer 2" />
<vehicle id="450" name="Trailer 3" />
<vehicle id="591" name="Trailer 4" />
</group>
<group name="Camiones">
<vehicle id="499" name="Benson" />
<vehicle id="609" name="Black Boxville" />
<vehicle id="422" name="Bobcat" />
<vehicle id="498" name="Boxville" />
<vehicle id="414" name="Mule" />
<vehicle id="600" name="Picador" />
<vehicle id="543" name="Sadler" />
<vehicle id="428" name="Securicar" />
<vehicle id="478" name="Walton" />
<vehicle id="456" name="Yankee" />
<vehicle id="554" name="Yosemite" />
</group>
<group name="Camionetas">
<vehicle id="459" name="Berkley's RC van" />
<vehicle id="482" name="Burrito" />
<vehicle id="483" name="Camper" />
<vehicle id="508" name="Journey" />
<vehicle id="418" name="Moonbeam" />
<vehicle id="582" name="News van" />
<vehicle id="413" name="Pony" />
<vehicle id="440" name="Rumpo" />
</group>
</group>
<group name="Miscelaneos">
<group name="Otros">
<vehicle id="485" name="Baggage" />
<vehicle id="568" name="Bandito" />
<vehicle id="424" name="BF Injection" />
<vehicle id="504" name="Bloodring Banger" />
<vehicle id="538" name="Brownstreak Engine" />
<vehicle id="431" name="Bus" />
<vehicle id="457" name="Caddy" />
<vehicle id="437" name="Coach" />
<vehicle id="532" name="Combine harvester" />
<vehicle id="588" name="Hotdog" />
<vehicle id="434" name="Hotknife" />
<vehicle id="494" name="Hotring racer" />
<vehicle id="502" name="Hotring racer 2" />
<vehicle id="503" name="Hotring racer 3" />
<vehicle id="444" name="Monster" />
<vehicle id="556" name="Monster 2" />
<vehicle id="557" name="Monster 3" />
<vehicle id="572" name="Mower" />
<vehicle id="423" name="Mr. Whoopee" />
<vehicle id="570" name="Kart" />
<vehicle id="531" name="Tractor" />
<vehicle id="449" name="Trolly" />
<vehicle id="583" name="Tug" />
<vehicle id="539" name="Vortex" />
</group>
<group name="Vehiculos radiocontrolados">
<vehicle id="441" name="RC Bandit" />
<vehicle id="464" name="RC Baron" />
<vehicle id="594" name="RC Flower Pot" />
<vehicle id="501" name="RC Goblin" />
<vehicle id="465" name="RC Raider" />
<vehicle id="564" name="RC Tiger" />
</group>
</group>
<group name="SUVs y Wagons">
<vehicle id="579" name="Huntley" />
<vehicle id="400" name="Landstalker" />
<vehicle id="500" name="Mesa" />
<vehicle id="470" name="Patriot" />
<vehicle id="404" name="Perennial" />
<vehicle id="489" name="Rancher" />
<vehicle id="479" name="Regina" />
<vehicle id="442" name="Romero" />
<vehicle id="495" name="Sandking" />
<vehicle id="458" name="Solair" />
Link to comment
Looks good. You could release that as a resource on the MTA community site.

I'll work on that.

Yeah, nice. My only critisism is the use of ticks instead of time - people with high FPS will find the text dissappearing quicker than others.

Also, in future people may be interested in a custom locations text.

If i release it as a standalone resource then it will work with a custon xml file.

If i use the setTimer function the text flashes, so if you know any workaround for that i'll use it.

Link to comment
The difference between 30fps and 50fps is 3 seconds, not a big deal.

https://community.multitheftauto.com/index.php?p= ... ils&id=488

There's the standalone-freeroam resource, updated with more comments and that kind of stuff.

What do you mean 3 seconds? The difference between 30fps and 50fps is only 20fps which is not 3 seconds (it's 1 second on slow PCs).

getTickCount is solution for you. Just getTickCount when you started to show text add amount of seconds that text should last for and then check if getTickCount returns more than your (start tick count + your time).

You should know how to do it, but in case you don't:

startedAt = getTickCount( )
 
-----
if getTickCount( ) < startedAt + 4000 then -- 4seconds
-- show your text
else
-- stop showing your text
end

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