OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting Multiplayer => Topic started by: fleepee on 06 Feb 2010, 12:17:00

Title: transfer weapons and ammo in a MP campaign
Post by: fleepee on 06 Feb 2010, 12:17:00
I'm making a campaign, and I wish that it can be played in an hosted MP way.
I've got problems transfering weapons and ammo from a mission to the next one... :no:

here are the codes i'm using (you'll see I'm not a good scripter, sorry...):
in the campaign's description.ext:
Code: [Select]
weaponPool=true;
    
class Campaign
{
    name =  "Once upon a time...";
    firstBattle = missions;
//    disableMP = false;


    class missions
...etc...

in a save_status.SQF file launched at first mission's end:
Code: [Select]
if (alive civ1 and primaryWeapon civ1!="") then {addweaponpool [primaryWeapon civ1,1];};
if (alive civ1 and secondaryWeapon civ1!="") then {addweaponpool [secondaryWeapon civ1,1];};
if (alive civ2 and primaryWeapon civ2!="") then {addweaponpool [primaryWeapon civ2,1];};
if (alive civ2 and secondaryWeapon civ2!="") then {addweaponpool [secondaryWeapon civ2,1];};
if (alive civ3 and primaryWeapon civ3!="") then {addweaponpool [primaryWeapon civ3,1];};
if (alive civ3 and secondaryWeapon civ3!="") then {addweaponpool [secondaryWeapon civ3,1];};
if (alive civ4 and primaryWeapon civ4!="") then {addweaponpool [primaryWeapon civ4,1];};
if (alive civ4 and secondaryWeapon civ4!="") then {addweaponpool [secondaryWeapon civ4,1];};
if (alive civ5 and primaryWeapon civ5!="") then {addweaponpool [primaryWeapon civ5,1];};
if (alive civ5 and secondaryWeapon civ5!="") then {addweaponpool [secondaryWeapon civ5,1];};
if (alive civ6 and primaryWeapon civ6!="") then {addweaponpool [primaryWeapon civ6,1];};
if (alive civ6 and secondaryWeapon civ6!="") then {addweaponpool [secondaryWeapon civ6,1];};
if (alive civ7 and primaryWeapon civ7!="") then {addweaponpool [primaryWeapon civ7,1];};
if (alive civ7 and secondaryWeapon civ7!="") then {addweaponpool [secondaryWeapon civ7,1];};
if (alive civ8 and primaryWeapon civ8!="") then {addweaponpool [primaryWeapon civ8,1];};
if (alive civ8 and secondaryWeapon civ8!="") then {addweaponpool [secondaryWeapon civ8,1];};

//{deleteStatus _x} foreach ["civ1", "civ2", "civ3", "civ4", "civ5", "civ6", "civ7", "civ8"];

if (alive civ1) then {civ1 saveStatus "civ1";};
if (alive civ2) then {civ2 saveStatus "civ2";};
if (alive civ3) then {civ3 saveStatus "civ3";};
if (alive civ4) then {civ4 saveStatus "civ4";};
if (alive civ5) then {civ5 saveStatus "civ5";};
if (alive civ6) then {civ6 saveStatus "civ6";};
if (alive civ7) then {civ7 saveStatus "civ7";};
if (alive civ8) then {civ8 saveStatus "civ8";};

addweaponpool ["binocular",5];

addmagazinepool ["30Rnd_762x39_AK47",50];
if (true) exitwith {};
there are more addmagazinepool lines as I don't know yet how to transfer the exact amount of ammo of each playable slots (can be AIs in game)

in a load_status.sqf file launched in the init code of next mission's start:
Code: [Select]
civ1 loadStatus "civ1";
civ2 loadStatus "civ2";
civ3 loadStatus "civ3";
civ4 loadStatus "civ4";
civ5 loadStatus "civ5";
civ6 loadStatus "civ6";
civ7 loadStatus "civ7";
civ8 loadStatus "civ8";

if (true) exitwith {};

When I reach the briefing of the second mission, I've got the weapons added in the weapon pool all right, but I can't select any of them nor magazines... ???

It works perfectly when I'm not hosting the campaign... :dunno:
I've search the forum for answers, but nothing worked... :weeping:

Help me please!!!
Title: Re: transfer weapons and ammo in a MP campaign
Post by: kju on 06 Feb 2010, 13:47:18
I think the BI a2 campaign uses it too or at the a1?

You could check how they are doing it.  :)
Title: Re: transfer weapons and ammo in a MP campaign
Post by: fleepee on 06 Feb 2010, 16:06:07
I had a look on A2 missions, but I didnt see anything that could transfer weapons and ammo to next mission, or... I don't understand it!! ;)
Title: Re: transfer weapons and ammo in a MP campaign
Post by: kju on 06 Feb 2010, 22:32:35
BI is using loadStatus and saveStatus too. Search again in ca\missions\campaign\missions.
Title: Re: transfer weapons and ammo in a MP campaign
Post by: fleepee on 07 Feb 2010, 07:31:39
I couldn't find these directories using eliteness to de-PBO the Arma2/addons/CA file... :scratch:
Title: Re: transfer weapons and ammo in a MP campaign
Post by: kju on 07 Feb 2010, 12:13:39
ca is the name space. You need to check the missions.pbo.
Title: Re: transfer weapons and ammo in a MP campaign
Post by: JamesF1 on 07 Feb 2010, 14:50:19
According to the Biki, loadStatus doesn't work in MP - so that probably won't solve your problem, will it?
Title: Re: transfer weapons and ammo in a MP campaign
Post by: kju on 07 Feb 2010, 18:08:56
The note is probably based on OFP/ArmA I.

ArmA II introduced MP campaign via local host.
Title: Re: transfer weapons and ammo in a MP campaign
Post by: JamesF1 on 07 Feb 2010, 19:41:29
Ahh, fair enough... I cede to your superior knowledge :good:
Title: Re: transfer weapons and ammo in a MP campaign
Post by: fleepee on 07 Feb 2010, 21:18:08
I've read the same about loadstatus in mp, and i'm sure there is a way to do what i want...  :D
Title: Re: transfer weapons and ammo in a MP campaign
Post by: kju on 07 Feb 2010, 22:51:21
Well why not try it with a simple setup first in SP and go from the to local host.
Or double check if it does work in the a2 campaign.
From what I recall for some missions you can retain the equipment from the mission before.

Maybe its a MP locality problem. Do you execute it only on the host or also on each client?

PS: This is not needed at the end of file:
Code: [Select]
if (true) exitwith {};
if the script returns a value, can do just
Code: [Select]
true;
Title: Re: transfer weapons and ammo in a MP campaign
Post by: fleepee on 28 Feb 2010, 13:27:03
everything works fine in SP, it doesn't when I host the campaign...
I couldn't find anything about savestatus in the CA missions folder.

Quote
Maybe its a MP locality problem. Do you execute it only on the host or also on each client?
the savestatus script is launched in an outro script launched by a trigger activated by a publicvariabled variable...

in the next mission, the loadstatus script is launched in the init file...
So I think each client runs the scripts... Am I wrong?
Title: Re: transfer weapons and ammo in a MP campaign
Post by: kju on 28 Feb 2010, 16:44:39
init file = init.sqf?

You mean a map placed trigger?
Did you debug MP with diag_log?
Title: Re: transfer weapons and ammo in a MP campaign
Post by: fleepee on 28 Feb 2010, 18:28:44
Quote
init file = init.sqf?
yes

Quote
You mean a map placed trigger?
yes

Quote
Did you debug MP with diag_log?
I don't know what it is and how to do it... ???
I've just checked arma2server.rpt and arma2.rpt
Title: Re: transfer weapons and ammo in a MP campaign
Post by: kju on 28 Feb 2010, 18:39:28
http://community.bistudio.com/wiki/diag_log

You can log variables (anything you like) to the rpt.
It is very useful for analysis. In addition to Gaia's debug console.  :good:
Title: Re: transfer weapons and ammo in a MP campaign
Post by: fleepee on 17 Jul 2010, 10:56:48
I'm still losing time with that function...

Can't someone help me?!!

The campaign is ready for release, but as the scenario is civilians entering a resistance movement, it's important that the weapons they collect can be transfered to the next mission...

I'm using the weaponpool, I've got the weapons I (and other group units) had at the end of first mission added in the weaponpool all right, but when I reach the briefing of the second mission, if I select weapons in the briefing, they disappear from weapon pool...

It works perfectly when I'm not hosting the campaign and play the campaign in single player...
Title: Re: transfer weapons and ammo in a MP campaign
Post by: kju on 17 Jul 2010, 17:55:59
Maybe just a game bug or is there a working example?
Does the OA campaign use that feature?

If not, I'd suggest you to create a report at the CIT.

Maybe as workaround you can come up with a scripting solution.
Query the players weapon via script during the briefing phase constantly and readd it once the mission starts.
Title: Re: transfer weapons and ammo in a MP campaign
Post by: fleepee on 17 Jul 2010, 18:17:02
What is CTI? :dunno:
in the init.sqf of first mission I'm defining 2 arrays:
Code: [Select]
weapon_pool = [];
ammo_pool = [];

i'm using at mission ending a script including:

Code: [Select]
if (_x hasWeapon "ItemGPS") then {weapon_pool = weapon_pool + ["ItemGPS"]};
removeAllItems  _x;
_weps = weapons _x;
_mags = magazines _x;
{weapon_pool = weapon_pool + [_x]} foreach _weps;
{ammo_pool = ammo_pool + [_x]} foreach _mags;

} foreach units igor_team;

savevar "weapon_pool";
savevar "ammo_pool";

And in the following mission:
Code: [Select]
if (local server) then {
{crate_pool addweaponCargo [_x,1]} foreach weapon_pool;
{crate_pool addMagazineCargo [_x,1]} foreach ammo_pool;
};

crate_pool is an emptied ammo crate placed in the second mission.
when I display the weapons and ammo I want to save to next mission with
Code: [Select]
hint format ["%1,%2", weapon_pool, ammo_pool], I've got the entire both lists at the end of first mission, but these lists are empty in the next one... ???

How does the "savevar" command works?
How can I get these arrays in the next mission?
Title: Re: transfer weapons and ammo in a MP campaign
Post by: kju on 19 Jul 2010, 07:50:18
first use diag_log:
http://community.bistudio.com/wiki/diag_log

second as BI uses saveVar in both a2 and OA, it does work
the way you use it looks, OK, but again check how BI uses it

you can use the campaignConfigFile namespace to check if your variables are in there
http://community.bistudio.com/wiki/campaignConfigFile

campaignConfigFile getVariable "myVar"

use a debug console like gaia's. see attachment. also works in mp

maybe just the weapon pool is broken and not saveVar

to explain your test setup precisely would help a lot obviously (client, server, host, etc)

CIT (not CTI): http://dev-heaven.net/projects/cis

hope it helps  :blink:
Title: Re: transfer weapons and ammo in a MP campaign
Post by: fleepee on 20 Jul 2010, 09:13:09
Apparently, the "savevar" commands doesn't work for a MP hosted campaign!!
That's so silly! >:(
I'm now using "savestatus" to transfer weapons and ammo...
the weapon pool in the briefing would have been greater than transfer crates or truck contents...
Title: Re: transfer weapons and ammo in a MP campaign
Post by: ual002 on 20 Jul 2010, 19:44:03
If you get the finished product working Id be interested to see the scripting and an explanation of how to set it up between the two missions.  I'm sure this may end up being a very popular thread for MP campaign makers in ARMA2.

-Cheers