SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Thread Tools Display Modes
Old 11/02/2019, 10:25 PM   #1
Little Clucker
Join Date: Jul 2016
Location: Israel
Posts: 36
Reputation: 0
Default Array does not work properly " array index out of bounds "

I'm getting these errors:

array index out of bounds (variable "Report_Reason")
array index out of bounds (variable "Reporter_ID")

PHP Code:
// Reports
new countReport=0;


PHP Code:
IsPlayerLoggedIn(playerid)) return SendClientMessage(playeridCOLOR_GREY"You need to login first before using any command.");
sscanf(params"s[128]"params)) return SendClientMessage(playeridCOLOR_WHITE"[Usage]: /report [text]");
PlayerInfo[playerid][pRMute] > 0) return SendClientMessage(playeridCOLOR_GREY"You are muted from reporting.");
AntiAdv(playeridparams)) return 1;
strlen(params) > 128) return SendClientMessage(playeridCOLOR_GREY"Maximum characters limit is 128.");
ReportTime[playerid] > 0)
format(stringsizeof(string), "You need to wait %d more seconds before making a report message again."ReportTime[playerid]);
format(stringsizeof(string), "Report from {FF6347}[%d] {FFFF91}%s: %s"playeridRPN(playerid), params);
format(stringsizeof(string), "Report from [%d] %s: %s"playeridRPN(playerid), params);
SendClientMessage(playeridCOLOR_ORANGE"Your report have been sent to the online admins, Please be patient.");
ReportTime[playerid] = 25;
reported[playerid] = 1;

XpoZzA is offline   Reply With Quote
Old 11/02/2019, 11:23 PM   #2
Pottus's Avatar
Join Date: Jun 2012
Posts: 5,352
Reputation: 1272
Default Re: Array does not work properly " array index out of bounds "

Here is how I would set things up. Didn't test it but I think I got the basics down here take a look and learn. You are doing it all wrong man!

#include <a_samp>
#include <sscanf2>
// These kind of systems almost never change it's always like this when
// creating any dynamic system check here for another example it is older
// and there is a couple of things I would do differently today and also doesn't
// use y_iterate doesn't matter though it's the same concept either way

// Going to use foreach for looping
#include <YSI\y_iterate>
#include <YSI\y_commands>
#include <YSI\y_hooks>

// You can have as many repots as you want
#define             MAX_REPORTS                 1000

// Fine tune your length
#define             MAX_REPORT_REASON           128

// Make sure there is actually some kind of reason
#define             MIN_REASON_LENGTH           4

// Creation error reasons
#define             ERROR_REPORT_NOTCON         -1
#define             ERROR_REPORT_SHORT          -2
#define             ERROR_REPORT_NOFINDEX       -3

// Create our iterator
static Iterator:ReportIter<MAX_REPORTS>;

// Data structure of storing reports

// Create our variable to store data using the g_REPORTINFO enum data structure


// If a player goes off line remove their reports!
hook OnPlayerDisconnect(playerid, reason)
	// Loop through and check if this player had reports
	foreach(new i : ReportIter)
		// Player had a report but the report might still be good to check
		// Just set the report id to an invalid player
		if(g_ReportData[i][g_ReportID] == playerid)
			g_ReportData[i][g_ReportID] = INVALID_PLAYER_ID;
	return 1;

//--Create Delete Functions-----------------------------------------------------

// Create a report
CreateReport(playerid, reportid, reason[])
	// Set up variables
	new line[128], rname[MAX_PLAYER_NAME+1], name[MAX_PLAYER_NAME+1];
	// We want to make sure there is actually a reason
	if(strlen(reason) < MIN_REASON_LENGTH)
		GetPlayerName(playerid, name, MAX_PLAYER_NAME+1);
		printf("ERROR::CreateReport::Reason Too Short::ID: %i Name: %s", playerid, name);
	// Usually this would be checked before calling CreateReport still a good sanity check
		// Get a free index to use for the report
	    new index = Iter_Free(ReportIter);

		// Is there any free indexes?
		if(index > -1)
			// Add the index this to the iterator
		    Iter_Add(ReportIter, index);

			// Store all the data
            g_ReportData[index][g_ReportID] = playerid;
            g_ReportData[index][g_ReportedID] = reportid;
            g_ReportData[index][g_ReportTime] = gettime();
			format(g_ReportData[index][g_ReportReason], MAX_REPORT_REASON, "%s", reason);

			// Finally the report will always have to be annonced!
			GetPlayerName(playerid, rname, MAX_PLAYER_NAME+1);
			format(line, sizeof(line), "%s(%i) has reported %s{%i) for %s", rname, playerid, name, reportid);

			// Loop through players
			foreach(new i : Player)
				// Is player an admin? (Change this to meet your system's needs)
			 		SendClientMessage(i, 0xFF0000FF, line);

			// Always return the index of the report
	    	return index;
		// No indexes? This is a serious problem and shouldn't happen under
		// normal conditions show the error
		    // No free indexes return the error
			printf("ERROR::CreateReport::No Free Report Indexes");

	// Reported id is not connected show the error
	printf("ERROR::CreateReport::Reporter Not Connected");

// Remove a report
	// Is there an index with a report?
	if(Iter_Contains(ReportIter, index))
		Iter_Remove(ReportIter, index);
		return 1;

	// Failed the index does not exist!
	return 0;

//--Support Functions-----------------------------------------------------------
IsPlayersReport(playerid, index)
	// Does this index exist?
	if(Iter_Contains(ReportIter, index))
		// Yes this player did report this player!
		if(g_ReportData[index][g_ReportID] == playerid)
			return 1;
	return 0;

// There our Create() Remove/Destory() functions are created now we can use
// these to do useful stuff! This is the core support of the entire system
// If you write this part of your system well the rest is so damn easy all
// your support is there and everything falls into place like dominos!

CMD:report(playerid, params[])
	new reportid, reason[MAX_REPORT_REASON], index;

	// Get reported id and reason
	sscanf(params, "us[128]", reportid, reason);

	// Check if reported id is connected
		// Make sure the reason is a valid length yes we check in the function too
		// but you might call that function in another way skipping this check
		// when you plan of doing nothing if there is a failure (unlikely) but
		// we put that support in naturally.
	    if(strlen(reason) >= MIN_REASON_LENGTH)
	        // Can't report yourself
			if(playerid != reportid)
				// We have a valid report issue the report!
				index = CreateReport(playerid, reportid, reason);

				// You can update this to show more information
				// Lets reuse this variable since we're done with it
				// Just going to re-purpose it's use.
				format(reason, sizeof(reason), "Report Accepted! Type /cancelreport %i to cancel this report!", index);
				SendClientMessage(playerid, 0x00FF00FF, reason);
			// Player is stupid and reported himself!
			else SendClientMessage(playerid, 0xFF0000FF, "You can't report yourself idiot!");
		// No reason provided
		else SendClientMessage(playerid, 0xFF0000FF, "You must provide a reason!");
	// Reported player is not connected
	else SendClientMessage(playerid, 0xFF0000FF, "Player is connected!");

	// Return 1 on commands
	return 1;

// Simple function to cancel a report
CMD:cancelreport(playerid, params[])
	new index = strval(params);
	if(index >= 0 && index < MAX_REPORTS)
		// Make sure this is this players report!
		if(IsPlayersReport(playerid, index))
		    SendClientMessage(playerid, 0x00FF00FF, "Report Has Been Removed");
	// No reports to cancel
	else SendClientMessage(playerid, 0xFF0000FF, "There is no report to cancel!");
	return 1;
Pottus is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
error 006: must be assigned to an array Neooooo Scripting Help 0 06/07/2015 05:20 PM
error 006: must be assigned to an array giorgosdim12 Scripting Help 9 29/04/2015 12:46 PM
Array must be index, expected token ';' but found this '}' And must be assigned to array again. Deal-or-die Scripting Help 2 14/08/2012 08:33 PM
error 006: must be assigned to an array(To array set string) gamelaster Scripting Help 4 02/02/2012 05:25 AM
error 006: must be assigned to an array Coicatak Help Archive 12 22/02/2009 09:09 AM

All times are GMT. The time now is 10:28 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.