GetVehicleName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (updated)
Line 16: Line 16:
This example checks whether a player enters an AT-400 or a Shamal.  If they do, it announces it to the chat specifying what vehicle was stolen.
This example checks whether a player enters an AT-400 or a Shamal.  If they do, it announces it to the chat specifying what vehicle was stolen.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- add the event to the event handler
function planeEnter ( theVehicle, seat, jacked ) --when someone enters a vehicle
addEventHandler ( "onPlayerEnterVehicle", root, "onPlayerEnterVehicle" )
   id = getVehicleID ( theVehicle ) -- get the ID of the vehicle
function onPlayerEnterVehicle ( vehicle, seat, jacked ) --when someone enters a vehicle
   if id == 519 or 577 then --if theVehicle is one of these two planes
   id = getVehicleID ( vehicle ) -- get the ID of the vehicle
     vehiclename = getVehicleName ( theVehicle ) -- define the vehicle name  
   if id == 519 or 577 then --if the vehicle is one of these two planes
     outputChatBox ( "Someone stole a "..vehiclename.."!" ) -- announce that someone stole the plane
     vehiclename = getVehicleName ( vehicle ) -- define the vehicle name  
     outputChatBox ( "Someone stole the "..vehiclename.."!" ) -- announce that someone stole the plane
   end
   end
end
end
-- add the event to the event handler
addEventHandler ( "onPlayerEnterVehicle", getRootElement(), planeEnter )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Vehicle_functions}}
{{Vehicle_functions}}

Revision as of 16:25, 8 July 2007

This function returns a string containing the name of the vehicle

Syntax

string getVehicleName ( vehicle theVehicle )             

Required Arguments

  • theVehicle: The vehicle you want to get the name of.

Returns

Returns a string containing the requested vehicle's name, or false if the vehicle passed to the function is invalid.

Example

This example checks whether a player enters an AT-400 or a Shamal. If they do, it announces it to the chat specifying what vehicle was stolen.

function planeEnter ( theVehicle, seat, jacked ) --when someone enters a vehicle
  id = getVehicleID ( theVehicle ) -- get the ID of the vehicle
  if id == 519 or 577 then --if theVehicle is one of these two planes
     vehiclename = getVehicleName ( theVehicle ) -- define the vehicle name 
     outputChatBox ( "Someone stole a "..vehiclename.."!" ) -- announce that someone stole the plane
  end
end
-- add the event to the event handler
addEventHandler ( "onPlayerEnterVehicle", getRootElement(), planeEnter )

See Also