Jump to content
Sign in to follow this  
kvntvan

How to make your mission MP safe?

Recommended Posts

So I recently released my first few missions for a group I joined, but it turns out I had broken most of them with my poor coding. My triggers would activate in singleplayer just fine but in MP they seem to activate once per player. So a simple tank spawning script ended up spawning 25 t-72s and a script I was using to spawn flares was spawning more flares then stars in the sky. And my players inventories were refreshing everytime a player joined, supposedly because I set player load outs in their init box and not the init.sqf. So what  I was wondering was if you guys had tips or a checklist for making a mission MP safe? And how can I possibly fix this issue with my triggers spawning units for every player?

 

Heres the example of the code I'm using for the sky flares. Its activated by a trigger that checks for Blufor players

 

On trigger Act

startFlares = 1; null = [40, 65, 25, 200, 25, "GREEN", -9, platform1] execVM "skyFlares.sqf";

Skyflares.sqf

if (isserver) then {

// skyFlares.sqf
// startFlares = 1; null = [<max distance>, <base delay>, <max added delay>, <base height>, <random added or subtracted height>, <color>, <speed (must be negative)>, <object pos>] execVM "skyFlares.sqf";
 
// declare a few variables we need and make _sign randomly negative
_sign = 1;
_random = false;
if (floor random 10 > 4) then { _sign = -1 };
_flareArray = ["WHITE", "RED", "GREEN", "YELLOW", "IR"];
 
// organize our arguments
_flareDist = _this select 0;
_delay = _this select 1;
_delayRandom = _this select 2;
_flareHeight = _this select 3;
_flareHeightRandom = _this select 4;
_flareType = _this select 5;
_flareSpeed = _this select 6;
_flarePos = _this select 7;
 
// create loop for spawning flares
while { startFlares == 1 } do
{
        // check if random
        if (_flareType == "RANDOM") then { _flareType = _flareArray call BIS_fnc_selectRandom; _random = true };
        // assign colors
        switch (_flareType) do
        {
                case "WHITE":   { _flareType = "F_40mm_White" };
                case "RED":     { _flareType = "F_40mm_Red" };
                case "GREEN":   { _flareType = "F_40mm_Green" };
                case "YELLOW":  { _flareType = "F_40mm_Yellow" };
                case "IR":      { _flareType = "F_40mm_CIR" };
        };
        // get a random spot around the target
        _pos = [_flarePos, random _flareDist, random 360] call BIS_fnc_relPos;
        _pos = [_pos select 0, _pos select 1, _flareHeight + (random _flareHeightRandom * _sign)];
        // make the flare at that spot
        _flare = _flareType createVehicle _pos;
        // set its speed
        _flare setVelocity [0, 0, _flareSpeed];
        // delay plus random delay
        sleep _delay + random _delayRandom;
        // reset random if it was there before
        if (_random) then { _flareType = "RANDOM" };
};

I added an "ifserver" section in the beginning because one of my group members told me it might fix the issue, but alas it did not. Thanks for any help you can offer!

Share this post


Link to post
Share on other sites

So I recently released my first few missions for a group I joined, but it turns out I had broken most of them with my poor coding. My triggers would activate in singleplayer just fine but in MP they seem to activate once per player. So a simple tank spawning script ended up spawning 25 t-72s

 

 

Know that pain, guess everyone started like that.

 

A great resource of information is KK's blog.

Read his multiplayer scripting guides/tutorials and try to understand where things are executed.

 

 

About your flare trigger issue.

Is your trigger set to activate repeatedly?

Share this post


Link to post
Share on other sites

 

About your flare trigger issue.

Is your trigger set to activate repeatedly?

Yes they are actually! hopefully that is the issue but I can't test it because no one from my server is up at the moment! Thanks!

Share this post


Link to post
Share on other sites

The issue here is simple.

 

The isServer check doesn't work, because the script will still run everytime on the server when the trigger is activated.

In order to fix that, you'd need to define a global variable, and prevent the script execution if this variable is known.

 

 

So a simple tank spawning script ended up spawning 25 t-72s

 

 

How do you execute the script, and where?

Share this post


Link to post
Share on other sites

The issue here is simple.

 

The isServer check doesn't work, because the script will still run everytime on the server when the trigger is activated.

In order to fix that, you'd need to define a global variable, and prevent the script execution if this variable is known.

 

 

 

How do you execute the script, and where?

hi there! your suggestion fixed the flares, such an obvious issue I'm an idiot!

 

As for the tanks, I "fixed" that by replacing the script entirely with the Enemy Occupation System's "bastion" zones.

 

BUT it was pretty much this script (replacing the MI-24 with a T-72 classname) titled "reinforce.sqf" or whatever, called by a Blufor present trigger, I found this code on a youtube tutorial and I used it to spawn stuff in other missions (that I'm realizing I'll need to fix too :( )

_mygroup = [getmarkerpos "mgs1", EAST, ["RHS_Mi24P_CAS_vdv"],[],[],[],[],[],180] call BIS_fnc_spawnGroup;
_wp1 = _mygroup addwaypoint [getmarkerpos "wp1",0];
	_wp1 setWaypointType "MOVE"; 
	_wp1 setWaypointSpeed "LIMITED"; 
	_wp1 setWaypointBehaviour "AWARE"; 
_wp2 = _mygroup addwaypoint [getmarkerpos "wp2",0];
	_wp2 setWaypointType "SAD"; 
	_wp2 setWaypointSpeed "FULL"; 
	_wp2 setWaypointBehaviour "AWARE"; 

Share this post


Link to post
Share on other sites

To make your mission MP safe, its prudent to develop it in MP :)

 

People developing MP missions from the editor/preview iterations, tend to encounter the MP issues since they are developing in SP setting.

 

Get a TADST virtual dedicated server and connect to your session as a client. Also learn how to effectively execute code in debug console, since its much faster iteration time. Don't have to repack PBO/preview/etc just to fix a small issue. Once your debug console-tested code is roughly done, then its no trouble to paste it into a file and have the mission compile it.

Share this post


Link to post
Share on other sites

 

hi there! your suggestion fixed the flares, such an obvious issue I'm an idiot!

 

As for the tanks, I "fixed" that by replacing the script entirely with the Enemy Occupation System's "bastion" zones.

 

BUT it was pretty much this script (replacing the MI-24 with a T-72 classname) titled "reinforce.sqf" or whatever, called by a Blufor present trigger, I found this code on a youtube tutorial and I used it to spawn stuff in other missions (that I'm realizing I'll need to fix too :( )

_mygroup = [getmarkerpos "mgs1", EAST, ["RHS_Mi24P_CAS_vdv"],[],[],[],[],[],180] call BIS_fnc_spawnGroup;
_wp1 = _mygroup addwaypoint [getmarkerpos "wp1",0];
	_wp1 setWaypointType "MOVE"; 
	_wp1 setWaypointSpeed "LIMITED"; 
	_wp1 setWaypointBehaviour "AWARE"; 
_wp2 = _mygroup addwaypoint [getmarkerpos "wp2",0];
	_wp2 setWaypointType "SAD"; 
	_wp2 setWaypointSpeed "FULL"; 
	_wp2 setWaypointBehaviour "AWARE"; 

 

Well that script is also missing the isServer or a similar check for locality.

 

My tip, never use a script posted somewhere unless you understand what it does. You'll never get the hang of it that way.

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  

×