Help with a stock.
#1

Hey, I'm quite new to pawn so please don't laugh.
I'm developing a training gamemode for a roleplay server and I'm trying to stock the names of the faction's ranks.
In this case the police department, and I'm having some problems with it.
I want it so when I type "rankname[playerid]" it will display the rank's name instead of the number.

PHP код:
stock rankname(playerid)
{
    switch(
PlayerInfo[playerid][pRank])
    {
        case 
0rankname(playerid) = "None";
        case 
1rankname(playerid) = "Recruit";
        case 
2rankname(playerid) = "Police Officer I";
        case 
3rankname(playerid) = "Police Officer II";
        case 
4rankname(playerid) = "Lead Officer";
        case 
5rankname(playerid) = "Senior Lead Officer";
        case 
6rankname(playerid) = "Sergeant";
        case 
7rankname(playerid) = "Staff Sergeant";
        case 
8rankname(playerid) = "Lieutenant";
        case 
9rankname(playerid) = "Captain";
        case 
10rankname(playerid) = "Commander";
        case 
11rankname(playerid) = "Deputy Chief";
        case 
12rankname(playerid) = "Chief of Police";
    }

Please tell me what's wrong with it and how can I fix this, thanks.
Reply
#2

Hello.

Can you show us that error, which appears?

Greetz, LetsOWN
Reply
#3

pawn Код:
stock rankname(playerid)
{
    switch(PlayerInfo[playerid][pRank])
    {
        case 0: return "None";
        case 1: return "Recruit";
        case 2: rankname(playerid) = "Police Officer I";
        case 3: rankname(playerid) = "Police Officer II";
        case 4: rankname(playerid) = "Lead Officer";
        case 5: rankname(playerid) = "Senior Lead Officer";
        case 6: rankname(playerid) = "Sergeant";
        case 7: rankname(playerid) = "Staff Sergeant";
        case 8: rankname(playerid) = "Lieutenant";
        case 9: rankname(playerid) = "Captain";
        case 10: rankname(playerid) = "Commander";
        case 11: rankname(playerid) = "Deputy Chief";
        case 12: rankname(playerid) = "Chief of Police";
    }
}
This should work, just change the last ones with 'return' aswell. Though, im not really sure if it works like this
Reply
#4

pawn Код:
new ranknames[][] = {
"None",
"Recruit",
"Police Officer I",
"Police Officer II",
"Lead Officer",
"Senior Lead Officer",
"Sergeant",
"Staff Sergeant",
"Lieutenant",
"Captain",
"Commander",
"Deputy Chief",
"Chief of Police"
};
Then use this as a string for the rank names:

ranknames[RANK NUMBER GOES HERE]
Reply
#5

Quote:
Originally Posted by Wesley221
Посмотреть сообщение
pawn Код:
stock rankname(playerid)
{
    switch(PlayerInfo[playerid][pRank])
    {
        case 0: return "None";
        case 1: return "Recruit";
        case 2: rankname(playerid) = "Police Officer I";
        case 3: rankname(playerid) = "Police Officer II";
        case 4: rankname(playerid) = "Lead Officer";
        case 5: rankname(playerid) = "Senior Lead Officer";
        case 6: rankname(playerid) = "Sergeant";
        case 7: rankname(playerid) = "Staff Sergeant";
        case 8: rankname(playerid) = "Lieutenant";
        case 9: rankname(playerid) = "Captain";
        case 10: rankname(playerid) = "Commander";
        case 11: rankname(playerid) = "Deputy Chief";
        case 12: rankname(playerid) = "Chief of Police";
    }
}
This should work, just change the last ones with 'return' aswell. Though, im not really sure if it works like this
As far as I know, returning strings like that in PAWN crashes the compiler. I personally do what you're (the original poster) trying to do like this:

pawn Код:
stock MyFunc()
{
    new szRet[64]; //Replace 64 with your longest return string length.
    switch(NUMBER) //Replace NUMBER with your array
    {
        case 0: strcat(szRet, "Case Zero");
        case 1: strcat(szRet, "Case One");
        //etc etc
    }
    return szRet;
}
Reply
#6

But why use cases? It's such an inefficient way to do it. Look at my code.
Reply
#7

Quote:
Originally Posted by MP2
Посмотреть сообщение
But why use cases? It's such an inefficient way to do it. Look at my code.
You posted at the same time as me, but yes this would work in a much better way - however the original poster requested a function, not an alternate way to do it.
Reply
#8

PHP код:
stock rankname(playerid)
{
new 
restring[128];
            switch(
PlayerInfo[playerid][pRank])
            {
                        case 
0restring "None";
                        case 
1restring "Recruit";
                        case 
2restring "Police Officer I";
                        case 
3restring "Police Officer II";
                        case 
4restring "Lead Officer";
                        case 
5restring "Senior Lead Officer";
                        case 
6restring "Sergeant";
                        case 
7restring "Staff Sergeant";
                        case 
8restring "Lieutenant";
                        case 
9restring "Captain";
                        case 
10restring "Commander";
                        case 
11restring "Deputy Chief";
                        case 
12restring "Chief of Police";
            }
return 
restring;

Reply
#9

Lock and archive.
You really confused me, but yanir3's post is working great, thank you!
[rep+]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)