Damn, what's wrong now? Array index...
#1

Me again.

I'm trying to make that a script loads variables (for enum) for each faction from a file. When I paste the script on GameModeInit I get this:

Код:
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(15) : warning 201: redefinition of constant/macro (symbol "MAX_PLAYERS")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(178) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(179) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(180) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(181) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(182) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(183) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(184) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(185) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(186) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(187) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(188) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(189) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(190) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(191) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(192) : error 032: array index out of bounds (variable "Faction1")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(195) : error 032: array index out of bounds (variable "Faction2")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(196) : error 032: array index out of bounds (variable "Faction2")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(197) : error 032: array index out of bounds (variable "Faction2")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(198) : error 032: array index out of bounds (variable "Faction2")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(199) : error 032: array index out of bounds (variable "Faction2")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(200) : error 032: array index out of bounds (variable "Faction2")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(201) : error 032: array index out of bounds (variable "Faction2")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(202) : error 032: array index out of bounds (variable "Faction2")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(203) : error 032: array index out of bounds (variable "Faction2")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(204) : error 032: array index out of bounds (variable "Faction2")
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(205) : error 032: array index out of bounds (variable "Faction2")

This is the code I'm using:

Код:
	// Load faction variables
	
	Faction1[fFaction1][fLeader] = dini_Set(SERVER_FACTION_FILE_1, "Leader");
 	Faction1[fFaction1][fFactionName] = dini_Set(SERVER_FACTION_FILE_1, "FactionName");
  	Faction1[fFaction1][fRank1] = dini_Int(SERVER_FACTION_FILE_1, "Rank1");
   	Faction1[fFaction1][fRank2] = dini_Int(SERVER_FACTION_FILE_1, "Rank2");
    Faction1[fFaction1][fRank3] = dini_Int(SERVER_FACTION_FILE_1, "Rank3");
    Faction1[fFaction1][fRank4] = dini_Int(SERVER_FACTION_FILE_1, "Rank4");
    Faction1[fFaction1][fRank5] = dini_Int(SERVER_FACTION_FILE_1, "Rank5");
    Faction1[fFaction1][fRank6] = dini_Int(SERVER_FACTION_FILE_1, "Rank6");
    Faction1[fFaction1][fRank7] = dini_Int(SERVER_FACTION_FILE_1, "Rank7");
    Faction1[fFaction1][fSkin1] = dini_Int(SERVER_FACTION_FILE_1, "Skin1");
    Faction1[fFaction1][fSkin2] = dini_Int(SERVER_FACTION_FILE_1, "Skin2");
    Faction1[fFaction1][fSkin3] = dini_Int(SERVER_FACTION_FILE_1, "Skin3");
    Faction1[fFaction1][fSkin4] = dini_Int(SERVER_FACTION_FILE_1, "Skin4");
    Faction1[fFaction1][fSkin5] = dini_Int(SERVER_FACTION_FILE_1, "Skin5");
    Faction1[fFaction1][fSkin6] = dini_Int(SERVER_FACTION_FILE_1, "Skin6");


	Faction2[fFaction2][fLeader] = dini_Int(SERVER_FACTION_FILE_2, "Leader");
 	Faction2[fFaction2][fFactionName] = dini_Int(SERVER_FACTION_FILE_2, "FactionName");
  	Faction2[fFaction2][fRank1] = dini_Int(SERVER_FACTION_FILE_2, "Rank1");
   	Faction2[fFaction2][fRank2] = dini_Int(SERVER_FACTION_FILE_2, "Rank2");
    Faction2[fFaction2][fRank3] = dini_Int(SERVER_FACTION_FILE_2, "Rank3");
    Faction2[fFaction2][fRank4] = dini_Int(SERVER_FACTION_FILE_2, "Rank4");
    Faction2[fFaction2][fRank5] = dini_Int(SERVER_FACTION_FILE_2, "Rank5");
    Faction2[fFaction2][fRank6] = dini_Int(SERVER_FACTION_FILE_2, "Rank6");
    Faction2[fFaction2][fRank7] = dini_Int(SERVER_FACTION_FILE_2, "Rank7");
    Faction2[fFaction2][fSkin1] = dini_Int(SERVER_FACTION_FILE_2, "Skin1");
    Faction2[fFaction2][fSkin2] = dini_Int(SERVER_FACTION_FILE_2, "Skin2");
    Faction2[fFaction2][fSkin3] = dini_Int(SERVER_FACTION_FILE_2, "Skin3");
    Faction2[fFaction2][fSkin4] = dini_Int(SERVER_FACTION_FILE_2, "Skin4");
    Faction2[fFaction2][fSkin5] = dini_Int(SERVER_FACTION_FILE_2, "Skin5");
    Faction2[fFaction2][fSkin6] = dini_Int(fiSERVER_FACTION_FILE_2, "Skin6");
This is enum:

Код:
enum fFaction2
{
	fLeader[MAX_PLAYER_NAME],
	fFactionName[50],
    fRank1,
    fRank2,
    fRank3,
    fRank4,
    fRank5,
    fRank6,
    fRank7,
    fSkin1,
    fSkin2,
    fSkin3,
    fSkin4,
    fSkin5,
    fSkin6,
}


// VARIABLES
new PlayerInfo[MAX_PLAYERS][pInfo];
new gPlayerLogged[MAX_PLAYERS];
new pPaycheck;
new paytimer;
new checkpaytimer;
new bool:pMuted[MAX_PLAYERS] = false;
Please help me with this, this is important for my GM.
Reply
#2

take a look at this.. I think your problem lies with the defenition of your 2 variables Faction1 and Faction2.... both wich you are not showing...
Reply
#3

Thanks for that link. I found what the problem was. When I placed "new Faction1[Faction1]" I didn't set the array size.


This is how it looks now, gonna test it IG now.
// FACTION VARIABLES:
new Faction1[100][fFaction1];
new Faction2[100][fFaction2];

Also, how to get rid of a following warning?
Код:
C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(15) : warning 201: redefinition of constant/macro (symbol "MAX_PLAYERS")
I set it to be 200
Reply
#4

it is not as bad as it looks but it is (pre)defined in the sa-mp.inc ... you can remove it from your script and edit it there if you'd like, remember it is changed there tho... if you need it again
Reply
#5

#undef MAX_PLAYERS
#define MAX_PLAYERS 200
Reply
#6

Thanks John.

Still, I'm having problems with reading text from .ini file.

If I put dini_Get(SERVER_FACTION_FILE_1, "FactionName")
I get an error saying:

[code]C:\Users\Kreso\Desktop\SAMP Server\gamemodes\GGRP.pwn(179) : error 047: array sizes do not match, or destination array is too small[code]

Also, when I add in faction1 enum array size to a string (like: fRank1[30]) I get 20+ errors. All I want to do is to get the text written in .ini file in those variables.

Here is a part of code:

pawn Код:
// http://gb-rp.one-forum.net/
// INCL
#include <a_samp>
#include <dini>
#include <dudb>
#include <zcmd>
#include <sscanf2>
#pragma unused ret_memcpy

// SCRIPT DEFINES
#undef MAX_PLAYERS
#define MAX_PLAYERS 200
#define SERVER_USER_FILE "users/%s.ini"
#define PLAYER_NAME MAX_PLAYER_NAME
#define SERVER_FACTION_FILE_1 "factions/1.ini"
#define SERVER_FACTION_FILE_2 "factions/2.ini"

// COLORS
#define COLOR_POWDERBLUE 0xB0E0E6FF
#define COLOR_BLUE 0x0000BBAA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_GOLD 0xFFD700FF
#define COLOR_OLIVE 0x808000FF
#define COLOR_ORED 0xFF0000FF
#define COLOR_SALMON 0xFA8072FF
#define COLOR_MAGENTA 0xFF00FFFF
#define COLOR_TEAL 0x008080FF
#define COLOR_BROWN 0xFFBB7796
#define COLOR_LOCALMSG 0xEC5413AA
#define COLOR_ADMINCMD 0xF97804FF
#define COLOR_ADMINDUTY 0x007E96F6
#define COLOR_NOTLOGGED 0x00000000
#define COLOR_GRAD1 0xB4B5B7FF
#define COLOR_GRAD2 0xBFC0C2FF
#define COLOR_MONEYBAR 0x005800FF
#define COLOR_GRAD3 0xCBCCCEFF
#define COLOR_GRAD4 0xD8D8D8FF
#define COLOR_GRAD5 0xE3E3E3FF
#define COLOR_GRAD6 0xF0F0F0FF
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xA10000AA
#define COLOR_DARKRED 0xCD000000
#define COLOR_ANTICHEAT 0xAA3333AA
#define COLOR_LIGHTRED 0xFF6347AA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_LIGHTGREEN 0x9ACD32AA
#define COLOR_LIGHTRED 0xFF6347AA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_LIGHTBLUE2 0x0080FFAA
#define COLOR_LIGHTGREEN 0x9ACD32AA
#define COLOR_LIGHTORANGE 0xFF8000FF
#define COLOR_DARKBROWN 0xB36C42FF
#define COLOR_MEDIUMBLUE 0x1ED5C7FF
#define COLOR_LIGHTYELLOW 0xE0E377AA
#define COLOR_LIGHTYELLOW2 0xE0EA64AA
#define COLOR_LIGHTYELLOW3 0xFF6347AA
#define COLOR_DARKPURPLE 0x5F56F8AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_YELLOW2 0xF5DEB3AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_FADE1 0xE6E6E6E6
#define COLOR_FADE2 0xC8C8C8C8
#define COLOR_FADE3 0xAAAAAAAA
#define COLOR_FADE4 0x8C8C8C8C
#define COLOR_FADE5 0x6E6E6E6E
#define COLOR_PURPLE 0xC2A2DAAA
#define COLOR_DBLUE 0x2641FEAA
#define COLOR_ALLDEPT 0xFF8282AA
#define COLOR_NEWS 0xFFA500AA
#define COLOR_OOC 0xE0FFFFAA
#define COLOR_NEWOOC 0x0080FFAA
// END COLORS

// FACTIONS (TEAMS)

// FORWARDS
forward NearByMessage(playerid, colour, string[]);
forward NearByMessageLow(playerid, colour, string[]);
forward NearByMessageShout(playerid, colour, string[]);
forward paycheck();
forward checkpaytime();
forward savestats(playerid);
forward updatestats(playerid);

// PLAYER INFORMATION IS STORED TEMPORERALY HERE
enum pInfo
{
    pAdminLevel,
    pCash,
    pScore,
    pPaycheckStatus,
    pRespect,
    pNextLvl,
    pLeader,
    pFaction,
    pFRank,
}

// FACTION INFORMATION ARE LOADED HERE FROM FILE (TEMP)
// Faction 1 = SFPD
// Faction 2 = Goverment
enum fFaction1
{
    fLeader[MAX_PLAYER_NAME],
    fFactionName[40],
    fRank1,
    fRank2,
    fRank3,
    fRank4,
    fRank5,
    fRank6,
    fRank7,
    fSkin1,
    fSkin2,
    fSkin3,
    fSkin4,
    fSkin5,
    fSkin6,
}


// THE GOVERNMENT
enum fFaction2
{
    fLeader[MAX_PLAYER_NAME],
    fFactionName[40],
    fRank1,
    fRank2,
    fRank3,
    fRank4,
    fRank5,
    fRank6,
    fRank7,
    fSkin1,
    fSkin2,
    fSkin3,
    fSkin4,
    fSkin5,
    fSkin6,
}


// VARIABLES
new PlayerInfo[MAX_PLAYERS][pInfo];
new gPlayerLogged[MAX_PLAYERS];
new pPaycheck;
new paytimer;
new checkpaytimer;
new bool:pMuted[MAX_PLAYERS] = false;



// FACTION VARIABLES:
new Faction1[100][fFaction1];
new Faction2[100][fFaction2];

main()
{
    print("\n--------------------------------------");
    print(" my server ");
    print(" made by: Outcast. ");
    print("--------------------------------------/n");
}


public OnGameModeInit()
{
    SetGameModeText("Gant Bridge Roleplay v.0.1");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    paytimer = SetTimer("paycheck",3600000,true);
    checkpaytimer = SetTimer("checkpaytime",1800000,true);
   
    // Load faction variables
   
    Faction1[fFaction1][fLeader] = dini_Get(SERVER_FACTION_FILE_1, "Leader");
    Faction1[fFaction1][fFactionName] = dini_Int(SERVER_FACTION_FILE_1, "FactionName");
    Faction1[fFaction1][fRank1] = dini_Int(SERVER_FACTION_FILE_1, "Rank1");
    Faction1[fFaction1][fRank2] = dini_Int(SERVER_FACTION_FILE_1, "Rank2");
    Faction1[fFaction1][fRank3] = dini_Int(SERVER_FACTION_FILE_1, "Rank3");
    Faction1[fFaction1][fRank4] = dini_Int(SERVER_FACTION_FILE_1, "Rank4");
    Faction1[fFaction1][fRank5] = dini_Int(SERVER_FACTION_FILE_1, "Rank5");
    Faction1[fFaction1][fRank6] = dini_Int(SERVER_FACTION_FILE_1, "Rank6");
    Faction1[fFaction1][fRank7] = dini_Int(SERVER_FACTION_FILE_1, "Rank7");
    Faction1[fFaction1][fSkin1] = dini_Int(SERVER_FACTION_FILE_1, "Skin1");
    Faction1[fFaction1][fSkin2] = dini_Int(SERVER_FACTION_FILE_1, "Skin2");
    Faction1[fFaction1][fSkin3] = dini_Int(SERVER_FACTION_FILE_1, "Skin3");
    Faction1[fFaction1][fSkin4] = dini_Int(SERVER_FACTION_FILE_1, "Skin4");
    Faction1[fFaction1][fSkin5] = dini_Int(SERVER_FACTION_FILE_1, "Skin5");
    Faction1[fFaction1][fSkin6] = dini_Int(SERVER_FACTION_FILE_1, "Skin6");


    Faction2[fFaction2][fLeader] = dini_Int(SERVER_FACTION_FILE_2, "Leader");
    Faction2[fFaction2][fFactionName] = dini_Int(SERVER_FACTION_FILE_2, "FactionName");
    Faction2[fFaction2][fRank1] = dini_Int(SERVER_FACTION_FILE_2, "Rank1");
    Faction2[fFaction2][fRank2] = dini_Int(SERVER_FACTION_FILE_2, "Rank2");
    Faction2[fFaction2][fRank3] = dini_Int(SERVER_FACTION_FILE_2, "Rank3");
    Faction2[fFaction2][fRank4] = dini_Int(SERVER_FACTION_FILE_2, "Rank4");
    Faction2[fFaction2][fRank5] = dini_Int(SERVER_FACTION_FILE_2, "Rank5");
    Faction2[fFaction2][fRank6] = dini_Int(SERVER_FACTION_FILE_2, "Rank6");
    Faction2[fFaction2][fRank7] = dini_Int(SERVER_FACTION_FILE_2, "Rank7");
    Faction2[fFaction2][fSkin1] = dini_Int(SERVER_FACTION_FILE_2, "Skin1");
    Faction2[fFaction2][fSkin2] = dini_Int(SERVER_FACTION_FILE_2, "Skin2");
    Faction2[fFaction2][fSkin3] = dini_Int(SERVER_FACTION_FILE_2, "Skin3");
    Faction2[fFaction2][fSkin4] = dini_Int(SERVER_FACTION_FILE_2, "Skin4");
    Faction2[fFaction2][fSkin5] = dini_Int(SERVER_FACTION_FILE_2, "Skin5");
    Faction2[fFaction2][fSkin6] = dini_Int(SERVER_FACTION_FILE_2, "Skin6");

    return 1;
}
Reply
#7

Try using format instead to get around the issue:

pawn Код:
format(Faction1[fFaction1][fLeader],24,"%s",dini_Get(SERVER_FACTION_FILE_1, "Leader"));
Reply
#8

I'm not sure why you are creating multiple enums, when this could be done easily in one?

pawn Код:
FactionDetails[factionid][fName]; // Example
Reply
#9

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Try using format instead to get around the issue:

pawn Код:
format(Faction1[fFaction1][fLeader],24,"%s",dini_Get(SERVER_FACTION_FILE_1, "Leader"));
No errors or anything but it won't read the information when I need it. This is just an example command I did to test it out. I don't get that SendClientMessage:

pawn Код:
COMMAND:test(playerid, params[])
{
    new msg[50];
    format(msg, 300, "The name of this faction is %s, Skin is: %i", Faction1[fFaction1][fFactionName], Faction1[fFaction1][fSkin4]);
    SendClientMessage(playerid, COLOR_WHITE, msg);
    return 1;
}
Thank you, it works now. Can you explain me what I did wrong there?
Reply
#10

Quote:

#undef MAX_PLAYERS
#define MAX_PLAYERS 200

Nice!! (something like redef exists? )

no scripting errors and no message at all means there is something wrong with your cmd handling... returning 0 on onplayercmdtext ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)