RU/giveWeapon: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Enterprise (talk | contribs)
No edit summary
Line 3: Line 3:
giveWeapon gives a specified weapon to a certain player or ped. There is an optional argument to specify ammunition. For example, a melee weapon doesn't need an ammo argument.
giveWeapon gives a specified weapon to a certain player or ped. There is an optional argument to specify ammunition. For example, a melee weapon doesn't need an ammo argument.


==Syntax==  
==Синтаксис==  
<syntaxhighlight lang="lua">bool giveWeapon ( player thePlayer, int weapon [, int ammo=30, bool setAsCurrent=false ] )</syntaxhighlight>  
<syntaxhighlight lang="lua">bool giveWeapon ( player thePlayer, int weapon [, int ammo=30, bool setAsCurrent=false ] )</syntaxhighlight>  
С помощью этой функции можно выдать оружие [[element/Player|игроку]], [[Element/Ped|педу]].
===Обязательные аргументы===
*'''thePlayer:''' [[element/Player|игроку]] или [[Element/Ped|педу]] которому выдаётся оружие.
*'''weapon:''' [[Weapon|Модель]] выдаваемого оружия.


===Required Arguments===  
===Выборочные аргументы===  
*'''thePlayer:''' A [[player]] object referencing the specified player 
*'''weapon:''' A whole number integer that refers to a [[Weapon]] ID. Click [[Weapon|here]] for a list of possible weapon IDs.


===Optional Arguments===
*'''ammo:''' Колличество патронов которое будет даваться к оружию.  Для оружий, которые не требуют боеприпасов, такие, как ближний бой, патронов будет 1.
{{OptionalArg}}
*'''setAsCurrent:''' Логическое значение будет ли оружие в руках после выдачи
*'''ammo:''' A whole number integer serving as the ammo amount for the given weapon.  For weapons that do not require ammo, such as melee, this should be at least 1.
*'''setAsCurrent:''' A boolean value determining whether or not the weapon will be set as the players current.


===Returns===  
===Возврат===  
Returns ''true'' if weapon was successfully acquired, ''false'' otherwise.
 
Возвращёет ''true'' Если оружие успешно выдано, ''false'' если иначе.
 
===Пример===
В этом примере при спавне игрока ему выдаётся M4
<syntaxhighlight lang="lua">
function giveWeaponsOnSpawn ( theSpawnpont, theTeam )
    giveWeapon ( source, 31, 200 ) -- Дадим M4 с 200 патронами
end
addEventHandler ( "onPlayerSpawn", getRootElement(), giveWeaponsOnSpawn )
</syntaxhighlight>


==Example==  
==Example==  

Revision as of 02:02, 4 September 2011

This page requires local translation. If page will remain not translated in reasonable period of time it would be deleted.
After translating the page completely, please remove the ‎{{translate}}‎ tag from the page.

giveWeapon gives a specified weapon to a certain player or ped. There is an optional argument to specify ammunition. For example, a melee weapon doesn't need an ammo argument.

Синтаксис

bool giveWeapon ( player thePlayer, int weapon [, int ammo=30, bool setAsCurrent=false ] )

С помощью этой функции можно выдать оружие игроку, педу.

Обязательные аргументы

Выборочные аргументы

  • ammo: Колличество патронов которое будет даваться к оружию. Для оружий, которые не требуют боеприпасов, такие, как ближний бой, патронов будет 1.
  • setAsCurrent: Логическое значение будет ли оружие в руках после выдачи

Возврат

Возвращёет true Если оружие успешно выдано, false если иначе.

Пример

В этом примере при спавне игрока ему выдаётся M4

function giveWeaponsOnSpawn ( theSpawnpont, theTeam )
    giveWeapon ( source, 31, 200 ) -- Дадим M4 с 200 патронами
end
addEventHandler ( "onPlayerSpawn", getRootElement(), giveWeaponsOnSpawn )

Example

Example 1: This example gives a player an M4 with 200 ammo whenever they spawn.

function giveWeaponsOnSpawn ( theSpawnpont, theTeam )
    giveWeapon ( source, 31, 200 ) -- Gives the M4 weapon with 200 ammo
end
addEventHandler ( "onPlayerSpawn", getRootElement(), giveWeaponsOnSpawn ) -- attach the event handler


Example 2: This example adds a "give" command in console which allows giving of any weapon by entering "give <id> <amount>".

function consoleGive ( thePlayer, commandName, weaponID, ammo )
	local status = giveWeapon ( thePlayer, weaponID, ammo, true )   -- attempt to give the weapon, forcing it as selected weapon
	if ( not status ) then                                          -- if it was unsuccessful
		outputConsole ( "Failed to give weapon.", thePlayer )   -- tell the player
	end
end
addCommandHandler ( "give", consoleGive )


Example 3: This example creates a ped in certain coordinates. You can give him a weapon with "give <weaponID> <amount>" command in console.

ped = createPed( 19, -1634.5775, 1203.85, 7.1796 );

addCommandHandler( "give",
  function ( player, command, id, amount )
    if not id then return end
    giveWeapon( ped, id, amount, true )
  end
)

See Also

Серверные функции

  • giveWeapon - дает указанное оружие игроку или пешеходу
  • takeAllWeapons - удаляет всё оружие с указанного игрока или пешехода
  • takeWeapon - удаляет указанное оружие или боеприпасы с игрока или пешехода
ДО ВЕРСИИ 1.3.1 :
  • takeWeaponAmmo - удаляет определённое кол-во боеприпасов у игрока для указанного оружия
  • giveWeaponAmmo - даёт определённое кол-во боеприпасов игроку для указанного оружия

Клиентские функции

Общие функции

  • getOriginalWeaponProperty - получает исходное свойство указанного типа оружия
  • getPickupWeapon - получает ID оружия из указанного пикапа
  • getSlotFromWeapon - получает слот к которому принадлежит оружие
  • getWeaponIDFromName - получает ID оружия из его названия
  • getWeaponNameFromID - получает название оружия или причину смерти из его ID
  • getWeaponProperty - получает свойство указанного оружия
  • setWeaponAmmo - устанавливает определенное кол-во боеприпасов для указанного оружия
  • setWeaponProperty - устанавливает свойство указанного типа оружия