Jump to content
Sign in to follow this  
Bankler

Script not running in multiplayer

Recommended Posts

Disclaimer. First post. Apology if I haven't spent enough effort searching for the answer on my own. I tried though.

I have problems with a script not running unless the player hosting the server triggers it.

The goal is to have a group of four guys (officer1, officer2...) join the leader of group alpha or bravo, whoever gets within six meters of them. Along with this join, some other things happen, like task status updates and stuff, so I put it all in a script.

Units: alpha_leader, bravo_leader, officer1, officer2, officer3, officer4.

In alpha_leader and bravo_leader respectively I have this in the init field:

alpha = group this;

bravo = group this;

Trigger:

Activation:

None

Condition:

(alpha_leader distance officer1 < 6) or (bravo_leader distance officer1 < 6)

On Act:

_Handle = player execVM "join.sqf";

join.sqf

hint "script is running";

//Check whoever was nearest.
dist_alpha = alpha_leader distance officer1;
dist_bravo = bravo_leader distance officer1;

//Make the officers join the nearest group.
if (dist_alpha < dist_bravo) then{
hint "alpha was closest";
[officer1, officer2, officer3, officer4] join alpha; 
}
else{
hint "bravo was closest";
[officer1, officer2, officer3, officer4] join bravo;  
};

//Update task stuff.
tskObj1 setTaskState "SUCCEEDED"; 
taskhint ["Task succeeded:\nGet to the downed C-130 crew", [0, 1, 0, 1], "taskDone"];
player setCurrentTask tskObj2;

If the host is playing alpha or bravo leader, the four officers joins the group. If any other client tries, it seems the script is not running at all (the first hint line is not shown at least). I don't know if it's a syntax error or if I need to understand the whole server/client scripting issue better.

I'd appreciate your help. Thanks in advance!

//Bankler

Share this post


Link to post
Share on other sites

Try with AddAction:

Create a Trigger:

Condition:

player distance officer1 < 3

Activation:

Action_join = officer1 addAction ["Join","join.sqf"];

Deactivation:

officer1 removeAction Action_join;

Join.sqf:

[officer1, officer2, officer3, officer4] join (group player);

officer1 removeAction Action_join;

Share this post


Link to post
Share on other sites

Thanks, Giallustio. Unfortunately I didn't get it to work. Maybe I'm missing something.

I removed my own trigger and and replaced my script with yours. I kept the units without changing anything. Now nothing at all happens when you walk up to them, not even if you're the host. I noticed "player distance officer1 < 3" in condition. Is "player" a reserved variable meaning "any player"? Or do I need to set "player" as the name for the unit?

EDIT: "Or do I need to set "player" as the name for the unit?" ... Apparently, that was not even possible. ;)

Edited by Bankler

Share this post


Link to post
Share on other sites

I'm not too familiar with server-side stuff either, but a lot of scripts use an isServer check which solves a lot of problems since all the stuff in the script would only be executed once on the server, and since the server is, well... the server :p, all clients connected to it should get the info too. And that way everything should stay in sync (though I might be completely off here).

Might give it a try:

if (isServer) then
{
hint "script is running";

//Check whoever was nearest.
dist_alpha = alpha_leader distance officer1;
dist_bravo = bravo_leader distance officer1;

//Make the officers join the nearest group.
if (dist_alpha < dist_bravo) then{
hint "alpha was closest";
[officer1, officer2, officer3, officer4] join alpha; 
}
else{
hint "bravo was closest";
[officer1, officer2, officer3, officer4] join bravo;  
};

//Update task stuff.
tskObj1 setTaskState "SUCCEEDED"; 
taskhint ["Task succeeded:\nGet to the downed C-130 crew", [0, 1, 0, 1], "taskDone"];
player setCurrentTask tskObj2;
}; //don't forget this little bracket

Share this post


Link to post
Share on other sites

Thanks for the input! I appreciate it.

But an isServer check here, could that possibly solve it? I mean, The script isn't running at all for anyone but the server, and I think this is the very problem here. If we make an isServer-check, we would REALLY make sure nobody but the server can trigger the join-event, wouldn't we? With that said, it's probably true that the problem is indeed related to something like this. But I don't know.

Share this post


Link to post
Share on other sites

Still no go. The trigger is activated when I walk up towards the officers. But the script doesn't run. Regardless of singleplayer or multiplayer.

Share this post


Link to post
Share on other sites

See if the problem is with the trigger firing or the script itself. Using your original example, change the On Act of the trigger to just a simple hint; don't actually run the script. Then repeat the experiment and see if the hint works. From there, the solution should be easy to figure out.

Share this post


Link to post
Share on other sites

Okay, I went back to the original. I changed the On Act on the trigger to:

hint "trigger works";

The trigger works for me and the other client as well (ie the hint pops up for both of us). So the problem seems to be that the script doesn't get called for some reason. Because in the first row of the script I have

hint "script is running";

and that never happens.

Share this post


Link to post
Share on other sites

Now it's just a process of elimination.

First, the way you're calling the script is odd. I don't know if this is actually causing a problem, but you shouldn't use local variables (variables that start with an underscore like "_Handle") in a trigger field. Furthermore, there is no reason to pass "player" to the script. Change your script call in the On Act field to the following:

nul = [] execVM "join.sqf"

If the "script is running" hint still doesn't show up when the host isn't a leader, try commenting out (just add "//" to the beginning of a line) different parts of the script to see if anything is causing a problem (I would start with the task stuff at the bottom -- just comment all of that out).

---------- Post added at 08:13 PM ---------- Previous post was at 08:11 PM ----------

Also, how are you naming these units? Are they all named in the editor's name field, or were some of them created using scripting?

Edited by ST_Dux

Share this post


Link to post
Share on other sites

Problem is now solved. I finally worked it out. There were a couple of problems.

1. At one point, the generated mission file went file protected because I was running two clients on the same computer. This made the changes not reflect in the mp mission test and made me somewhat confused. Sorry for that... Dumb mistake.

2. In my triggers and my script, I assumed that both alpha_leader and bravo_leader would always exist. However, when I tested the mission in MP, sometimes I disabled all the AI and only picked one of the two leaders. When (in my trigger and my script) I tried to compare distances to an object that didn't exist, the trigger/script didn't work at all. When I did my tests, I sometimes had these two particular units selected and sometimes not, which led to the trigger work sometimes and sometimes not (and I didn't realize until now...).

Solution:

I added two "are you close to officer1?" triggers instead of one. One for each leader.

I changed the script so it handles if one of the leaders was not chosen in the unit selection screen in the lobby, using the isnil thingy. The script isn't that elegant really, but gets the job done.

//Assume that both leaders exist.
_was_alone = false;

//Check if only one of the leaders exists.
if ((!(isnil "alpha_leader")) && (isnil "bravo_leader")) then{
[officer1, officer2, officer3, officer4] join alpha; 
_was_alone = true;
};
if ((!(isnil "bravo_leader")) && (isnil "alpha_leader")) then{
[officer1, officer2, officer3, officer4] join bravo; 
_was_alone = true;
};

//If both are alive, determine who is closest.
if (!_was_alone) then{
//Check whoever was nearest.
dist_alpha = alpha_leader distance officer1;
dist_bravo = bravo_leader distance officer1;

//Make the officers join the nearest group.
if (dist_alpha < dist_bravo) then{
	[officer1, officer2, officer3, officer4] join alpha; 
}
else{
	[officer1, officer2, officer3, officer4] join bravo;  
};
};

//Update task stuff.
tskObj1 setTaskState "SUCCEEDED"; 
taskhint ["Task succeeded:\nGet to the downed C-130 crew", [0, 1, 0, 1], "taskDone"];
player setCurrentTask tskObj2;

ST_Dux, Giallustio, NGagedFX>> THANKS A LOT FOR YOU HELP! You totally pushed me in the right direction to discover my mistakes. :bounce3:

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  

×