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

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
Ænima
Addicted to Zandronum
Posts: 3578
Joined: Tue Jun 05, 2012 6:12 pm

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

#1

Post by Ænima » Sun Jul 15, 2012 1:34 pm

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?
Reinforcements: midgame Survival joining/respawning
Doom64: Unabsolved: Doom64 + Diablo II
ZandroSkins: a pack made by our community
AeniPuffs: 3D blood and bullet puff effects, free to use for your own mods
Squad Radio: a WASD-based radio chat menu, add your own custom sounds!
Mercenaries (on hold)
Image

Theshooter7
Forum Regular
Posts: 262
Joined: Wed Jun 06, 2012 2:15 am

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

#2

Post by Theshooter7 » Tue Jul 17, 2012 3:16 pm

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.
Image

Ijon Tichy
Frequent Poster Miles card holder
Posts: 901
Joined: Mon Jun 04, 2012 5:07 am

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

#3

Post by Ijon Tichy » Wed Jul 18, 2012 3:47 am

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
Last edited by Ijon Tichy on Wed Jul 18, 2012 3:48 am, edited 1 time in total.

Watermelon
Zandrone
Posts: 1244
Joined: Thu Jun 28, 2012 9:07 pm
Location: Rwanda

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

#4

Post by Watermelon » Wed Jul 18, 2012 6:37 pm

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.

ZzZombo
Forum Regular
Posts: 323
Joined: Mon Jun 11, 2012 12:11 pm
Location: Ravenholm

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

#5

Post by ZzZombo » Sun Jul 22, 2012 12:41 pm

I need it, dude.

Post Reply