Jump to content
Sign in to follow this  
dachevs

JIP - Saving Variables

Recommended Posts

Hello, basically, I have a variable for money in my mission.

I need to know how to save that variable to the server, so when I reconnect, I get that variable back.

WHAT I KNOW:

-I know to use the OnPlayerConnected.

-I believe I have to save it into an array on the server, which I have done, but I don't know how to access something from an array which is only on the server.

Can anyone help me out?

Share this post


Link to post
Share on other sites

I'm no expert, but publicVariable and addPublicVariableEventHandler does seem like logical choices here. The event handler will not fire on the client updating the variable though.

Check out the mission Domination how the vars_array are used in this fashion to store variables and mission progress for jip'ing clients.

Share this post


Link to post
Share on other sites

I think you're going to always have to update every client's money variable (with the name of the player) to the server whenever they change it, since when a client disconnects you won't have access to his local money variable. Then, when a new player connects in that slot, compare the names, and if they're equal the server should set the client's money to the stored value.

What I would do: (or something along these lines)

Make a unique variable for each client slot that each client will use to update their money (EG w1_money, w2_money). Add an eventhandler on the server for each of these variables that saves the current player name and money variable in a small array w1_money_array = ["DaChevs",10000]. Then when a player connects, check the array for their slot to see if the names are the same, and if so, have the server update the money for that slot (W1money, etc) to the new value.

You'll need to make sure, though, that when a client connects he doesn't initialize the money to 0 AFTER the server updates it to the correct amount.

Also, since the publicvariable event handler doesn't fire on the computer that updates the variable, you'll have to save the array + name locally in case it's a player who has a server+client on the same arma instance.

I can help more if you need it.

Share this post


Link to post
Share on other sites

right, I believe its an array. And save it on the server.

then when they connect:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_name = _this select 0;

_savedmoneyvariable = Server_Stats_Array select 0;

if (player == _name) then

{

Cash = Cash + _savedmoneyvariable

};

maybe something along these lines?

I would love more help Captain, thanks wink_o.gif

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×