Page 1 of 1

How do I save a number to a player's .ini?

Posted: Sun Jul 15, 2012 1:34 pm
by Ænima
Title says it all.

Lemme 'splain ... In Mercenaries, players will be able to save their items to the server after "registering", aka picking a 4-digit "PIN" number so that their items can be saved in a global array. When they join the server later, they'll need to provide their PIN so that they can get their stuff back.

However, I'd like to make things more convenient for players by making it so that their PIN is stored in their ini and automatically inputted (via an Enter script) when they join the game. How can I do this? I heard ZH does this with achievements or something.

And no, cheating (via players peeking at and editing their ini's) will not be possible. All of the player's weapons and items get stored on the server. The only thing that will be stored in their ini is their ID number.

So yeah, can anyone halp?

RE: How do I save a number to a player's .ini?

Posted: Tue Jul 17, 2012 3:16 pm
by Theshooter7
This may not be possible, since you can't manipulate strings in any way dynamically, unfortunately. In Zandronum, however, you could probably use Ijon's stralloc() lib to build a string containing the PIN, then use ConsoleCommand() with archivecvar to store it.

ZH probably just uses archivecvar with a specific boolean to tell whether the achievement has been completed or not.

The only way you could get around this is to have a really hackish method of storing each pin digit as a separate cvar, using archivecvar to store each one depending on the digit. Here is a simple (pseudo code) example:

Code: Select all

switch(digit1)
{
  case 0:
    ConsoleCommand("archivecvar pin_digit1 0");
    break;


  case 1:
    ConsoleCommand("archivecvar pin_digit1 1");
    break;


  case 2:
    ConsoleCommand("archivecvar pin_digit1 2");
    break;

    ....
}
Repeat for each digit in the pin. Then, when loading:

Code: Select all

switch(GetCVar("pin_digit1"))
{
  case 0:
    mypin[0] = 0;
    break;

  case 1:
    mypin[0] = 1;
    break;

    ....
Yeah, extremely hacky and messy but it's the only way I can think of for dynamic number loading.

RE: How do I save a number to a player's .ini?

Posted: Wed Jul 18, 2012 3:47 am
by Ijon Tichy
well if we have access to strparam:

Code: Select all

int conPIN = 2600;
int conStr = StrParam(s:"set derp_pin", d:conPIN, s:" ", d:GetActorProperty(0, APROP_Health)) );
ConsoleCommand(conStr);
also, if you can use stralloc, you necessarily have access to strparam - stralloc uses strparam extensively to rebuild strings

RE: How do I save a number to a player's .ini?

Posted: Wed Jul 18, 2012 6:37 pm
by Watermelon
You can also use the 98d way of storing a CVar currently, though its huge compared to Zandronum's StrParam, so if you want it I can provide it.

RE: How do I save a number to a player's .ini?

Posted: Sun Jul 22, 2012 12:41 pm
by ZzZombo
I need it, dude.