Jump to content

Recommended Posts

Hi guys, I've been steadily producing terrible code and making it less terrible as I go. I'm still having problems recognizing locality of certain commands, and when/who needs to execute the specific code. Thanks for your help, as I continue to produce horrible scripts! :sorry:

What I'm trying to do
1) Players use an addaction to start an event (working)
2) Players are transported into a plane (working)

a) the plane begins to get shot down (crash) (working)
b) some radio chatter (text and sound), and music plays (only working for the player that triggered the action ("player1"))
c) some explosion happens and an engine fire starts (working)
d) the plane is forced downward (working kind of brute force though)
3) Players encounter another explosion at low altitude (working)
a) players are knocked unconscious (only working for "player1")
b) random clutter is spawned based on player count (working)
c) players are stripped of random items and those items are placed in some boxes (half working only player1 loses items)
3) Players awaken to a crash site (working again only player1 was unconscious) 
a) music switch to shorter track (working only for player1)
b) static engine noise plays from the wreck (working for playe1 only)

I have also noticed that for "player1" the events progress linearly through the script, but for the other players that is not necessarily the case. I was poking around and it sounds to be scheduler related, but I'm not quite understanding how to work around that. Ideally all of the events in my script would happen synchronously and in the order they are shown in the script. Any help in pointing me where to go from here is much appreciated, script and description.ext to follow.

description.ext
 

  Reveal hidden contents



Crash.sqf
 

  Reveal hidden contents

 

Edited by Cockheaven
speeling

Share this post


Link to post
Share on other sites

If you want to script for multiplayer, start with some basics.

Pay attention from arguments AND effects of EACH command you're using.

If I'm right, I don't understand why, any players can "addAction" this disaster. The fact is this code will run a local code from this "winner" and all the local effects will stay on his PC. You need to remoteExec:

- all EL commands/functions (you'll know what I mean after reading the link) to make these effects global (say3D is a perfect example)

- but also all AL functions for applying them on the right objects' locality (you run locally a code on the "winner"'s PC, but the object is on server), typically setVelocity you want to apply on plane. This plane is on server if no played pilot, on pilot's PC if pilot (driver) is played.

 

Fortunately some commands don't need that (setPosATL is AG EG so, never mind where you'll fire from, all players get the right behavior).

 

So, you have the guideline. I wouldn't script that from an addAction but somewhere on server as result of a trigger (server only).

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Thanks again @pierremgi, I have Everything working except for one section and I'm thinking i need to treat this as a function and remote exec the whole thing. Here's the snip.

 

  Reveal hidden contents

So If I'm understanding correctly, what's happening is the outside foreach is running on the server, and it runs once per player. However since it runs on the server the nested foreach containing "removeMagazineGlobal" doesn't run on the player that the outside foreach is run on, how do I accomplish this, Can i define _X = _CK_CurrentPlayer and pass that to the nested foreach, well that's what I'm going to try. Otherwise i was thinking that I make this a function and run the function on each client? But IDK how to do that, at least how to pass params etc...

Share this post


Link to post
Share on other sites

Okay, so i spent some time trying a few things but no success. 

First up I created a function, or I thought I did....
initserver.sqf
 

  Reveal hidden contents

then somewhere in the events chain

remotexec ["fnc_CK_STRIP",0];

didn't work, so i tried 

remotexeccall ["fnc_CK_STRIP",0];

didn't work either...

Second thing I tried was putting it in a script and calling the script

CK_STRIP.sqf
 

  Reveal hidden contents

then somewhere in the events chain

remotexec ["CK_STRIP.sqf",0];

didn't work, so i tried 

remotexeccall ["CK_STRIP.sqf",0];

didn't work either...

So I was rolling on this train of finally getting locality, and now I've run into a locality blockade... I can run that code locally via debug console and it does what I want it to do. What method am I supposed to use to accomplish this? That code needs to run on each client, I thought remotexec did that, am i using it wrong, is there some other syntax/command to use?
 

Share this post


Link to post
Share on other sites

Consider the server as a good place to spawn AIs, and trigger "events" (wide meaning). So, all local objects (edited crates, vehicles (AI manned or empty, AIs) are managed here. On the other hand, players are local on their PC, but also their subordinates and driven vehicle... I gave you the link for that. Locality can change along with the status (the owner) of the AIs/vehicles...

The addAction always run a code on the "caller" PC, so, this is a good reason to remoteExec on the right place some code for a remote player/AI/object, or for sharing a result of this code.

So, you need to ever pay attention for SYNTAX command AND ARGUMENTS locality AND EFFECTS locality.

BI created, for simplification, some global commands like addItemCargoGlobal. This command (AG EG) is supposed to run from a PC (server or client,) but should never be remoteExecuted everywhere! It's global.

As rule of thumb:

* AG EG  never remoteExec, run as is,

* SE  run it on server only (remoteExec to 2 if necessary)

* AL EG run it on the right place (where local is. i.e. the command must apply to a local object), or remoteExec it on the right place

* AG EL will run fine locally, but you can broadcast it with a remoteExecution and choose the clients. (0 = everywhere: server + clients)

* AL EL  double pay attention for locality of argument and broadcast if needed.

 

Don't mix forEach and locality. forEach is a tool to avoid repeating inner code. That's all.

So, if you want to apply a loadout at start, whatever the unit is played or not, the initServer.sqf is fine. Use the global commands, remoteExec those who are not EG, and do not remoteExec your whole function!

 

Share this post


Link to post
Share on other sites

Here is how I would do it, in conceptual pseudo code:

 

On server:

 

Main script. Does everything it can, and calls out ”events” for stuff that need to be handled locally, for clients to ”listen” to.

 

If AI is piloting the plane in its own group then the plane is probably local to the server (let’s assume that).

 



	TakeOff;



	PlaneTakesHitAndStalls;



	SendEvent(OnPlaneStallBegin);



	EngineExplosion;



	PlaneLoosesHeight;



	PlayAnotherExplosion;



	SendEvent(OnSecondExplosion);



	[/CODE]


 

On client(s):

 


	Function OnPlaneStallBegin {


	    Play radio chattering;


	}


	 


	Function OnSecondExplosion {


	    Make player unconcious;


	    RandomClutter;


	    StripOfItems;


	    AllThatRemains;


	}


	[/CODE]


 

With this ”architecture” you solve all issues with timings and keeps concerns apart. I.e. the server will do its thing, and the clients align, and the code will be relatively easy to maintain.

 

EDIT: Sorry for the formatting. I don’t know why it happens - but it’s when I use my smart phone.

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

×