SetPlayerWeapon: Difference between revisions

From Onset Developer Wiki
Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|Gives the player a weapon.}} {{FuncSyntax|SetPlayerWeapon(player, weapon_model, ammo, equip, weapon_slot)}} {{FuncParameters}..."
 
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server|1.0}}
== Important ==
The "weapons.lua" inside the "/packages/default" needs to be loaded within your own package.json. The file needs to be placed in "/packages/YourGamemodeName". Without the weapons.lua inside the folder the weapons won't load.


{{FuncDescription|Gives the player a weapon.}}
{{FuncDescription|Gives the player a weapon.}}


{{FuncSyntax|SetPlayerWeapon(player, weapon_model, ammo, equip, weapon_slot)}}
{{FuncSyntax|SetPlayerWeapon(player, weapon_model, ammo, equip, weapon_slot [, bLoaded])}}


{{FuncParameters}}
{{FuncParameters}}
Line 11: Line 13:
{{FuncParam|equip|''true'' for the player to equip the weapon. ''false'' to just assign this new weapon to a weapon slot.}}
{{FuncParam|equip|''true'' for the player to equip the weapon. ''false'' to just assign this new weapon to a weapon slot.}}
{{FuncParam|weapon_slot|The slot to assign 1-3.}}
{{FuncParam|weapon_slot|The slot to assign 1-3.}}
{{FuncParam|bLoaded|To have the magazine loaded already or not.}}


{{FuncReturnValue|Returns '''true''' on success, '''false''' on error.}}
{{FuncReturnValue|Returns '''true''' on success, '''false''' on error.}}
Line 21: Line 24:
end
end


SetPlayerWeapon(player, weapon, ammo, true, slot)
SetPlayerWeapon(player, weapon, ammo, true, slot, true)
end
end
AddCommand("w", cmd_w)
AddCommand("w", cmd_w)
Line 28: Line 31:


{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
* [[GetPlayerWeapon]]

Latest revision as of 14:24, 29 December 2021

SetPlayerWeapon

Type: Function
Context: Server
Introduced: v1.0

Important

The "weapons.lua" inside the "/packages/default" needs to be loaded within your own package.json. The file needs to be placed in "/packages/YourGamemodeName". Without the weapons.lua inside the folder the weapons won't load.

Description

Gives the player a weapon.

Syntax

SetPlayerWeapon(player, weapon_model, ammo, equip, weapon_slot [, bLoaded])

Parameters

  • player
    The player identifier.
  • weapon_model
    The weapon model Weapons.
  • ammo
    How many bullets the player gets.
  • equip
    true for the player to equip the weapon. false to just assign this new weapon to a weapon slot.
  • weapon_slot
    The slot to assign 1-3.
  • bLoaded
    To have the magazine loaded already or not.

Return Value

  • Returns true on success, false on error.

Example

function cmd_w(player, weapon, slot, ammo)
	if (weapon == nil or slot == nil or ammo == nil) then
		return AddPlayerChat(player, "Usage: /w <weapon> <slot> <ammo>")
	end

	SetPlayerWeapon(player, weapon, ammo, true, slot, true)
end
AddCommand("w", cmd_w)
AddCommand("weapon", cmd_w)

See also