Jump to content
Sign in to follow this  
CodeVision

Spawning an Ammobox Clientside

Recommended Posts

Hi Guys,

I've seen lots of threads with repeat questions, and folks advising on using the search function...I feel like this is a question that has to have been answered before, but believe me, I've tried the search function....I've been sitting on this question for weeks because I don't want to look like an ass, but I'm just going to ask.

How can I spawn a client-side ammobox? I'm trying to build a basic mission template just a little at a time. I'm trying to get some fundamentals down, but an integral part of my template is the client-side ammo box like the one in Domination. Is it something that I need to put in the init.sqf? I'm lost here...

If it's something that's explained in one of the guides, maybe you could point me to it?

I hope I'm not clogging the editing forum with another repeat question, I just don't know what to do at this point.

Thanks in advance.

Share this post


Link to post
Share on other sites

this actually looks exactly like what I'm trying to add, and for the same purpose as well. I wanted to limit weapon options based on type, or failing that, based on name...Not sure if I'll go with the typeOf function, or keep the player name, but I will give this a try tomorrow to see if I can get it going.

Thanks!!!

Share this post


Link to post
Share on other sites

Or give this a shot, its almost exactly the same thing as used in Domination, right down to the crate contents. This was definitely me just kind of winging JIP, and as far as I tested it works perfectly with one person, but haven't tried with more or with JIP. Was just a theory thing. Also, because of the isServer at the top (to keep it all local), you can't test it on your own unless you comment that line out for testing.

Good luck! Sorry if this doesn't work for you. If it doesn't, let me know and it'll be a learning experience for me as well.

Share this post


Link to post
Share on other sites

OK, Grimes' example was a little easier for me to implement from scratch, at least for testing.

The problem I ran into here is the same problem I had when I tried to edit the ammobox filler script that's built into Domination....The box spawns in the proper place, but the ammo doesn't clear, and it doesn't load with the items in the script.

It's almost like the script works halfway. I tried the single and multiplayer editors, and I tried commenting out the server check line at the top of the script. Does this problem sound familiar at all?

I'm going to give the Demonized script a try now to see if I get a different result.

---------- Post added at 05:04 PM ---------- Previous post was at 05:01 PM ----------

One thing I would add, Grimes...I have the same problem when I try to load your JIP demo mission. The only change I made was to comment out the "if (isServer) exitWith {};" portion. Again, I tried the single and multiplayer editors, so I wonder if this is an issue with some kind of addon I might be running, or something I'm missing altogether.

---------- Post added at 05:50 PM ---------- Previous post was at 05:04 PM ----------

Alright, I took out the "[] spawn {" section of Grimes' script, and it seems to be working now. Does this section of the script do anything specifically? I don't want to break anything.

Thanks!

Share this post


Link to post
Share on other sites

My bet is that you copy and pasted the Domination ammobox filler bit straight over, which you can't do because of things defined in a file that was #include d. I do not know why you are having this problem, it worked just fine for me.

the [] spawn is used to loop the filler so that every 600 seconds/10 minutes it clears the box then re-adds everything, keeping it "full".

Edit: Ok, now I see what you mean by the crate not filling. Let me work on that, might've missed something.

Edit2: Replaced the spawn with while {alive _box} do { , but now the game hangs up for 10 seconds and spams 100,000 lines in my RPT about the sleep at the end being a generic error. Anybody know why the error is occurring? It's just a sleep..

Edited by Grimes [3rd ID]

Share this post


Link to post
Share on other sites

I use local ammo boxes in nearly everything I do for a variety of reasons, so here is a gutted example with the very basics.

_loc = _this select 0;

_box = "USSpecialWeaponsBox" createVehicleLocal (getmarkerpos _loc);

_box setdir (markerdir _loc);

_box allowdamage false;

_box setpos (getmarkerpos _loc);

while {true} do {

clearweaponcargo _box;

clearmagazinecargo _box;

_box addweaponcargo ["Binocular",5];

_box addmagazinecargo ["30Rnd_556x45_Stanag",50];

sleep 1800;

};

It's pretty similar to what Grimes posted, so you might have the same result.

Edited by Strikor

Share this post


Link to post
Share on other sites

Yeah, that's almost the exact same as the one I posted. The issue we are having is in the filler. I guess it just doesn't like that macros.

So CodeVision I suggest you either find a different/basic filler, or go through the one from Domination and take out the macros (so its a full "_box addWeaponCargo ["WhipCreamPie",9001]"

Share this post


Link to post
Share on other sites
;2007869']My bet is that you copy and pasted the Domination ammobox filler bit straight over' date=' which you can't do because of things defined in a file that was #include d. I do not know why you are having this problem, it worked just fine for me.

the ['] spawn is used to loop the filler so that every 600 seconds/10 minutes it clears the box then re-adds everything, keeping it "full".

Edit: Ok, now I see what you mean by the crate not filling. Let me work on that, might've missed something.

Edit2: Replaced the spawn with while {alive _box} do { , but now the game hangs up for 10 seconds and spams 100,000 lines in my RPT about the sleep at the end being a generic error. Anybody know why the error is occurring? It's just a sleep..

Well in the Domination mission I got the problem when I tried to put some conditions on the available weapons based on class...I suppose there's any number of ways I could have broken that script....

But at this point, the ammobox loads just fine. I even added the

"while {true} do {" prior to the clearing and reloading of the box. I set the timer to 20 seconds to test, but it doesn't refill the box.

Still this is progress...I'll keep plugging away at it.

Strikor, in your missions, have you had any issues refilling the box?

Share this post


Link to post
Share on other sites

Negative. In my experience they work even better than global ammo boxes. Do you have ArmA running with -showScriptErrors enabled? That can usually point you in the right direction, even if the error isn't particularly informative.

Share this post


Link to post
Share on other sites

Thanks for the tip, I am now, and will use this going forward.

I'm getting the same error as Grimes, and after reading around a bit on "sleep", I'm wondering if the problem is that the script is being "called" in the On Act field in the mission trigger. I am gathering that "sleep" can only be used on scripts executed with execVM and Spawn.

Since this refill is going to happen every 5-10 minutes, I'm not sure if execVM is the way I should go.

Maybe there's another way I could make the script "sleep", without using that command specifically. Either that, or I'll might need to run the ammo filler without using the Call function.

Share this post


Link to post
Share on other sites

Wait wait wait... So go back and tell us how you're executed all this and what you're trying to accomplish. Give the context. My main question is why are you "call"ing and not using execVM?

The point of [] spawn and while loops is to do just that. Loop. execVM IS the way you should go unless I'm missing something here.

Share this post


Link to post
Share on other sites

As always, upload what you have so far so we can see what you're talking about. :)

Share this post


Link to post
Share on other sites

Hrmm.....I'm not too sure how to upload...Do I need to use filefront or something? I don't have anything like that set up, but I can if it's essential.

Grimes, as far as executing, I used a trigger set for "Present" to call my ammobox spawn and fill script, which I called "i_client.sqf". The trigger is basically the same as the one you had in your JIP template. I even used the - call compile preprocessFileLineNumbers "ammobox.sqf"; - in the On Act field, which is what I saw in your mission.

Let me go back and read how to post code, and I'll post what I put in the i_client.sqf.

OK, let's see if this post works:


//Init file for client


//Uncomment Below for enable server check
//if (isServer) exitWith {};


_Type = (typeOf player);

// Class arrays
_Tml = ["US_Soldier_SL_EP1", "US_Soldier_TL_EP1", "US_Soldier_Officer_EP1", "US_Delta_Force_TL_EP1"];
_Med = ["US_Soldier_Medic_EP1", "US_Delta_Force_Medic_EP1"];
_Mng = ["US_Soldier_MG_EP1", "US_Soldier_AMG_EP1", "US_Delta_Force_AR_EP1", "US_Delta_Force_MG_EP1"];
_Grn = ["US_Soldier_AA_EP1", "US_Soldier_AT_EP1", "US_Soldier_AAT_EP1", "US_Soldier_HAT_EP1", "US_Soldier_AHAT_EP1", "US_Soldier_LAT_EP1", "US_Soldier_GL_EP1"];
_Snp = ["US_Soldier_Marksman_EP1", "US_Soldier_Sniper_EP1", "US_Soldier_SniperH_EP1", "US_Soldier_Sniper_NV_EP1", "US_Soldier_Spotter_EP1", "US_Delta_Force_Marksman_EP1"];
_Pil = ["US_Soldier_Pilot_EP1", "US_Pilot_Light_EP1"];
_Eng = ["US_Soldier_Engineer_EP1"];
_Crw = ["US_Soldier_Crew_EP1"];
_Rfl = ["US_Soldier_EP1", "US_Soldier_B_EP1", "US_Soldier_Light_EP1", "US_Delta_Force_EP1", "US_Delta_Force_Assault_EP1", "US_Delta_Force_M14_EP1", "US_Delta_Force_Night_EP1", "US_Delta_Force_SD_EP1"];

if (_this != player) exitWith {}; // exit all other clients.

//Ammobox Deployment

_m = "client_ammobox_pos";
_mpos = getMarkerPos _m;
_mdir = markerDir _m;

_box = "USVehicleBox" createVehicleLocal _mpos;
_box allowDamage false;
_box setDir _mdir;
_box setPos _mpos;
player reveal _box;
//player reveal _box;

#define __awc(wtype,wcount) _box addWeaponCargo [#wtype,wcount];
#define __amc(mtype,mcount) _box addMagazineCargo [#mtype,mcount];


while {alive _box} do {
clearMagazineCargo _box;
clearWeaponCargo _box;

//For All

//Pistols
__awc(M9,1)
__awc(M9SD,1)
__awc(Colt1911,1)
__awc(revolver_EP1,1)
__awc(revolver_gold_EP1,1)
__awc(glock17_EP1,1)
__awc(Sa61_EP1,1)
__awc(UZI_EP1,1)
__awc(UZI_SD_EP1,1)
__awc(M16A2,1)
//Rifles
__awc(LeeEnfield,1)
__awc(M4A1,1)
__awc(M4A3_CCO_EP1,1)
__awc(M14_EP1,1)
__awc(SCAR_L_CQC,1)
__awc(SCAR_L_CQC_Holo,1)
__awc(SCAR_L_STD_HOLO,1)
__awc(SCAR_L_CQC_CCO_SD,1)
__awc(SCAR_H_CQC_CCO,1)
__awc(SCAR_H_CQC_CCO_SD,1)
__awc(FN_FAL,1)
__awc(G36C_camo,1)
__awc(G36_C_SD_camo,1)
__awc(Sa58P_EP1,1)
__awc(Sa58V_EP1,1)
__awc(Sa58V_CCO_EP1,1)
__awc(SCAR_L_STD_Mk4CQT,1)
//Launchers
__awc(M136,1)
//Grenades
//__amc(HandGrenade_Stone,50)
__amc(HandGrenade_West,30)
__amc(Smokeshell,20)
__amc(Smokeshellred,20)
__amc(Smokeshellgreen,20)
__amc(SmokeShellYellow,20)
__amc(SmokeShellOrange,20)
__amc(SmokeShellPurple,50)
__amc(SmokeShellBlue,50)
__amc(FlareWhite_M203,20)
__amc(FlareGreen_M203,20)
__amc(FlareRed_M203,20)
__amc(FlareYellow_M203,20)
__amc(1Rnd_HE_M203,30)
__amc(6Rnd_FlareWhite_M203,20)
__amc(6Rnd_FlareGreen_M203,20)
__amc(6Rnd_FlareRed_M203,20)
__amc(6Rnd_FlareYellow_M203,20)
__amc(6Rnd_HE_M203,30)
__amc(6Rnd_Smoke_M203,20)
__amc(6Rnd_SmokeRed_M203,20)
__amc(6Rnd_SmokeGreen_M203,20)
__amc(6Rnd_SmokeYellow_M203,20)
__amc(1Rnd_Smoke_M203,20)
__amc(1Rnd_SmokeRed_M203,20)
__amc(1Rnd_SmokeGreen_M203,20)
__amc(1Rnd_SmokeYellow_M203,20)
//Ammo
__amc(30Rnd_9x19_MP5,30)
__amc(30Rnd_9x19_MP5SD,30)
__amc(7Rnd_45ACP_1911,30)
__amc(6Rnd_45ACP,50)
__amc(20Rnd_B_765x17_Ball,30)
__amc(10Rnd_B_765x17_Ball,50)
__amc(15Rnd_9x19_M9,30)
__amc(15Rnd_9x19_M9SD,30)
__amc(17Rnd_9x19_glock17,50)
__amc(20Rnd_556x45_Stanag,30)
__amc(30Rnd_556x45_Stanag,30)
__amc(30Rnd_556x45_StanagSD,30)
__amc(30Rnd_762x39_SA58,50)
__amc(20Rnd_762x51_FNFAL,30)
__amc(10x_303,50)
__amc(30Rnd_556x45_G36,30)
__amc(30Rnd_556x45_G36SD,30)
__amc(200Rnd_556x45_M249,30)
__amc(100Rnd_556x45_M249,50)
__amc(100Rnd_556x45_BetaCMag,30)
//__amc(8Rnd_B_Beneli_74Slug,50)
__amc(5Rnd_762x51_M24,6)
__amc(20Rnd_762x51_DMR,50)
__amc(10Rnd_127x99_M107,3)
__amc(20Rnd_762x51_B_SCAR,30)
__amc(20rnd_762x51_SB_SCAR,30)
__amc(100Rnd_762x51_M240,30)
__amc(M136,10)
__amc(Dragon_EP1,10)
__amc(MAAWS_HEAT,2)
__amc(MAAWS_HEDP,2)
__amc(Pipebomb,5)

__amc(Laserbatteries,20)
__amc(JAVELIN,1)
__amc(STINGER,2)
//__amc(30Rnd_545x39_AK,50)
//__amc(PG7V,3)
//__amc(PG7VR,3)
//__amc(PG7VL,3)
//__amc(100Rnd_762x54_PK,50)
//__amc(60Rnd_762x54_DT,50)
//__amc(75Rnd_545x39_RPK,50)
__amc(30Rnd_9x19_UZI,50)
__amc(30Rnd_9x19_UZI_SD,50)
//__amc(30Rnd_762x39_AK47,50)
//__amc(10Rnd_762x54_SVD,50)
//Other
__amc(IR_Strobe_Target,3)
__amc(IR_Strobe_Marker,3)
__amc(IRStrobe,3)
__awc(NVGoggles,1)
__awc(Binocular,1)

//For Team Leaders
if (_Type in _Tml) then {
//Rifles
__awc(M16A2GL,1)
__awc(M4A3_RCO_GL_EP1,1)
__awc(SCAR_L_STD_EGLM_RCO,1)
__awc(SCAR_L_CQC_EGLM_Holo,1)
__awc(M32_EP1,1)
__awc(SCAR_H_STD_EGLM_Spect,1)
__awc(FN_FAL_ANPVS4,1)
__awc(Sa58V_RCO_EP1,1)
__awc(G36A_camo,1)
__awc(G36K_camo,1)
__awc(SCAR_L_STD_EGLM_TWS,1)
//Launchers
__awc(M79_EP1,1)
__awc(Mk13_EP1,1)
__awc(M47Launcher_EP1,1)
__awc(MAAWS,1)
__awc(JAVELIN,1)
__awc(STINGER,1)
//Other
__awc(Binocular_Vector,1)
__awc(Laserdesignator,1)
};


//For Medics
if (_Type in _Med) then {
};

//For Auto Gunners
if (_Type in Mng) then {
//Machine Guns
__awc(MG36_camo,1)
__awc(Mk_48_DES_EP1,1)
__awc(m240_scoped_EP1,1)
__awc(M249_EP1,1)
__awc(M249_TWS_EP1,1)
__awc(M249_m145_EP1,1)
__awc(M60A4_EP1,1)
};

//For Grenadiers
if (_Type in _Grn) then {
//Launchers
__awc(M47Launcher_EP1,1)
__awc(MAAWS,1)
__awc(JAVELIN,1)
__awc(STINGER,1)
__awc(M79_EP1,1)
__awc(Mk13_EP1,1)
};

//For Pilots
if (_Type in _Pil) then {
};

//For Crewmen
if (_Type in _Crw) then {
};

//For Riflemen
if (_Type in _Rfl) then {
};

//For Snipers
if (_Type in _Snp) then {
//Rifles
__awc(SCAR_H_LNG_Sniper,1)
__awc(SCAR_H_LNG_Sniper_SD,1)
__awc(SCAR_H_STD_TWS_SD,1)
__awc(M24_des_EP1,1)
__awc(M107,1)
__awc(m107_TWS_EP1,1)
__awc(M110_TWS_EP1,1)
__awc(M110_NVG_EP1,1)
};

//For Engineers
if (_Type in _Eng) then {
//Mine
__amc(Mine,10)
};
sleep 40;
};
[/Code]

[color=Silver]

[size=1]---------- Post added at 08:48 PM ---------- Previous post was at 08:39 PM ----------[/size]

[/color]BTW, the sleep timer is just set to a low value so that I can test the refill.

Edited by CodeVision
posting code

Share this post


Link to post
Share on other sites

Oh wow, you're right. I'm sorry, didn't realize I had "call" in there.

Change the OnAct of the trigger to

nul = server execVM "ammobox.sqf"; 

Then make a Game Logic object and name it server. Done.

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  

×