20.04.2015, 08:44
Hello, im using the following code in my server for anti 2-shot.
Using the "OnPlayerUpdate" func.
There is a problem in this code, it give the false warning for anti 2-shot whenever the player switches the sawns not to 2-shot but to use the other weap..
Like if someone shoots 3 bullets from sawns and then scrolls to other weap (it will give warning)
I want to make it like, when someone switches the sawns and then scroll back to sawns then it should give the warning, not when some one switches to other weapon.
Any help?
Using the "OnPlayerUpdate" func.
PHP код:
public OnPlayerUpdate(playerid)
{
// anti 2 shot
static
s_iState,
s_iSpecialAction
;
s_iState = GetPlayerState( playerid );
s_iSpecialAction = GetPlayerSpecialAction( playerid );
if ( s_iState == PLAYER_STATE_ONFOOT && ( s_iSpecialAction == SPECIAL_ACTION_NONE || s_iSpecialAction == SPECIAL_ACTION_DUCK ) )
{
static
s_iWeapon,
s_iAmmo
;
s_iWeapon = GetPlayerWeapon( playerid );
s_iAmmo = GetPlayerAmmo( playerid );
if ( g_cPreviousWeapon{ playerid } != s_iWeapon )
{
if ( g_cPreviousWeapon{ playerid } == WEAPON_SAWEDOFF )
{
if ( Bit_Get( g_abIsSawnoffClipUsed, playerid ) )
{
static
s_iWeaponState
;
s_iWeaponState = GetPlayerWeaponState( playerid );
if ( ( s_iWeaponState == WEAPONSTATE_MORE_BULLETS || s_iWeaponState == WEAPONSTATE_LAST_BULLET ) && g_cFiredShots{ playerid } != 4 )
{
Bit_Let( g_abThisBitchDidntReload, playerid );
g_iReloadEvadeTime[ playerid ] = GetTickCount( );
}
}
g_cFiredShots{ playerid } = 0;
}
else if ( s_iWeapon == WEAPON_SAWEDOFF )
{
if ( Bit_Get( g_abThisBitchDidntReload, playerid ) )
{
if ( GetTickCount( ) - g_iReloadEvadeTime[ playerid ] < PUNISH_THRESOLD )
{
new
Float:fVX,
Float:fVY,
Float:fVZ
;
GetPlayerVelocity( playerid, fVX, fVY, fVZ );
if ( floatabs( fVZ ) < 0.15 )
{
new string[256];
if(sWarns[playerid] == 0)
{
sWarns[playerid]++;
GameTextForPlayer(playerid, "~r~2 shots Detected!", 3500, 3);
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 80;
}
else
if(sWarns[playerid] == 1)
{
if(PlayerInfo[playerid][pWarnTime] < 1)
{
sWarns[playerid]++;
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 140;
}
}
else
if(sWarns[playerid] == 2)
{
if(PlayerInfo[playerid][pWarnTime] < 1)
{
sWarns[playerid]++;
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 240;
}
}
else
if(sWarns[playerid] == 3)
{
if(PlayerInfo[playerid][pWarnTime] < 1)
{
sWarns[playerid]++;
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 520;
}
}
else
if(sWarns[playerid] == 4)
{
if(PlayerInfo[playerid][pWarnTime] < 1)
{
format(string, sizeof(string), "(SERVER COMPLAINT) %s (%d) May Be Possibly Using 2 Shots.", PlayerInfo[playerid][pName],playerid);
SendClientMessageToAdmins(COLOR_ADMIN, string);
PlayerInfo[playerid][pWarnTime] = 720;
}
}
}
}
Bit_Vet( g_abThisBitchDidntReload, playerid );
}
}
g_cPreviousWeapon{ playerid } = s_iWeapon;
}
if ( s_iWeapon == WEAPON_SAWEDOFF )
{
if ( g_iSawnoffAmmo[ playerid ] == -1 )
g_iSawnoffAmmo[ playerid ] = GetPlayerAmmo( playerid );
else
{
if ( GetPlayerWeaponState( playerid ) == WEAPONSTATE_RELOADING )
{
if ( Bit_Get( g_abIsSawnoffClipUsed, playerid ) )
Bit_Vet( g_abIsSawnoffClipUsed, playerid );
}
else
{
if ( g_iSawnoffAmmo[ playerid ] != s_iAmmo )
{
if ( s_iAmmo < g_iSawnoffAmmo[ playerid ] )
{
Bit_Let( g_abIsSawnoffClipUsed, playerid );
g_cFiredShots{ playerid } += g_iSawnoffAmmo[ playerid ] - s_iAmmo;
}
else
{
g_cFiredShots{ playerid } = 0;
Bit_Vet( g_abIsSawnoffClipUsed, playerid );
}
g_iSawnoffAmmo[ playerid ] = s_iAmmo;
}
}
}
}
else if ( g_iSawnoffAmmo[ playerid ] != -1 || Bit_Get( g_abIsSawnoffClipUsed, playerid ) )
{
g_iSawnoffAmmo[ playerid ] = -1;
Bit_Vet( g_abIsSawnoffClipUsed, playerid );
g_cFiredShots{ playerid } = 0;
}
}
else if ( g_iSawnoffAmmo[ playerid ] != -1 || Bit_Get( g_abIsSawnoffClipUsed, playerid ) )
{
g_iSawnoffAmmo[ playerid ] = -1;
Bit_Vet( g_abIsSawnoffClipUsed, playerid );
g_cFiredShots{ playerid } = 0;
}
return 1;
}
There is a problem in this code, it give the false warning for anti 2-shot whenever the player switches the sawns not to 2-shot but to use the other weap..
Like if someone shoots 3 bullets from sawns and then scrolls to other weap (it will give warning)
I want to make it like, when someone switches the sawns and then scroll back to sawns then it should give the warning, not when some one switches to other weapon.
Any help?