Difference between revisions of "SetPedArmor"

From Multi Theft Auto: Wiki
Jump to: navigation, search
 
Line 19: Line 19:
 
This example removes the armor of a player.
 
This example removes the armor of a player.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
function givePlayerArmor ( player, command )
+
function armor (player, command)
setPedArmor ( player, 100 )    -- Set player's armor to 100 when he types the command 'addarmor'
+
  if command == "addarmor" then
 +
      setPedArmor ( player, 100 )    -- Set player's armor to 100 when he types the command 'addarmor'
 +
  elseif command == "removearmor" then
 +
      setPedArmor ( player, 0 )      -- Set player's armor to 0 when he types the command 'removearmor'
 +
  end
 
end
 
end
addCommandHandler ( "addarmor", givePlayerArmor )
+
addCommandHandler ("addarmor", armor)
 +
addCommandHandler ("removearmor", armor)
  
function removePlayerArmor ( player, command )
 
setPedArmor ( player, 0 )      -- Set player's armor to 0 when he types the command 'removearmor'
 
end
 
addCommandHandler ( "removearmor", removePlayerArmor )
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 33: Line 34:
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
function givePlayerArmor( player, command, amount )
 
function givePlayerArmor( player, command, amount )
if getPedArmor(player) == 100 then
+
  if getPedArmor(player) == 100 then
return
+
      outputChatBox("Your armor already is complete!", player, 220, 0, 0 ) -- Inform the player if your armor already is complete.
outputChatBox("Your armor already is complete!", player, 220, 0, 0 ) -- Inform the player if your armor already is complete.
+
      return
end
+
  end
if amount and tonumber(amount) >= 1 or tonumber(amount) <= 100 then -- If amount is between 1 and 100.
+
 
setPedArmor( player, tonumber(amount) )    -- Set amount armor that player chosen on the command.
+
  if amount and tonumber(amount) >= 1 or tonumber(amount) <= 100 then -- If amount is between 1 and 100.
else
+
      setPedArmor(player, tonumber(amount))    -- Set amount armor that player chosen on the command.
return
+
  else
end
+
      outputChatBox( "Syntax: /addarmor [armor-amount] the amount should be between 1 and 100", player, 220, 0, 0 ) -- Inform the player if 'amount' argument is missing.
if not amount then
+
  end
outputChatBox( "sintax: /addarmor [armor-amount]", player, 220, 0, 0 ) -- Inform the player if 'amount' argument is missing.
 
end
 
 
end
 
end
 
addCommandHandler( "addarmor", givePlayerArmor )
 
addCommandHandler( "addarmor", givePlayerArmor )

Latest revision as of 11:43, 10 October 2016

This function allows you to set the armor value of a ped.

Syntax

bool setPedArmor ( ped thePed, float armor )

OOP Syntax Help! I don't understand this!

Method: ped:setArmor(...)
Variable: .armor
Counterpart: getPedArmor

Required Arguments

  • thePed: the ped whose armor you want to modify.
  • armor: the amount of armor you want to set on the ped. Valid values are from 0 to 100.

Returns

Returns true if the armor was changed succesfully. Returns false if an invalid ped was specified, or the armor value specified is out of acceptable range.

Example

This example removes the armor of a player.

function armor (player, command)
   if command == "addarmor" then 
      setPedArmor ( player, 100 )    -- Set player's armor to 100 when he types the command 'addarmor'
   elseif command == "removearmor" then 
      setPedArmor ( player, 0 )      -- Set player's armor to 0 when he types the command 'removearmor'
   end 
end
addCommandHandler ("addarmor", armor)
addCommandHandler ("removearmor", armor)

In this, adds an amount of armor that the player defined in command 'addarmor'.

function givePlayerArmor( player, command, amount )
   if getPedArmor(player) == 100 then
      outputChatBox("Your armor already is complete!", player, 220, 0, 0 ) -- Inform the player if your armor already is complete.
      return
   end

   if amount and tonumber(amount) >= 1 or tonumber(amount) <= 100 then -- If amount is between 1 and 100.
      setPedArmor(player, tonumber(amount))    -- Set amount armor that player chosen on the command.
   else
      outputChatBox( "Syntax: /addarmor [armor-amount] the amount should be between 1 and 100", player, 220, 0, 0 ) -- Inform the player if 'amount' argument is missing.
   end
end
addCommandHandler( "addarmor", givePlayerArmor )

See Also