Jump to content
Sign in to follow this  
Narsiph

Script does not work on Server - Out of Clues (Save & Unlock Script)

Recommended Posts

Heyho.

 

I want to achieve, that the weapon unlock script does what it should do. Offline it does its work perfectly but i cant get it to work on the dedicated server (gameserver). Neither does it save it over inidbi (i think this problem is bound right to the rest of it not working) nor does it do its job correclty. Yet, it throws absolutely no errors oO I am finally out of clues.

 

/*
Weapon Check Script by Narsiph

Call this script, if you want to check the main-box for weapons to unlock for the ACE-Arsenal.
With "unlimited" you can change the amount of weapon needed. Its always +1. So if you type in 19, you actually need 20.
 
The temporary chest is needed, because weapons that are not available to unlock, will be cycled through and put back in the
main chest.

Main ACE Arsenal Chest: "merc_arsenal_box"
Temporary Chest for the 'check'-cycle: "Weapon_cache_temp"
*/


if (isServer or isDedicated) then
{
	[] spawn
	{
	while {mercWhile} do
	{

// Change the value (Default: 19) if you want to unlock Weapons faster/slower.
unlimited = 1;




/*
Puts all the weapons in an local variable (classnames & amount)
The array from "getWeaponCargo" looks like this:
["classname1", "classname2"],["14",""]
*/
_itemarray = getWeaponCargo merc_arsenal_box;



// The local variable presented here, counts how many different weapons are in the box.
_weaponnames = count (_itemarray select 0);



// If there are, somehow, weapons in the temporary chest, they will get deleted with this.
clearWeaponCargo weapon_cache_temp;



// We need those variables for the database.
_inidbi = ["new", "Merc Arsenal"] call OO_INIDBI;



/*
We decided to go with a 'for' instead a 'while'. With both you can actually achieve the same.
The _loop local variable is set to zero and helps us not only to count but also to select the weapons
and the amount from the array.

It loops only as long as there are weapons in the array.

Weaponamount is the amount of weapons from the getWeaponCargo in the second (0,1) array. Combined
with the loop variable, we made sure it goes through all the weapons.
Weaponname is exactly that. The string of the weapon class name.

If the weapon is more than the variable 'unlimited' (default: 19), so, 20 and more, it will be added
as a general usable weapon in the ace-arsenal.
Else the weapon is put, temporarily, in another box.

We save every unlimited weapon in the Merc Arsenal Database, under the Unlimited key.
That for, we use a seperator that we can later use to make an weapon array.
*/


for [{_loop=0}, {_loop<_weaponnames}, {_loop=_loop+1}] do
{
_weaponamount = (_itemarray select 1) select _loop;
_weaponname = (_itemarray select 0) select _loop;
	if (_weaponamount > unlimited) then 
		{
			[merc_arsenal_box, [_weaponname]] call ace_arsenal_fnc_addVirtualItems;
			_seperator = ",";
			_readoldweapons = ["read", ["Merc Arsenal", "Unlimited"]] call _inidbi;
			_newmercweapons = _readoldweapons + _seperator + _weaponname;
			["write", ["Merc Arsenal", "Unlimited", _newmercweapons]] call _inidbi;
			
		}
		else
		{
			weapon_cache_temp addWeaponCargo [_weaponname,_weaponamount];

		};
};



// With this, we delete all the weapons in the main box.
clearWeaponCargo merc_arsenal_box;




// This is, more or less, the exact same thing as the for-loop before.
// This time we put back all the weapons in the main box so they can be used by the mercs.
_itemarray = getWeaponCargo weapon_cache_temp;
_weaponnames = count (_itemarray select 0);

for [{_loop=0}, {_loop<_weaponnames}, {_loop=_loop+1}] do
{
_weaponamount = (_itemarray select 1) select _loop;
_weaponname = (_itemarray select 0) select _loop;

		
merc_arsenal_box addWeaponCargo [_weaponname,_weaponamount];

};	
};
};
}
else
{

hint "YOU SHALL NOT SAVE!"

};

 

This gets called over the initServer.sqf. My money-save-script works just fine and also writes its stuff down into the inidbi-db... So, i dont know where i went wrong. Maybe i oversaw something.

 

Thanks in advance for your help.

 

Stay crunchy.

Share this post


Link to post
Share on other sites

Update to the main post:

 

I figured out why there arent any errors. The script works just fine, yet only on the server. Means: It writes the data to the inidbi-db's, transfers and deletes the weapons. Yet: Not for all (jip) clients. So the problem is different. I am on it and trying to fix it.

 

Stay crunchy.

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  

×