GetPlayerPreviousAndNextWeapon: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 8: Line 8:
** [[Player|Players]]
** [[Player|Players]]


==Returns==
==Code==
This function returns two numbers the first the previous weapon of the element and the second the next weapon of the element.
<section name="Function source" class="both" show="true">
<syntaxhighlight lang="lua">
function getPreviousAndNextWeapon(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
</syntaxhighlight>
</section>

Revision as of 16:08, 4 January 2019

Syntax

int getPreviousAndNextWeapon ( element theElement )

Required arguments

Code

Click to collapse [-]
Function source
function getPreviousAndNextWeapon(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