From 2d661b5a30f35946bf05e1d6818c101121ade973 Mon Sep 17 00:00:00 2001 From: jenz Date: Fri, 23 Feb 2024 20:01:24 +0100 Subject: [PATCH] fixing some indexes out of bounds --- ZombieRiot/scripting/Medic.sp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/ZombieRiot/scripting/Medic.sp b/ZombieRiot/scripting/Medic.sp index 3694f7fa..0dc3641b 100644 --- a/ZombieRiot/scripting/Medic.sp +++ b/ZombieRiot/scripting/Medic.sp @@ -18,7 +18,7 @@ new Handle:gShowInChat = INVALID_HANDLE; new Handle:gMaxTimeUse = INVALID_HANDLE; new gPlayerMoney; -new gUsedMedic[ 33 ]; +new gUsedMedic[ MAXPLAYERS + 1 ]; public Plugin:myinfo = @@ -66,12 +66,17 @@ public OnMapStart() } public Action:Event_PlayerSpawn( Handle:event, const String:name[], bool:dontBroadcast ) { - if( GetConVarInt( gPluginEnabled ) == 1 ) - { - new id = GetClientOfUserId( GetEventInt( event, "userid" ) ); + if( GetConVarInt( gPluginEnabled ) == 1 ) + { + new id = GetClientOfUserId( GetEventInt( event, "userid" ) ); + if (!IsValidClient(id)) + { + return Plugin_Handled; + } - gUsedMedic[ id ] = 0; - } + gUsedMedic[ id ] = 0; + } + return Plugin_Handled; } public Action:Command_Medic( id, args ) { @@ -169,3 +174,13 @@ stock AttachClientIcon( index ) TE_WriteNum( "m_iAttachToClient", index ); TE_SendToAll(); } + + +stock bool IsValidClient(int client) +{ + if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client)) + { + return true; + } + return false; +}