11.12.2010, 01:51
Change weapon as passenger:
Used PVars because the function GetPlayerWeapon or SetPlayerArmedWeapon don'ts works more than one time , when the player is a passenger, in the version 0.3c RC4-2.
pawn Код:
#include <a_samp>
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
new bool: FirstTime[MAX_PLAYERS];
public OnPlayerDisconnect(playerid, reason)
{
FirstTime[playerid] = false;
return true;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(128) && GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
{
if(FirstTime[playerid])
{
SetPVarInt(playerid, "weaponActual", GetPlayerWeapon(playerid));
FirstTime[playerid] = false;
}
NextSlot(playerid, GetPVarInt(playerid, "weaponActual"));
}
return 1;
}
NextSlot(playerid, weaponinuse)
{
static weapons[13][2], i, j;
for (i = 2; i < 13; ++i)
{
GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
if(weapons[i][0] == weaponinuse) j=i;
}
while(j < 7)
{
j++;
if(weapons[j][0])
{
SetPlayerArmedWeapon(playerid, weapons[j][0]);
SetPVarInt(playerid, "weaponActual", weapons[j][0]);
return true;
}
}
SetPlayerArmedWeapon(playerid, weapons[2][0]);
SetPVarInt(playerid, "weaponActual", weapons[2][0]);
return true;
}