2024-03-16, 09:17 AM
To fix the "array index out of bounds" error, you need to ensure that the playerid you're using to access PlayerInfo is within the bounds of the array
PHP Code:
function UpdatePaddy(playerid)
{
if(playerid < 0 || playerid >= MAX_PLAYERS) // Check if playerid is within bounds
{
printf("Error: Invalid player ID %d", playerid);
return 0;
}
for(new i = 0; i < MAX_PADDYS; i++)
{
if(PlayerInfo[playerid][pPaddyUsed][i] == 1)
{
if(PlayerInfo[playerid][pPaddyProgress][i] < 100)
{
PlayerInfo[playerid][pPaddyProgress][i] += 1;
if(PlayerInfo[playerid][pPaddyProgress][i] == 100)
{
// Update paddy appearance
new Float:x, Float:y, Float:z;
GetDynamicObjectPos(PlayerInfo[playerid][pPaddyObject][i], x, y, z);
SetDynamicObjectMaterial(PlayerInfo[playerid][pPaddyObject][i], 2, 862, "gta_procdesert", "sm_Agave_bloom");
DestroyDynamic3DTextLabel(PlayerInfo[playerid][pPaddyText][i]);
PlayerInfo[playerid][pPaddyText][i] = CreateDynamic3DTextLabel("", -1, x, y, z + 2, 5.0);
}
// Update dynamic text label
new string[128];
format(string, sizeof(string), "Ültetvény\n %d%", PlayerInfo[playerid][pPaddyProgress][i]);
UpdateDynamic3DTextLabelText(PlayerInfo[playerid][pPaddyText][i], -1, string);
}
}
}
return 1;
}