Jump to content
Sign in to follow this  
fortun

Making script work in Multiplayer

Recommended Posts

Hi! Im using Focks guide, but he has still not yet given out the multiplayer part.

So since im doing a CO-OP Mission, i would like to know how i can get scripts to work on both players.

For example.

Its me (Name in editor: Frank)

and my Co-op Friend (Name in editor: David)

So, i did a simple script where it shows the nearest enemy of the player.

Test.sqf

_me = player;

while {true} do
{

sleep 1;
_en = player findnearestenemy player;
player dotarget _en;
};

Then i have in the init

execVM "test.sqf";

Its working perfectly, of course for me.

But, its probably not at all going to work if we play togheter online because i want "Player" to use it, and since we are two players, how would it know who is the one and also check the separate players for the nearest enemy and show it?

So, if i want the script to find nearest enemy player for "Frank" and for "David", separatly and show it, how could i do that in the best way?

I guess i just could do a repeat of that script and just change name in each of them to "Frank" (instead of player) and to "David". But that can't really be the

right way to do it, right? Cause if i have like 50 persons, it would be a hell to make separate scripts to all of them ^^

I just started scripting yesterday, so it may not look good. But i am doing this for learning. And i think there are others who maybe wants to know too.

Thanks!

Share this post


Link to post
Share on other sites
I just started scripting yesterday, so it may not look good. But i am doing this for learning. And i think there are others who maybe wants to know too.
Im using Focks guide, but he has still not yet given out the multiplayer part.

Correct i havent got round to the multiplayer scripting yet - time is a killer at the mo, but since you have only been scripting for a day or so - i suggest jumping into MP just now is a bit too eager. Its a little more complex than first thought.

for what you have written, the script can run on all computers at start - including the server - so first thing would be to stop the server needing to run the script because it is not a player and the objective to find nearest enemy is not necessary. Therefore you would have !isserver boolean check...

With this in place when the server runs this script it will simply not run it - however - those clients on a dedicated server (not host) would run that script. Player can be a funny old command. Yes every player is a player, but when the game is running on a MP server- the player can change. Thus the easiest way is to call that one script from each init of the player (for basic level of scripting and does not require the !isserver check). so now you have one script - that can be accessed by many - however you want to get rid of the player and replace with the player's(client) object that is calling the script - (something like this in players init - dude = [] execVm "detect.sqf";)

detect.sqf


_me = _this;  //for a basic understanding - _this is the player calling the script

while {true} do
{

_myGroup = group _me; 
_myNearestEnemy = (units _myGroup select 0) findNearestEnemy _me ; 
hint _myNearestEnemy;

sleep 1;
};


Unfortunately i havent tested the above and its a quick example. Havent done scripting for a while and a bit rusty - but hopefully you will get the idea. There are many ways round and with the player command, much of which folks will guide you on this forum. Yet this is fairly basic stuff and covering the basics will make the MP stuff a little easier for you in the long run... hosting and using a dedicated server is another issue to get over as well - Trial and error works but it does take a while. Hence why i suggest the basics first and understanding efficiency and necessity when coding. keep plugging away and goodluck

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  

×