Assistance with my system
#1

So I'm still working on my dynamic faction system, it all functions properly. The one thing that bugs me out is if the player's factionid in his data is 0, it displays he's in the first faction listed. I figured out on how that works because the enum count starts from 0 and goes to 19 when my limit is 20, using this for example:
Код:
if(pData[playerid][pFactionRank] >= fData[pData[playerid][pFaction]][fManageRank])
I honestly have no clue on how I could possibly get to doing this. I have tried to set the player's faction to -1 as a default, that just ends up in index array bounds something error.

What could I be doing to start the count from 1 to 20 instead of 0 to 19? If someone understands me?
Reply
#2

How are you setting the player's faction to -1?
If it's like this:
Код:
enum ENUM_NAME
{
    pFaction = -1
};
Then it's incorrect. Do it when the player connects.

If not:

Check if it's == to -1 before using fData[pData[playerid][pFaction][fManageRank], or else it'll be fData[-1][fManageRank], and that's invalid.
Reply
#3

Quote:
Originally Posted by Stinged
Посмотреть сообщение
How are you setting the player's faction to -1?
If it's like this:
Код:
enum ENUM_NAME
{
    pFaction = -1
};
Then it's incorrect. Do it when the player connects.

If not:

Check if it's == to -1 before using fData[pData[playerid][pFaction][fManageRank], or else it'll be fData[-1][fManageRank], and that's invalid.
Код:
CMD:settest(playerid, params[])
{
	new type, count;
	if(sscanf(params, "ii", type, count)) return SendUsageMessage(playerid, "/settest [type] [number] (1:faction,2:factionrank,3:facmanagerank)");
	if(type > 3 || type < 1) return SendErrorMessage(playerid, "type cant be more than 3 or less than 1");
	switch(type)
	{
		case 1: pData[playerid][pFaction] = count;
		case 2: pData[playerid][pFactionRank] = count;
		case 3: fData[pData[playerid][pFaction]][fManageRank] = count;
	}
	return 1;
}
I use this to set out my factionid temporary since it's just me who's on the server.

Код:
CMD:factions(playerid, params[])
{
	new str[200];
	format(str, sizeof(str), "List Factions\n");
	if(pData[playerid][pFaction] >= 0)
	{
	    format(str, sizeof(str), "%sList %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
	    if(pData[playerid][pFactionRank] >= fData[pData[playerid][pFaction]][fManageRank])
	    {
	    	format(str, sizeof(str), "%sManage %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
	    }
	}
	if(pData[playerid][pAdmin] > 1)
	{
	    format(str, sizeof(str), "%sCreate Faction\nEdit Faction", str, fData[pData[playerid][pFaction]][fName]);
	}
	ShowPlayerDialog(playerid, DIALOG_FACTION_MAIN, DIALOG_STYLE_LIST, "Faction Control Panel", str, "Select", "Cancel");
	return 1;
}
Код:
[08:24:32] [debug] Run time error 4: "Array index out of bounds"
[08:24:32] [debug]  Accessing element at negative index -1
[08:24:32] [debug] AMX backtrace:
[08:24:32] [debug] #0 0006b310 in public cmd_factions (playerid=0, params[]=@02133ff0 "") at <myscript>.pwn:2682
[08:24:32] [debug] #1 native CallLocalFunction () from samp-server.exe
[08:24:32] [debug] #2 0000b9dc in public f3_KBROnPlayerCommandText (playerid=0, cmdtext[]=@02133fc8 "/factions") at C:\Users\Administrator\Desktop\Script from scratch new\pawno\include\izcmd.inc:94
Reply
#4

Edit: Wrong section
Reply
#5

No need to do that, kanerandyfirst.

Код:
if(pData[playerid][pAdmin] > 1)
{
    format(str, sizeof(str), "%sCreate Faction\nEdit Faction", str, fData[pData[playerid][pFaction]][fName]);
}
That's the problem. This is outside of the pFaction >= 0 check.
Which means, it'll be fData[-1][pFaction].
Reply
#6

Check if the player's is admin inside the if statement about faction >= 0

pawn Код:
if (pData[playerid][pFaction] >= 0)
{
    format(str, sizeof(str), "%sList %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
    if (pData[playerid][pFactionRank] >= fData[pData[playerid][pFaction]][fManageRank])
    {
        format(str, sizeof(str), "%sManage %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
    }

    if (pData[playerid][pAdmin] > 1)
    {
        format(str, sizeof(str), "%sCreate Faction\nEdit Faction", str, fData[pData[playerid][pFaction]][fName]);
    }
}
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Check if the player's is admin inside the if statement about faction >= 0

pawn Код:
if (pData[playerid][pFaction] >= 0)
{
    format(str, sizeof(str), "%sList %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
    if (pData[playerid][pFactionRank] >= fData[pData[playerid][pFaction]][fManageRank])
    {
        format(str, sizeof(str), "%sManage %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
    }

    if (pData[playerid][pAdmin] > 1)
    {
        format(str, sizeof(str), "%sCreate Faction\nEdit Faction", str, fData[pData[playerid][pFaction]][fName]);
    }
}
That isn't quite needed because an admin should be able to create a faction, even if he isn't in one.
Everything within the dialog functions well, the only thing that fucks me up is the enum, let me show you.

Up top, I have this

Код:
#define MAX_FACTIONS 		(20)
Код:
new fData[MAX_FACTIONS][factions];
Код:
forward OnFactionLoad(); public OnFactionLoad()
{
	new rows, fields, count = 0;
	cache_get_data(rows, fields, mysql);
	if(rows)
	{
		while(count < rows)
		{
			fData[count][fID] = cache_get_field_content_int(count, "fID");
			cache_get_field_content(count, "fName", fData[count][fName], mysql, 30);
			and so on, all data gets loaded
			count++;
		}
		printf("%i factions loaded.", count);
	}
	else printf("No factions found.");
	factioncount = count;
}
What my problem is, it loads all data in the enum and starts at 0, so lets say the 1st row = fData[0][fID]
What my check does is
Код:
fData[pData[playerid][pFaction][fID]
which is basically the same as
Код:
fData[0][fID]
which results in
Код:
1
which is the first row here

And my thing is that if a player isn't in a faction, the pFaction of that playerid is 0
How would I go and re-write/fix this?
Reply
#8

I don't get what you're trying to do with that command.
You're listing all the factions, yet you're not even looping through them?
Reply
#9

Quote:
Originally Posted by Stinged
Посмотреть сообщение
I don't get what you're trying to do with that command.
You're listing all the factions, yet you're not even looping through them?
I am not listing through all factions with that command. Re-read the code.

This isn't even about the command, read my previous post for my trouble.
Reply
#10

Oh sorry I just re-read it carefully. I mixed up a bit because of the "List Faction", didn't think of it as an option, but instead a title (Stupid thing to do)

Код:
CMD:factions(playerid, params[])
{
	new str[200];
	format(str, sizeof(str), "List Factions\n");
	if(pData[playerid][pFaction] >= 0)
	{
	    format(str, sizeof(str), "%sList %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
	    if(pData[playerid][pFactionRank] >= fData[pData[playerid][pFaction]][fManageRank])
	    {
	    	format(str, sizeof(str), "%sManage %s's Members\n", str, fData[pData[playerid][pFaction]][fName]);
	    }
	}
	if(pData[playerid][pAdmin] > 1)
	{
	    format(str, sizeof(str), "%sCreate Faction\nEdit Faction", str);
	}
	ShowPlayerDialog(playerid, DIALOG_FACTION_MAIN, DIALOG_STYLE_LIST, "Faction Control Panel", str, "Select", "Cancel");
	return 1;
}
Adding the option to create or edit factions doesn't need the player's faction name (Which can be id -1)
You're only using 1 %s, and that's for the List Faction (If the player doesn't have a faction)
So I just removed the fData part that.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)