Difference between revisions of "GetVehicleName"

From Multi Theft Auto: Wiki
m
(OOP)
 
(6 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__  
+
__NOTOC__
 +
{{Server client function}}
 
This function returns a string containing the name of the vehicle
 
This function returns a string containing the name of the vehicle
  
Line 6: Line 7:
 
string getVehicleName ( vehicle theVehicle )             
 
string getVehicleName ( vehicle theVehicle )             
 
</syntaxhighlight>  
 
</syntaxhighlight>  
 
+
{{OOP||[[vehicle]]:getName|name}}
 
===Required Arguments===  
 
===Required Arguments===  
*'''theVehicle:''' The vehicle you want to get the name of.  
+
*'''theVehicle:''' the [[vehicle]] you want to get the name of.  
  
 
===Returns===
 
===Returns===
Returns a string containing the requested vehicle's name, or false if the vehicle passed to the function is invalid.
+
Returns a string containing the requested vehicle's name, or ''false'' if the vehicle passed to the function is invalid.
  
 
==Example==  
 
==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.
 
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" )
+
    local id = getElementModel ( theVehicle ) -- get the model ID of the vehicle
function onPlayerEnterVehicle ( vehicle, seat, jacked ) --when someone enters a vehicle
+
    if id == 519 or id == 577 then -- if theVehicle is either Shamal or AT-400
  id = getVehicleID ( vehicle ) -- get the ID of the vehicle
+
        local vehicleName = getVehicleName ( theVehicle ) -- get the name of theVehicle
  if id == 519 or 577 then --if the vehicle is one of these two planes
+
        outputChatBox ( "Someone has stolen a " .. vehicleName .. "!" ) -- announce that someone has stolen the plane
    vehiclename = getVehicleName ( vehicle ) -- define the vehicle name  
+
    end
    outputChatBox ( "Someone stole the "..vehiclename.."!" ) -- announce that someone stole the plane
 
  end
 
 
end
 
end
 +
-- add the event handler to the event
 +
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), planeEnter )
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
==See Also==
 
==See Also==
 
{{Vehicle_functions}}
 
{{Vehicle_functions}}
 +
[[ru:getVehicleName]]

Latest revision as of 16:07, 13 October 2014

This function returns a string containing the name of the vehicle

Syntax

string getVehicleName ( vehicle theVehicle )             

OOP Syntax Help! I don't understand this!

Method: vehicle:getName(...)
Variable: .name

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
    local id = getElementModel ( theVehicle ) -- get the model ID of the vehicle
    if id == 519 or id == 577 then -- if theVehicle is either Shamal or AT-400
        local vehicleName = getVehicleName ( theVehicle ) -- get the name of theVehicle
        outputChatBox ( "Someone has stolen a " .. vehicleName .. "!" ) -- announce that someone has stolen the plane
    end
end
-- add the event handler to the event
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), planeEnter )

See Also

BETA: FROM VERSION 1.6 r7485 ONWARDS
BETA: FROM VERSION 1.6 r7485 ONWARDS