Jump to content
Sign in to follow this  
juxie

client-server multiplayer problem

Recommended Posts

I am writing a multiplayer mission

Added a stop action to a vehicle controlled by AI

When activating stop action from client machine, vehicle doesn't listen to command such as "vehicle stop true" or "(driver  vehicle) action ["eject", vehicle]"

Any idea what's this problem?

Please help thanks

Share this post


Link to post
Share on other sites

How do you activate the stop action? From a script?? Via a Radio Trigger???

Share this post


Link to post
Share on other sites

Here's the potential problem. For a command to work on a unit it must be executed on the machine on which the unit is local.  For enemy AI this would be the server. For friendly AI not under a player's command this would be the server. For friendly AI under a player's command,  this would be the player's machine.  The results of an addAction are only executed on the player's machine.  That is, when the player uses the added action, the  stop command only runs on the player's machine not on the server.

If you make sure the command is executed on all clients, using a trigger, for example, it should work. On machines for which the unit is not local the command will be ignored.  This is true in general for unit commands such as stop, move, target etc.

Another issue can be that units do not obey direct commands if they already have waypoints which were placed in the editor. They might obey the command for a split second, but then ignore it.

If the unit is in a land vehicle and you want it to stop the most effective way is to setFuel 0.  This is a real kludge, but it works.

So here is my advice-

In your init.sqs define a variable:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">stoptheai = FALSE

In your addaction:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addAction ["Stop dammit!","stoptheai.sqs"]

Make the script stoptheai.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">stoptheai = TRUE

publicVariable "stoptheai"

exit

In the editor add a trigger with the condition:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">stoptheai

And in the activation put the code you want to use to stop the ai, for example:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">doStop unitname; stoptheai = FALSE; publicvariable "stoptheai"

This is the most simple way.  One boolean (TRUE/FALSE) variable and trigger for each action. You could be more sophisticated and use one trigger for all actions and then have the trigger run a script that checks which action to apply.

Share this post


Link to post
Share on other sites

I didn't even know you could set variables using the addAction. I know that you can start a script that sets a variable to true/false and then broadcast it with publicVariable, but I've never seen it done directly in the addAction-syntax like your example. Is this method tested? In that case it would make a lot of things more easy for me.

Share this post


Link to post
Share on other sites
I didn't even know you could set variables using the addAction. I know that you can start a script that sets a variable to true/false and then broadcast it with publicVariable, but I've never seen it done directly in the addAction-syntax like your example. Is this method tested? In that case it would make a lot of things more easy for me.

Nope, it doesn't work like that. OFP will drop an error message like

Quote[/b] ]Script 'stoptheai = TRUE; publicVariable "stoptheai"' not found

Share this post


Link to post
Share on other sites

Ack.. I keep screwing up!  Have edited my above example to work properly with the addition of an intermediary script.

Share this post


Link to post
Share on other sites
Here's the potential problem. For a command to work on a unit it must be executed on the machine on which the unit is local.  For enemy AI this would be the server. For friendly AI not under a player's command this would be the server. For friendly AI under a player's command,  this would be the player's machine.  The results of an addAction are only executed on the player's machine.  That is, when the player uses the added action, the  stop command only runs on the player's machine not on the server.

If you make sure the command is executed on all clients, using a trigger, for example, it should work. On machines for which the unit is not local the command will be ignored.  This is true in general for unit commands such as stop, move, target etc.

Another issue can be that units do not obey direct commands if they already have waypoints which were placed in the editor. They might obey the command for a split second, but then ignore it.

If the unit is in a land vehicle and you want it to stop the most effective way is to setFuel 0.  This is a real kludge, but it works.

So here is my advice-

In your init.sqs define a variable:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">stoptheai = FALSE

In your addaction:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addAction ["Stop dammit!","stoptheai.sqs"]

Make the script stoptheai.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">stoptheai = TRUE

publicVariable "stoptheai"

exit

In the editor add a trigger with the condition:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">stoptheai

And in the activation put the code you want to use to stop the ai, for example:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">doStop unitname; stoptheai = FALSE; publicvariable "stoptheai"

This is the most simple way.  One boolean (TRUE/FALSE) variable and trigger for each action. You could be more sophisticated and use one trigger for all actions and then have the trigger run a script that checks which action to apply.

It seems to work only for one vehicle if the action is executed concurrently on 2 machines

How can I solve this?

Share this post


Link to post
Share on other sites

In the final trigger yoy repeat the command for both vehicles:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

doStop unit1; doStop unit2; stoptheai = FALSE; publicvariable "stoptheai"

Replace unit1 and unit2 with the names of your vehicles. That should stop both of them.

Share this post


Link to post
Share on other sites
In the final trigger yoy repeat the command for both vehicles:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

doStop unit1; doStop unit2; stoptheai = FALSE; publicvariable "stoptheai"

Replace unit1 and unit2 with the names of your vehicles. That should stop both of them.

Sorry you seem confused by me

What I wanted is to stop the vehicle when the stop action attached to it is activated

That means if there are 2 vehicles, there are 2 actions, one attached to each

Then if 2 users activated the actions, 2 will stop, if only one is activated, only one is stopped

Share this post


Link to post
Share on other sites

Then create two variables stoptheai1 and stoptheai2. Just double the procedure. Make two scripts stoptheai1.sqs and stoptheai2.sqs . addAction ["Stop","stoptheai1.sqs"] to one vehicle, addAction ["Stop","stoptheai2.sqs"] to the other. Make two triggers, one that activates when stoptheai1 is TRUE; the other activates when stoptheai1 is TRUE. The first trigger on activation: doStop vehicle1; stoptheai1 = FALSE; publicvariable "stoptheai1" . The second trigger on activation: doStop vehicle2; stoptheai1 = FALSE; publicvariable "stoptheai2."

Although this is not a very elegant solution it is straight forward, and not to sound too critical but it is an obvious extension of the method I first posted.

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  

×