Save text instead of numbers
#1

Hi. I have now for some time tried to figure out how to save letters instead of numbers. I want to allow people to choose what class they want to join as when they first join the server. Players will be able to choose from cowboy, indian and mexican.

Here is how my code current looks like:
pawn Код:
if (dialogid == 3)
    {
            switch(listitem) // This is far more efficient than using an if-elseif-else structure
            {
                case 0: // Listitems start with 0, not 1
                {
                    PlayerInfo[playerid][pClass] = 1;
                }
                case 1:
                {
                    PlayerInfo[playerid][pClass] = 2;
                }
                case 2:
                {
                    PlayerInfo[playerid][pClass] = 3;
                }
                // Add the rest of your listitems for dialog 1 here
            }
    }
    return 1;
}
As you can see I save pClass as numbers. What I want to do instead is save it as letters. Such as case 0 could look like this:
pawn Код:
case 0: // Listitems start with 0, not 1
                {
                    PlayerInfo[playerid][pClass] = "Cowboy";
                }
How can I do this?

Thanks.
Reply
#2

eyyy, anybody?
Reply
#3

in the enum or w/e you're using, you need to make "pClass[16]", and then that might work, If not you can format the variable like you format strings.

But you must define a size ([16]) in the PlayerInfo data enum.
Reply
#4

I have tried to put pClass[16], but it didn't work.
Reply
#5

Supposing you are using Dini (as you didn't specify), use dini_Set
Reply
#6

Quote:
Originally Posted by admantis
Посмотреть сообщение
Supposing you are using Dini (as you didn't specify), use dini_Set
He doesn't mean saving the file, re-read.

I suggest you use strmid.

pawn Код:
strmid(PlayerInfo[playerid][pClass], "Cowboy", 0, strlen("Cowboy"), 255);
Reply
#7

ok the easy way is at the top of your script go
pawn Код:
#define TEAM_COWBOY  1
#define TEAM_INDIAN     2
#define TEAM_MEXICAN  3
then you can go
pawn Код:
if (dialogid == 3)
    {
            switch(listitem) // This is far more efficient than using an if-elseif-else structure
            {
                case 0: // Listitems start with 0, not 1
                {
                    PlayerInfo[playerid][pClass] = TEAM_COWBOY;
                }
                case 1:
                {
                    PlayerInfo[playerid][pClass] = TEAM_INDIAN;
                }
                case 2:
                {
                    PlayerInfo[playerid][pClass] = TEAM_MEXICAN;
                }
                // Add the rest of your listitems for dialog 1 here
            }
    }
    return 1;
}
now in the defines you can call it whatever you want i just name it like that so i know what i am looking at
hope that helps
Reply
#8

Sorry, perhaps I wasn't very specific with what I meant, I need to save the file aswell to my Users folder. I'll experiment with what you have given me and see if I can figure it out. Thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)