SA-MP Forums Archive
Save text instead of numbers - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Save text instead of numbers (/showthread.php?tid=232084)



Save text instead of numbers - Omecken - 26.02.2011

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.


Re: Save text instead of numbers - Omecken - 26.02.2011

eyyy, anybody?


Re: Save text instead of numbers - Mike Garber - 26.02.2011

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.


Re: Save text instead of numbers - Omecken - 26.02.2011

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


Re: Save text instead of numbers - admantis - 27.02.2011

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


Re: Save text instead of numbers - pawn_ - 27.02.2011

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);



Re: Save text instead of numbers - (SF)Noobanatior - 27.02.2011

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


Re: Save text instead of numbers - Omecken - 27.02.2011

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.