GetPlayerPreviousAndNextWeapon: Difference between revisions
Jump to navigation
Jump to search
(→Syntax) |
(→Code) |
||
| Line 11: | Line 11: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function getPreviousAndNextWeapon(player) | function getPreviousAndNextWeapon(player) | ||
assert( isElement(player) and getElementType(player) == "player", "@getPreviousAndNextWeapon, expected player at argument '1', received ".. tostring(player) .."." ) | |||
local weapons = {}; | local weapons = {}; | ||
for i=0, 12 do | for i=0, 12 do | ||
Revision as of 16:11, 4 January 2019
Syntax
int getPreviousAndNextWeapon ( element thePlayer )
Required arguments
- thePlayer: The player who will pick up the weapons.
Code
Click to collapse [-]
Function sourcefunction getPreviousAndNextWeapon(player)
assert( isElement(player) and getElementType(player) == "player", "@getPreviousAndNextWeapon, expected player at argument '1', received ".. tostring(player) .."." )
local weapons = {};
for i=0, 12 do
weapons[i] = getPlayerWeapon(player, i);
end
local maxId = 0;
local minId = 12;
while weapons[maxId] == 0 do
maxId = maxId + 1;
end
while weapons[minId] == 0 do
minId = minId - 1;
end
return getPlayerWeapon(player) == 0 and weapons[minId] or weapons[getPlayerWeaponSlot(player) - 1] or 0, getPlayerWeapon(player) == 0 and weapons[maxId] or weapons[getPlayerWeaponSlot(player) + 1] or 0;
end