Home   Help Search Login Register  

Author Topic: Script Issue on Dedicated Server  (Read 12149 times)

0 Members and 1 Guest are viewing this topic.

Offline Nixer6

  • Members
  • *
Re: Script Issue on Dedicated Server
« Reply #45 on: 07 Jan 2008, 06:38:57 »
Case and I have been discussing this on another board and in PM.

I have a nice little script that works just perfect in SP and in MP testing. But...........

It will not work on a dedicated server! I have a few map click scripts and none of them work on a dedicated server.  :no:

Went looking at the biki, found this example;

This is how you do it in a .sqf file:

Code: [Select]
onmapsingleclick "[_pos, _units, _shift, _alt] execvm ""mapclick.sqf""; true";
So I made a two super simple scripts to test it.

A player, a radio alpha trigger that execs the first script, a guy named airboss who sidechats telling you to click on the map where the helo goes, a LB named helo and an empty marker named "csarIP".

first script called by the radio trigger:

Code: [Select]
airboss sidechat "click on the map where you want the helo to move to";
sleep .01;
onmapsingleclick "[_pos, _units, _shift, _alt] execvm ""mapclick.sqf""; true";

the second script called mapclick.sqf:

Code: [Select]
_pos = [0,0];
_pos = _this select 0;
OnMapSingleClick "";

sleep .005;

"csarIP" setMarkertype "marker";
"csarIP" setMarkerPos _pos;
sleep 1;
helo domove (getMarkerPos "csarIP");

The marker moves to where I click on the map. But on a dedi the helo won't budge! And I am not even telling it to move to _pos, I am telling it to move to a markerPos.

I mean what's up here? It works perfect in Sp and MP except on a dedi.  ???
Why do I have to be a Rocket Scientist to make a good mission?

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Script Issue on Dedicated Server
« Reply #46 on: 07 Jan 2008, 15:44:48 »
The issue is that in SP (and for the host in non-dedicated MP) the AI helo will always be local to the player's machine, but this is never true in dedicated MP server (or everyone except the host in non-dedicated MP). The command to doMove will be ignored unless the vehicle being given the order is local to the player. What you need to do is request the server to do the move if the player is remote to the server.

Need to accept requests to move the helo on the server (used when a non-host makes the request with a non-dedicated MP server or any player with a dedicated MP server):
Code: (init.sqf) [Select]
if (isServer) then
{
    "moveHeloTo" addPublicVariableEventHandler {
        _pos = _this select 1;
        helo domove _pos;
    };
};

There is no reason to initially define _pos to [0,0] since you will set it immediately after. If you want to define it as a local variable, just use private. I assume you added the sleeps thinking they may help (they often do), but they shouldn't have an effect on the script. Add them back in if you wanted a delay for effect, rather than to "nudge" the script towards working properly ;P
Code: (mapclick.sqf) [Select]
private "_pos";
_pos = _this select 0;
OnMapSingleClick "";

"csarIP" setMarkertype "marker";
"csarIP" setMarkerPos _pos;

if (local helo) then
{
    // In case we are SP or host on non-dedicated MP
    helo domove _pos;
}
else
{
    // Request the server to do the move from a remote player.
    moveHeloTo = _pos;
    publicVariable "moveHeloTo";
};

(code examples are untested, but I'm sure you can sort them out if there are problems. I also forgot to mention that this solution REQUIRES ArmA 1.09, though you could do something more complex in 1.08 if you really want to  :weeping:).
« Last Edit: 07 Jan 2008, 15:46:32 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Nixer6

  • Members
  • *
Re: Script Issue on Dedicated Server
« Reply #47 on: 07 Jan 2008, 17:40:05 »
Thanks Spooner will test it out later today and get back with the results.
Why do I have to be a Rocket Scientist to make a good mission?

Offline Case

  • Members
  • *
Re: Script Issue on Dedicated Server
« Reply #48 on: 07 Jan 2008, 23:35:58 »
I just finished testing your samples Spooner, and this works properly.

I will start to use this process to try to fix my MP mission.

Much appreciated!!


Offline Case

  • Members
  • *
Re: Script Issue on Dedicated Server
« Reply #49 on: 09 Jan 2008, 21:39:41 »
So,

I have started converting my mission over from SQS to SQF and have started to implement chopper movement using Spooner's suggestion.

I have the heli moving properly on dedi now.

My problem now is other commands to the chopper.

Do I have to create an addPublicVariableEventHandler for each type of action the heli will take?

For example, to do my insertion, I have these commands sent to the heli:

-  flyinheight
-  setspeedmode
-  land

What I am seeing happen now on dedi is the heli will fly to location clicked on the map, but just stay there at altitude.

It doesn't seem to get the following command which tells it to land and unload the passengers.  Again, this works on non-dedi server.

If I need to just create addPublicVariableEventHandler for each of the above actions, please let me know, if there is another way to do this, again, I am all ears.

I guess my question is, do you only need to use addPublicVariableEventHandler when using onMapSingleClick, or is it needed for any AI unit movement?


See below for code snippet

Code: [Select]

if (local MH6_1) then
{
    // In case we are SP or host on non-dedicated MP
    driver MH6_1 flyinheight 50;
MH6_1 domove _pos;
driver MH6_1 setspeedMode "Full";
mh6_1 sidechat format ["Driver flying non-dedi: %1", getpos AlphaTarget];
}
else
{
    // Request the server to do the move from a remote player.
    moveAlphaHeloTo = _pos;
    publicVariable "moveAlphaHeloTo";
};

mh6_1 sidechat "INSIDE alphainsertion_3";


while {MH6_1 distance _pos > 500} do
{
mh6_1 sidechat format ["Distance: %1", MH6_1 distance _pos];
sleep 1.0;
};

//#Approach
MH6_1 SetSpeedMode "Limited";
MH6_1 sidechat "Alpha team! Get ready boys, approaching insertion point";

while {!unitReady driver MH6_1} do
{
sleep 1.0
};
MH6_1 sidechat "Alpha team! Get ready for quick deployment";
MH6_1 land "GET OUT";

_numcrew = count crew MH6_1;
while { _numcrew > 1 } do
{
   _numcrew = count crew MH6_1;
sleep 1.0;
MH6_1 sidechat format ["unloading: %1 ", _numcrew];
};

This is just part of the code, where it 'stops' working is that the 'Land' command doesn't happen.


Thanks!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Script Issue on Dedicated Server
« Reply #50 on: 10 Jan 2008, 03:03:06 »
All of those actions need to be performed locally for the helo. Once you get a more complex series of things going on, it can be easier to put them all inside a function and to pass the parameters as an array within the "event" we are creating (This also makes it easy to do by just calling the function if in SP):
Code: (init.sqf) [Select]
moveHeloHandler = compile preprocessFileLineNumbers "moveHelo.sqf";

// Just pass the array of moveHeloEvent "parameters" (second element of _this) to the handler:
"moveHeloEvent" addPublicVariableEventHandler { (_this select 1) call moveHeloHandler };

Code: (moveHelo.sqf) [Select]
_helo = _this select 0;
_height = _this select 1;
_pos = _this select 2;
   
(driver _helo) flyinheight _height;
_helo domove _pos;
(driver _helo) setspeedMode "Full";

_helo sidechat format ["Driver flying non-dedi: %1", getpos AlphaTarget];

_helo sidechat "INSIDE alphainsertion_3";

while {_helo distance _pos > 500} do
{
    _helo sidechat format ["Distance: %1", _helo distance _pos];
    sleep 1.0;
};

//#Approach
_helo SetSpeedMode "Limited";
_helo sidechat "Alpha team! Get ready boys, approaching insertion point";

while {!unitReady driver _helo} do
{
    sleep 1.0
};
_helo sidechat "Alpha team! Get ready for quick deployment";
_helo land "GET OUT";

_numcrew = count crew _helo;

// You should re-calculate _numcrew at the end of a while loop like this with a sleep in it. Not sure it really matters in this case, but in others this might mean that the while logic is using information that was calculated before the sleep, not calculated just as you are doing the check.
while { _numcrew > 1 } do
{
    sleep 1.0;
    _helo sidechat format ["unloading: %1 ", _numcrew];
    _numcrew = count crew _helo;
};

You actually want this new moveHeloHandler to run on every machine, rather than just on the machine that is local to the helo. The directions to the actual helicopter need to be run on the server and the sideChat commands need to be run on every client (since all these commands will be ignored if performed on the wrong machine, it is easier to just run a single function with both types of command in it):
Code: (to move the helo) [Select]
// So the local machine performs the function directly:
_params = [MH6_1, 50, _pos];
_params call moveHeloHandler;

// Request that every OTHER machine performs the function based on receiving the event:
moveHeloEvent = _params;
publicVariable "moveHeloEvent";
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Nixer6

  • Members
  • *
Re: Script Issue on Dedicated Server
« Reply #51 on: 10 Jan 2008, 12:13:25 »
Once you get a more complex series of things going on

Now that was an understatement if I ever have read one.  :P

Spooner thanks so much for your helping me to slightly better grasp the whole locality thing in MP. I am working on a few different things with helos and it's just been driving me nuts.
So...I'd like to try another approach if possible.

Since I now know that OnMapSIngleClick works to at least move markers on a dedi, would it be possible to just use a helo with waypoints and simply move the waypoints with the setWPPos command? The only trouble is that when I checked the Comref here and at the Biki I found that the Biki tells me the effects of the command are local, again.

Why do I have to be a Rocket Scientist to make a good mission?

Offline Case

  • Members
  • *
Re: Script Issue on Dedicated Server
« Reply #52 on: 10 Jan 2008, 16:12:32 »
Thanks Spooner, this looks great.

I am modifying this post, as I have implemented this, but it isn't working correctly.

This is what I have.

Init.sqf
Code: [Select]
moveHeloHandler = compile preprocessFileLineNumbers "InsertionAlpha.sqf";

// Just pass the array of moveHeloEvent "parameters" (second element of _this) to the handler:
"moveHeloEvent" addPublicVariableEventHandler { (_this select 1) call moveHeloHandler };


Radio Trigger with following 'on act':

Code: [Select]
onmapsingleclick "[_pos] execvm ""HeloMoveTrigger.sqf""; true";

Script HeloMoveTrigger.sqf:

Code: [Select]

private ["_pos"];
hint "In helomove trigger";

_pos = _this select 0;

MH6_1 sidechat format ["click location: %1 ", _pos];
OnMapSingleClick "";

if (local MH6_1) then
{
// So the local machine performs the function directly:
_params = [MH6_1, 50, _pos];
_params call moveHeloHandler;
}
else
{
// Request that every OTHER machine performs the function based on receiving the event:
moveHeloEvent = _params;
publicVariable "moveHeloEvent";
};

Script InsertionAlpha.sqf (I have pasted the start of this script for now).
Code: [Select]
hint "IN InsertionAlpha.SQF";

private "_pos";
_helo = _this select 0;
_height = _this select 1;
_pos = _this select 2;   


(driver _helo) flyinheight _height;
_helo domove _pos;
(driver _helo) setspeedMode "Full";

_helo sidechat "Moving";


What happens is this:

1.  Initiate Radio Trigger
2.  Click on Map
3.  Get hint text "In Helo Move Trigger"
4.  Get sidechat "click location....."

Helo doesn't move, and no further sidechats.

It looks like it isn't entering into the InsertionAlpha.sqf file, can you see why this is?

Thanks!!!
« Last Edit: 10 Jan 2008, 18:07:48 by Case »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Script Issue on Dedicated Server
« Reply #53 on: 10 Jan 2008, 19:12:53 »
I'm a bit confused now, since you both seem to be asking for quite different solutions to the same problem and moving in quite different design directions, in spite of the fact that you have said that you are collaborating. This is meaning that I am having to make two solutions to every problem and is wasting a lot of time unnecessarily for all of us. Make up your mind which of you is actually doing the implementation, because I'm getting very confused!

@Case:
Bear in mind that if you use an editor radio trigger that ANY player can use it and that when ANY player uses the trigger then EVERY machine runs the code (so if I use the radio in this case, then every player then gains the map-clicking effect next time they click on the map). This is crazy and leads to a real mess in MP, but is fine in SP. In MP you should be creating radio triggers with createTrigger so that they only have a local effect, so that you can tell who has clicked and you can also limit who can click very easily (for example, to just squad leaders).

You've merged two versions of example scripts without full understanding so you've messed them up a bit. I gave one example that worked in one situation, then you redefined the situation so I changed the example. I wasn't meaning that you use a little bit of both examples and hope that then they still worked ;P You have to remember that in the example with "if (local MH6_1) then" in, the script was just acting on the helo, so you just want it acting locally Once the script has hints and chats in it, you actually want it running on the server (so the helo is given commands) and on ALL of the clients so that they see the text appear. Thus, you should use the example code I gave last and forget the original code that was appropriate in different circumstances.

Regardless, the actual reason your code was failing (though there may have been other issues, this was the most obbvious to me) was due to a variable scope issue (_params was undefined in the else clause).
Code: [Select]
_params = [MH6_1, 50, _pos]; // Need to define this here so that it is visible in both if and else blocks.
if (local MH6_1) then
{
    // So the local machine performs the function directly:
    _params call moveHeloHandler;
}
else
{
    // Request that every OTHER machine performs the function based on receiving the event:
    moveHeloEvent = _params;
    publicVariable "moveHeloEvent";
};
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Case

  • Members
  • *
Re: Script Issue on Dedicated Server
« Reply #54 on: 10 Jan 2008, 20:35:54 »
Spooner,

Thanks again for the reply.

To clarify, Nixer and I aren't working on the same project, we were just dealing with similiar problems (moving a heli through script), and were discussing the problem elsewhere.

Nixer, maybe you could break out from this thread with a new one with your specific problems?? :)

I will fix up the code later so that multiple people can't click on the map in MP, I understand what you are saying with this.

I updated my script and I am still having problems.

It looks like my 'InsertionAlpha.sqf' script is not being entered.

I updated my code as follows:
Code: [Select]
private ["_pos"];
hint "In helomove trigger";

_pos = _this select 0;

MH6_1 sidechat format ["click location: %1 ", _pos];
OnMapSingleClick "";
_params = [MH6_1, 50, _pos];

if (local MH6_1) then
{
// So the local machine performs the function directly:
MH6_1 sidechat "in local mh6_1";
_params call moveHeloHandler;
}
else
{
// Request that every OTHER machine performs the function based on receiving the event:
MH6_1 sidechat "In else";
moveHeloEvent = _params;
publicVariable "moveHeloEvent";
};

When it executes, I get the sidechats:  "in helo move trigger", then "in local mh6_1", but it looks like it isn't calling my MoveHeloHandler.

The first line of the MoveHeloHandler (which is the InsertionAlpha.sqf script) is to display a sidechat for "In InsertionAlpha", and this isn't showing.

Heli just stays on the ground.

Thanks again for any input on this.

Cheers!!

Offline Nixer6

  • Members
  • *
Re: Script Issue on Dedicated Server
« Reply #55 on: 11 Jan 2008, 17:50:14 »
Yeah. Sorry for the FUD.

Still lots of good stuff here, thanks.
Why do I have to be a Rocket Scientist to make a good mission?

Offline Case

  • Members
  • *
Re: Script Issue on Dedicated Server
« Reply #56 on: 13 Jan 2008, 22:05:22 »
I did some more testing, and I think I figured out one of the problems.

Spooner, I was looking at some of your post helping some other guys on the new AddPublicVariableEventHandler.
From one of your suggestions there, I did the following change:

I changed my init.sqf line from:
Code: [Select]
"moveHeloEvent" addPublicVariableEventHandler { (_this select 1) call moveHeloHandler };
To:
Code: [Select]
"moveHeloEvent" addPublicVariableEventHandler moveHeloHandler;
This works great now on non-dedi.

On dedi server the following happens: 

1. Initiate the trigger and click the map.
2. hint's show that it is in 'helomovetrigger.sqf'
3. second hint show that it is 'in else', i added this debug, and it is in my previous post. 

So the next command that should be executing are:
Code: [Select]
moveHeloEvent = _params;
publicVariable "moveHeloEvent";

Is this the correct syntax that should be executing on a dedi-server?  Nothing is happening after this point...  heli doesn't move, and the 'InsertionAlpha.sqf' script doesn't get entered, so, to me, this seems like I have a problem with my command trying to initiate the event call from a dedi-server.

Thanks!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Script Issue on Dedicated Server
« Reply #57 on: 13 Jan 2008, 23:12:54 »
Those two lines are not equivalent, and will definitely cause the code to fail in MP (in SP, this line is ignored). It depends what moveHeloHandler expects to receive; In your case, it expects to receive only the second element of the _this array (_this select 1), rather than both elements (the first is the name of the variable that changed, the second is the new value).

These two lines are equivalent though (though the former is slightly more efficient):
Code: [Select]
"moveHeloEvent" addPublicVariableEventHandler moveHeloHandler;
"moveHeloEvent" addPublicVariableEventHandler { _this call moveHeloHandler };
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Case

  • Members
  • *
Re: Script Issue on Dedicated Server
« Reply #58 on: 14 Jan 2008, 00:21:05 »
Ya,

I am using the former of your two samples now, and it works better, although, as I mentioned in the thread, there seems to be a problem still.

In SP, I am using this to call the event:

Code: [Select]
_params call moveHeloHandler;
This works properly.

In MP I use:

Code: [Select]
moveHeloEvent = _params;
publicVariable "moveHeloEvent";

This MP call doesn't seem to work properly as the script I compiled as the event isn't entered (according to some debug 'hints' and sidechats).

UPDATE:

I did some more testing and I am still having problems.  What it appears to me is that the dedi-server isn't executing the precompiled .sqf file.

Let me explain.

I used Spooner's first sample where the action for the heli was explicit in the init.sqf.  This worked great (dedi and non).

I used the second example, where a precompiled script is assigned to the publicvariable handler (see above, in my instance, preprocessFileLineNumbers "alphainsertion.sqf").

When I use this method, in dedi, this precompiled script isn't executed.  I have a hint in the first line of this script, that never displays.

I am wondering if someone can confirm for sure if they know that this method works in dedi-server?

I want to know if it is a problem with my code or not, so I can try to make some more progress here.  If nobody has actually made this work in dedi, then I will move on and make several eventhandlers doing smaller things for now.

Thanks again for everyone's help with this!

Cheers!

p.s. If someone wants a copy of my scripts to have a look at, please let me know, I would be more than happy to send them to you to take a look at. 

ANOTHER UPDATE:

To clarify, and make a long story short.

When calling an event handler, is this the proper syntax: (making this up for simplicity's sake)

Init.sqf
Code: [Select]
moveHeloHandler = compile preprocessFileLineNumbers "Insertion.sqf";
"moveHeloEvent" addPublicVariableEventHandler moveHeloHandler;


Insertion.sqf
Code: [Select]
stuff... doesn't matter for my question, as what is happening to me on dedi, this doesn't ever get called
HeloMoveTrigger.sqf  - i only left the section that calls the event handler... This is the sqf called from my radio trigger.
Code: [Select]

_params = [_heli, 50, _pos, _team];

if (local _heli) then
{
// So the local machine performs the function directly:
_heli sidechat "in local";
_params call moveHeloHandler;
}
else
{
// Request that every OTHER machine performs the function based on receiving the event:
_heli sidechat "In else";
moveHeloEvent = _params;
publicVariable "moveHeloEvent";
};

The above code, is where my question REALLY is.  Is this syntax correct?

Basically, if it is local, it runs it using a call to the handler name defined in the init.sqf, and if it is remote (ie on dedi-server), it calls it by passing the parameters into the publicvariable?

Is this correct? 

If it is, I can't for the life of me see what I am doing wrong.

Again, thanks for your consideration on this problem.

Cheers!

« Last Edit: 17 Jan 2008, 23:42:43 by Case »