Hi all, im creating a firefighter job on my gamemode, and i saw code at this forum for holding a key fire, and i use it, but after i shut down 1-2 flames, timer crashes.
Crashdetect:
Script:
Crashdetect:
Code:
[17:13:26] [debug] Run time error 4: "Array index out of bounds"
[17:13:26] [debug] Accessing element at negative index -1
[17:13:26] [debug] AMX backtrace:
[17:13:26] [debug] #0 000db7fc in ?? (0) from disaronno.amx
[17:13:26] [debug] #1 000dafec in public VatrogasniCheck (0) from disaronno.amx
Code:
if(newkeys & KEY_FIRE && !HoldingKey[playerid])
{
VatrogasniCheck( playerid );
HoldingKey[playerid] = true;
}
forward VatrogasniCheck(playerid);
public VatrogasniCheck(playerid)
{
if(IsPlayerConnected(playerid))
{
new
keys, ud, lr;
GetPlayerKeys(playerid, keys, ud, lr);
if(keys & KEY_FIRE)
{
PozarGasenje( playerid );
SetTimerEx("VatrogasniCheck", 500, 0, "i", playerid);
return 0;
}
}
HoldingKey[playerid] = false;
return 0;
}
stock PozarGasenje( playerid )
{
if(GasiPozar [ playerid ] != -1 )
{
if(GetPlayerState( playerid ) == PLAYER_STATE_ONFOOT)
{
if(NajblizaVatra(playerid) != -1 && GetPlayerWeapon(playerid) == 42)
{
if(IsPlayerAimingAt(playerid, FireCoord[ GasiPozar [ playerid ] ][ NajblizaVatra(playerid) ][ 0 ], FireCoord[ GasiPozar [ playerid ] ][ NajblizaVatra(playerid) ][ 1 ], FireCoord[ GasiPozar [ playerid ] ][ NajblizaVatra(playerid) ][ 2 ], 6.0))
{
if(FireData[ GasiPozar [ playerid ] ][ VatraHealth ][ NajblizaVatra(playerid) ] > 3)
{
FireData[ GasiPozar [ playerid ] ][ VatraHealth ][ NajblizaVatra(playerid) ] -= 3+random(3);
UpdatePlamenLabel( GasiPozar[ playerid ], NajblizaVatra(playerid) );
}
else
{
if(FireData[ GasiPozar [ playerid ] ][ VatraGori ][ NajblizaVatra(playerid) ] != 0)
{
Delete3DTextLabel( FireData[ GasiPozar [ playerid ] ][ VatraLabel ][ NajblizaVatra(playerid) ] );
if( IsValidObject( FireData[ GasiPozar [ playerid ] ][ VatraObjekat ][ NajblizaVatra(playerid) ] )) DestroyObject(FireData[ GasiPozar [ playerid ] ][ VatraObjekat ][ NajblizaVatra(playerid) ]);
FireData[ GasiPozar [ playerid ] ][ VatraGori ][ NajblizaVatra(playerid) ] = 0;
new platica = 50+random(50);
Msg3( playerid, "(Posao) Ugasili ste plamen, dobili ste "WHT"%d$ "B3"na platu.", platica);
PlayerInfo[ playerid ][ Plata ] += platica;
if(jobdeal == PlayerInfo[ playerid ][ pPosao ])
{
Msg3(playerid, "(Posao) Dobili ste dodatnih "WHT"%d$"B3" na platu jer je na vasem poslu Job Deal.", platica);
PlayerInfo[ playerid ][ Plata ] += platica;
}
DPC(playerid);
CheckEnd( playerid );
}
}
}
}
}
else if(GetPlayerState( playerid ) == PLAYER_STATE_DRIVER)
{
if(GetVehicleModel( GetPlayerVehicleID( playerid ) ) == 407)
{
if(IsPlayerAimingAt(playerid, FireCoord[ GasiPozar [ playerid ] ][ NajblizaKamVatra( playerid ) ][ 0 ], FireCoord[ GasiPozar [ playerid ] ][ NajblizaKamVatra( playerid ) ][ 1 ], FireCoord[ GasiPozar [ playerid ] ][ NajblizaKamVatra( playerid ) ][ 2 ]+1, 10.0)
&& NajblizaKamVatra( playerid ) != -1)
{
if(FireData[ GasiPozar [ playerid ] ][ VatraHealth ][ NajblizaKamVatra( playerid ) ] > 3)
{
FireData[ GasiPozar [ playerid ] ][ VatraHealth ][ NajblizaKamVatra( playerid ) ] -= 3+random(3);
UpdatePlamenLabel( GasiPozar[ playerid ], NajblizaKamVatra( playerid ) );
}
else
{
if(FireData[ GasiPozar [ playerid ] ][ VatraGori ][ NajblizaKamVatra( playerid ) ] != 0)
{
Delete3DTextLabel( FireData[ GasiPozar [ playerid ] ][ VatraLabel ][ NajblizaKamVatra( playerid ) ] );
if( IsValidObject( FireData[ GasiPozar [ playerid ] ][ VatraObjekat ][ NajblizaKamVatra( playerid ) ] )) DestroyObject(FireData[ GasiPozar [ playerid ] ][ VatraObjekat ][ NajblizaKamVatra( playerid ) ]);
FireData[ GasiPozar [ playerid ] ][ VatraGori ][ NajblizaKamVatra( playerid ) ] = 0;
new platica = 50+random(50);
Msg3( playerid, "(Posao) Ugasili ste plamen, dobili ste "WHT"%d$ "B3"na platu.", platica);
PlayerInfo[ playerid ][ Plata ] += platica;
if(jobdeal == PlayerInfo[ playerid ][ pPosao ])
{
Msg3(playerid, "(Posao) Dobili ste dodatnih "WHT"%d$"B3" na platu jer je na vasem poslu Job Deal.", platica);
PlayerInfo[ playerid ][ Plata ] += platica;
}
DPC(playerid);
CheckEnd( playerid );
}
}
}
}
}
}
}