PDA

View Full Version : enum Question.


SilencedPistol
09/05/2013, 08:42 PM
Okay, so I'm making a faction system and my main player enum is pInfo which has like pName, pPass, pSkin and stuff within it.

So what I'm asking is, how would I alter my enum to accommodate a faction system? Do I put pFaction, pRank and stuff within my pInfo enum, or create a separate enum like pFaction or something?

IceCube!
09/05/2013, 08:46 PM
Removed: The guy below is willing to go into more detail for you on here, I however dont have the paitience to do such as thing on here so I'll withdraw this comment.

Scenario
09/05/2013, 08:47 PM
This actually depends on how you plan to structure your faction system...

You can do it many different ways. You can make it so a person can be in a virtually unlimited amount of factions, make them allowed to be in a single faction, or in a set number of factions.

Furthermore, you can also make the faction system where ranks are dynamic (meaning instead of having 12 set ranks, you can have as many as you need/want) and/or where each "rank" has a different "rank description."

The possibilities are endless. So, tell me how you want to accomplish this so we can proceed further.

Rayan_black
09/05/2013, 08:57 PM
You can use the same enum if you want, but I prefer using different enums for each system I do so just:


enum fInfo
{
pOwner,
pMembers,
pRank,
blabla...etc..
}
new FactionInfo[MAX_PLAYERS][fInfo]

SilencedPistol
09/05/2013, 09:16 PM
Well RealCop, I'd like a dynamic faction system with a few commands and such. If you want, we can take this to PMs so we can get in contact more directly?

Scenario
09/05/2013, 09:19 PM
There's no point in taking this into a private discussion. There are 12,000 other coders on this forum that might assist you faster than I can in some aspects.

What's your saving system?

SilencedPistol
09/05/2013, 09:25 PM
y_ini and also using ZCMD for processing. Ultimatley and eventually, I want everything dynamic, I'll go into detail here.

/factionlist - Displays a list of 10 factions (maximum is 10). Each faction will be given an ID from 1 - 10.
/makeleader [playerid] [factionid] - Sets the playerid as leader of that faction ID.
/invite [playerid] - For use by higher faction ranks.
/uninvited [playerid] - For use by higher faction ranks.
/renamefaction [factionid] - Renames the factions name on /factionlist.
/setrank [playerid] [custom rank name] - Sets players name.

That's basically what I want eventually. I aint asking you for a code, just how would I go about arranging things so that I can make all that I want work?

Scenario
09/05/2013, 09:26 PM
One more question; How many factions can a player be in at once?

SilencedPistol
09/05/2013, 09:28 PM
Oh, just a maximum of 1 faction.

Scenario
10/05/2013, 04:50 PM
I apologize for the delayed response; had some stuff to take care of personally.

Let's begin working with the saving system. Now, bare in mind I don't know how y_ini works, but it should still be simple enough to allow me to explain this to you.

You said you only want 10 factions; so you're basically going to have one file per faction. In each file would be the following variables:

factionName
factionType (i.e. 1 = normal; 2 = LAW; 3 = EMS; 4 = GOV - we do this to determine command permissions)
factionRanks

Now, this is where it could get interesting. Upon creating the faction you COULD make it so you can set the number of ranks that the faction will have. Basically, you'll ask the administrator creating the faction how many ranks will be created. They'll input a number (for this example, let's say 15) and you'll set "factionRanks" to 15. Now, you'll ask them to input a rank name per each rank number. So, in total, they need 15 rank names.

In the file, you can format the "factionRankX" line where X is the rank number. I feel like this piece of code could assist in showing you how this is done.

public OnDialogResponse(...)
{
switch(dialogid)
{
case DIALOG_NAME:
{
if(response)
{
CreatingFactionRank[playerid]++; // see below

if(CreatingFactionRank[playerid] <= CreatingFactionTotalRanks[playerid]) // check to see if we've reached the amount of ranks we're creating..
{
// okay, so let's say that "inputtext" is the faction rank name; what we're going to do is open the .ini file of the faction and format this string:

format(szString, sizeof(szString), "factionRank%d", CreatingFactionRank[playerid]); // CreatingFactionRank[playerid] should increase on each dialog response
// it will tell us which number we're editing per each dialog response

WRITE FORMAT TO FILE HERE

// now we can format a new line so we can tell the admin which faction rank they're editing

format(szString, sizeof(szString), "You're now editing rank %d.\n\nPlease write the rank name below.", CreatingFactionRank[playerid]);
ShowPlayerDialog(playerid, DIALOG_ID, DIALOG_STYLE_INPUT, "Creating a Faction - Setting Rank Names", szString, "Submit", "Close");
}
}
}
}
return 1;
}
Let's say you had 10 ranks. The faction's file would look like this:

The faction ID would serve as its file name. The contents would include the following:

factionName = Los Santos Police Department
factionType = 2
factionRanks = 10
factionRank1 = Chief of Police
factionRank2 = Deputy Chief of Police
factionRank3 = Commander
factionRank4 = Captain
factionRank5 = Lieutenant
factionRank6 = Senior Lead Officer
factionRank7 = Police Officer III
factionRank8 = Police Officer II
factionRank9 = Police Officer I
factionRank10 = Probationary Officer

And, as far as I can see, you would be done with the creation of the faction.

When you load the faction, you'll need to load "factionRanks" and then make sure you use a format to load each faction rank depending on how many there are. Just keep in mind that everything has a limit. If you want "unlimited" ranks, just set it to like 30. Nobody will ever hit 30 ranks in a single faction- that's overkill.

As far as putting people in a faction is concerned, they just need two additional variables. They would be "pFaction" and "pRank".

At runtime, you would load all of the factions into their own enum and so when you need to figure out someone's rank name you would use the "pRank" variable to determine which rank number it is. Let me know if you need an example.

I hope this helps!

SilencedPistol
10/05/2013, 05:02 PM
This is becoming a lot more clearer to me, but what I want to know now is; where do I start?

What do I need to create within my gamemode to get this ball rolling? Once I get to grips with it, I know for a fact that I could be able to write it like it's my name.

This is my enum for players' information, so what do I edit within this enum to accommodate the factions so I can start writing commands for those factions?

enum pInfo
{
pName,
pPass,
pSkin,
pMoney,
pAdminLevel,
Frozen
};

Scenario
10/05/2013, 05:05 PM
Add "pFaction" and "pRank" to the enum you gave.

#define MAX_FACTIONS 10

enum e_FactionInformation
{
factionID,
factionName,
factionType,
factionRanks,
factionRank[30][100] // creates 30 "factionRank" variables; you use them like: "fInfo[factionid][factionRank][faction rank id]"
};

new
fInfo[MAX_FACTIONS][e_FactionInformation];

SilencedPistol
10/05/2013, 05:08 PM
You mate, you're a fucking life saver.

However, I'm not big on dialogs myself, so I was wondering if you could help me out with the first few starting points to get my faction system on the road. Basically, I have 5 admin ranks: I would like to be able to use /makeleader [playerid] [factionid] on somebody which would then set them as the factions leader, and would give them access to commands such as /invite, /uninvited, /rankname and what not.

How do I go about doing this?

RajatPawar
10/05/2013, 05:15 PM
Mostly a similiar solution for the above, which I find simpler.

#define FACTION_LSPD 1
#define FACTION_MAFIA 2
#define FACTION_INVALID -1
#define RANK_ONE 125
#define RANK_TWO 215
#define RANK_INVALID -2

enum f_Player
{
pFACTION,
pRANK
}
new playerINFO[MAX_PLAYERS][f_Player];
stock Faction_SetPlayer(playerid, factionid)
{
if( factionid != FACTION_INVALID) return playerINFO[playerid][pFACTION] = factionid;
}
stock Faction_SetRank(playerid, factionid, rank)
{
if(playerINFO[playerid][pFACTION] != -1)
{
if(rank != RANK_INVALID) return playerINFO[playerid][pRANK] = rank;
}
}

The same obviously. Just some ideas.

SilencedPistol
10/05/2013, 05:22 PM
@RealCop, I've compiled that piece of code you gave me, and these errors returned:


gamemodes\practisePRACTISEALL.pwn(96) : error 001: expected token: "}", but found "["
gamemodes\practisePRACTISEALL.pwn(97) : error 010: invalid function or declaration


Lines 96 & 97:

factionRank[30][100]
};

Scenario
10/05/2013, 05:23 PM
This could work for you, I believe:

CMD:makeleader(playerid, params[])
{
new
iID,
iFaction;

if(sscanf(params, "ud", iID, iFaction))
return SendClientMessage(playerid, COLOR, "SYNTAX: /makeleader [nick/id] [faction id]");
if(iID == INVALID_PLAYER_ID)
return SendClientMessage(playerid, COLOR, "ERROR: You've specified an invalid nickname/ID.");
if(iFaction < 1 || iFaction > 10)
return SendClientMessage(playerid, COLOR, "ERROR: You've specified an invalid faction ID.");

new
szString[144],
szName[MAX_PLAYER_NAME],
szName2[MAX_PLAYER_NAME];

GetPlayerName(playerid, szName, sizeof(szName));
GetPlayerName(playerid, szName2, sizeof(szName2));

format(szString, sizeof(szString), "* %s has set you as the leader of %s.", szName, fInfo[iFaction][fName]);
SendClientMessage(iID, COLOR, szString);
format(szString, sizeof(szString), "* You have set %s as the leader of %s.", szName2, fInfo[iFaction][fName]);
SendClientMessage(playerid, COLOR, szString);

pInfo[iID][pFaction] = iFaction;
pInfo[iID][pRank] = 1;
return 1;
}

SilencedPistol
10/05/2013, 05:34 PM
Complied.

These errors.


gamemodes\practisePRACTISEALL.pwn(96) : error 001: expected token: "}", but found "["
gamemodes\practisePRACTISEALL.pwn(97) : error 010: invalid function or declaration
gamemodes\practisePRACTISEALL.pwn(125) : error 017: undefined symbol "fName"
gamemodes\practisePRACTISEALL.pwn(127) : error 017: undefined symbol "fName"
gamemodes\practisePRACTISEALL.pwn(130) : error 028: invalid subscript (not an array or too many subscripts): "pInfo"
gamemodes\practisePRACTISEALL.pwn(130) : warning 215: expression has no effect
gamemodes\practisePRACTISEALL.pwn(130) : error 001: expected token: ";", but found "]"
gamemodes\practisePRACTISEALL.pwn(130) : error 029: invalid expression, assumed zero
gamemodes\practisePRACTISEALL.pwn(130) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


8 Errors.

Scenario
10/05/2013, 05:37 PM
Sorry, try this:

CMD:makeleader(playerid, params[])
{
new
iID,
iFaction;

if(sscanf(params, "ud", iID, iFaction))
return SendClientMessage(playerid, COLOR, "SYNTAX: /makeleader [nick/id] [faction id]");
if(iID == INVALID_PLAYER_ID)
return SendClientMessage(playerid, COLOR, "ERROR: You've specified an invalid nickname/ID.");
if(iFaction < 1 || iFaction > 10)
return SendClientMessage(playerid, COLOR, "ERROR: You've specified an invalid faction ID.");

new
szString[144],
szName[MAX_PLAYER_NAME],
szName2[MAX_PLAYER_NAME];

GetPlayerName(playerid, szName, sizeof(szName));
GetPlayerName(playerid, szName2, sizeof(szName2));

format(szString, sizeof(szString), "* %s has set you as the leader of %s.", szName, fInfo[iFaction][factionName]);
SendClientMessage(iID, COLOR, szString);
format(szString, sizeof(szString), "* You have set %s as the leader of %s.", szName2, fInfo[iFaction][factionName]);
SendClientMessage(playerid, COLOR, szString);

pInfo[iID][pFaction] = iFaction;
pInfo[iID][pRank] = 1;
return 1;
}

#define MAX_FACTIONS 10

enum e_FactionInformation
{
factionID,
factionName[75],
factionType,
factionRanks,
factionRank1[100],
factionRank2[100],
factionRank3[100],
factionRank4[100],
factionRank5[100],
factionRank6[100],
factionRank7[100],
factionRank8[100],
factionRank9[100],
factionRank10[100]
};

new
fInfo[MAX_FACTIONS][e_FactionInformation];

SilencedPistol
10/05/2013, 05:57 PM
The error seems to be with the iFaction thing, compiled and returned these errors:


gamemodes\practisePRACTISEALL.pwn(140) : error 028: invalid subscript (not an array or too many subscripts): "pInfo"
gamemodes\practisePRACTISEALL.pwn(140) : warning 215: expression has no effect
gamemodes\practisePRACTISEALL.pwn(140) : error 001: expected token: ";", but found "]"
gamemodes\practisePRACTISEALL.pwn(140) : error 029: invalid expression, assumed zero
gamemodes\practisePRACTISEALL.pwn(140) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.

Scenario
10/05/2013, 06:03 PM
Oh! pInfo needs to be whatever you use for your player enum. Like, when you get someone's password pInfo[playerid][pPassword] or something, but pInfo is obviously not what you're using.

SilencedPistol
10/05/2013, 06:09 PM
These are my enums.


enum pInfo
{
pName,
pPass,
pSkin,
pMoney,
pAdminLevel,
pFaction,
pRank,
Frozen
};
new PlayerInfo[MAX_PLAYERS][pInfo];

enum e_FactionInformation
{
factionID,
factionName[75],
factionType,
factionRanks,
factionRank1[100],
factionRank2[100],
factionRank3[100],
factionRank4[100],
factionRank5[100],
factionRank6[100],
factionRank7[100],
factionRank8[100],
factionRank9[100],
factionRank10[100]
};
new
fInfo[MAX_FACTIONS][e_FactionInformation];






What do I need to edit? Sorry for dragging you back here, but as soon as I get my head around this I'll be able to do it forever.

SilencedPistol
10/05/2013, 06:11 PM
@RealCop, The /makeleader command works perfectly! Everything saves in my Users folder when logging in and out, it's great!

However, I would now like to know a few more things and then I can manage the rest myself.

How do I create the /setrank command to change between ranks 1 (highest) to 10 (lowest).

How do I create the /setname command to change the factions' name.

How do I create the /factionlist command to display all 10 factions (I know what I want them to be).

And also, how do I assign commands to specific factions ranks, because I need rank level 3's to be able to use /invite in SAPD faction and what not.

Can you explain these things to me please?

Scenario
10/05/2013, 07:39 PM
They're all pretty straight forward...

CMD:setrank(playerid, params[])
{
new
iID,
iRank;

if(pInfo[playerid][pRank] != 1)
return SendClientMessage(playerid, COLOR, "ERROR: You can't use this command.");
if(sscanf(params, "ud", iID, iRank))
return SendClientMessage(playerid, COLOR, "SYNTAX: /setrank [nick/id] [rank]");
if(iID == INVALID_PLAYER_ID)
return SendClientMessage(playerid, COLOR, "ERROR: You've specified an invalid nickname/ID.");
if(iRank < 1 || iRank > 10)
return SendClientMessage(playerid, COLOR, "ERROR: You've specified an invalid rank. Valid ranks are between 1 and 10.");

new
szString[144],
szName[MAX_PLAYER_NAME],
szName2[MAX_PLAYER_NAME];

GetPlayerName(playerid, szName, sizeof(szName));
GetPlayerName(iID, szName2, sizeof(szName2));

format(szString, sizeof(szString), "* You have set %s(%d)'s rank to %d in %s.", szName2, iID, iRank, pInfo[iID][pFaction]); // change pInfo
SendClientMessage(playerid, COLOR, szString);

format(szString, sizeof(szString), "* %s(%d) has set your rank to %d in the %s.", szName, playerid, iRank, pInfo[iID][pFaction]); // change pInfo
SendClientMessage(iID, COLOR, szString);

pInfo[iID][pRank] = iRank; // change pInfo
return 1;
}

CMD:setname(playerid, params[])
{
new
iFaction,
szFactionName[50];

if(pInfo[playerid][pRank] != 1)
return SendClientMessage(playerid, COLOR, "ERROR: You can't use this command.");
if(sscanf(params, "ds[50]", iFaction, szFactionName))
return SendClientMessage(playerid, COLOR, "SYNTAX: /setname [faction id] [faction name]");

new
szString[144];

format(szString, sizeof(szString), "* You have set %s to %s.", fInfo[iFaction][factionName], params);
SendClientMessage(playerid, COLOR, szString);

copy(fInfo[iFaction][factionName], params);
return 1;
}

stock copy(dest[], source[]) for(new i = 0; i < strlen(source); i++) dest[i] = source[i];

CMD:listfactions(playerid, params[])
{
ListFactions(playerid);
return 1;
}

stock ListFactions(playerid)
{
new
szString[144];

for(new i = 0; i < MAX_FACTIONS; i++)
{
format(szString, sizeof(szString), "%d - %s", fInfo[i][factionID], fInfo[i][factionName]);
SendClientMessage(playerid, COLOR, szString);
}
}

SilencedPistol
10/05/2013, 08:32 PM
All works fine, simply brilliant RealCop.

You're very good at explaining things, and you write your code neatly like I do, so I can relate to it and actually understand it. I've given you a rep and sent you a PM of my gratitude.

I was now wondering if you'd help me with a few extra things like /invite, /f chat and a /gear command to access weapons for my FBI faction.

If you'd do that, I'd like to take this to PMs so that we can find eachother more easily.

If you guys stumble across this thread and need help, RealCop is the go to guy!

Scenario
10/05/2013, 08:54 PM
The /invite command is like the /setleader command. /f is basically a loop that checks if a player is in the faction and if so, they're sent the /f message. As for the /gear command, all you have to do is see if the player is in a faction type equal to 2.

SilencedPistol
10/05/2013, 09:47 PM
When I type /setname in game, it just returns the SendClientMessage, can you double check the command for me?

Scenario
11/05/2013, 01:25 AM
Okay, so you're saying the "copy" function isn't working then?

SilencedPistol
11/05/2013, 02:08 AM
I don't know man, it may be, but it doesn't work. (A bit tired atm.)

Scenario
11/05/2013, 02:42 AM
Oh, right! Change this:

copy(fInfo[iFaction][factionName], params);
To:

copy(fInfo[iFaction][factionName], szFactionNane);

SilencedPistol
11/05/2013, 04:39 PM
It compiled with no errors, but when I head in game and test out the commands, this happends:

I type /setname 0 Test and it just returns the /setname [factionid] [faction name] SendClientMessage.

I need it so that when I type /setname [factionid] [faction name] it changes the name of the faction in /factionlist, and also assigns it a faction ID from 1 -10.