Jump to content
Sign in to follow this  
conz

Trouble figuring out a script error

Recommended Posts

I'm having some trouble figuring out why a small script isn't working, I found a script to transfer AI from the server to the HC on reddit:

/*
* aitohc.sqf
*
* By VCRPlayer
*
* This script will move ANY ai (ie: zeus-spawned, etc)         to the headless client for processing on every frame
* 
* In init.sqf, put "[] execVM "aitohc.sqf";" (without outer quotes)
*
* In the description of the HeadlessClient virtual unit, put HC
*/
if (!isServer) exitWith {};
_HC = owner "HC"; //"HC" denotes the name of the unit in-game
waitUntil {!isNil "HC"};

["HCS_addToHC", "onEachFrame", {
   if ((isPlayer)||(_x in units group _HC)) exitWith {};
   if (isNull _HC) ExitWith{};

   { _x setGroupOwner _HC; //adding all units that aren't player or aren't already under HC to HC
   }forEach allUnits;

}] call BIS_fnc_addStackedEventHandler;

It runs but craps out and seems to cause a loop (high cpu) on both the HC and Server in its broken state. I'm not that well versed in arma scripting to figure out what is happening, from what I can tell the if statement is correct unless arma syntax differs from other languages with if ((statement) || (statement)).

I'd appreciate any help to solve this, I was hoping this script would be the golden ticket to get AI to run on the HC.

Error is as follows:

22:18:06 Error in expression <addToHC", "onEachFrame", {

if ((isPlayer)||(_x in units group _HC)) exitWith {};>

22:18:06 Error position: <)||(_x in units group _HC)) exitWith {};>

22:18:06 Error unexpected )

22:18:06 File mpmissions\__cur_mp.Bornholm\aitohc.sqf, line 17

22:18:06 Error in expression <addToHC", "onEachFrame", {

if ((isPlayer)||(_x in units group _HC)) exitWith {};>

22:18:06 Error position: <)||(_x in units group _HC)) exitWith {};>

22:18:06 Error unexpected )

22:18:06 File mpmissions\__cur_mp.Bornholm\aitohc.sqf, line 17

---

22:18:08 Error in expression <

>if (!isServer) exitWith {};

>_HC = owner "HC";

>waitUntil {!isNil "HC"};

[>

22:18:08 Error position: <owner "HC";

waitUntil {!isNil "HC"};

[>

22:18:08 Error owner: Type String, expected Object

22:18:08 File mpmissions\__cur_mp.Bornholm\aitohc.sqf, line 13

Share this post


Link to post
Share on other sites
if (!isServer) exitWith {};
_HC = owner HC; //"HC" denotes the name of the unit in-game

["HCS_addToHC", "onEachFrame", {
   if ((isPlayer)||(_x in units group _HC)) exitWith {};
   if (isNull _HC) ExitWith{};

   { _x setGroupOwner _HC; //adding all units that aren't player or aren't already under HC to HC
   }forEach allUnits;

}] call BIS_fnc_addStackedEventHandler;

Share this post


Link to post
Share on other sites
if (!isServer) exitWith {};
_HC = owner HC; //"HC" denotes the name of the unit in-game

["HCS_addToHC", "onEachFrame", {
   if ((isPlayer)||(_x in units group _HC)) exitWith {};
   if (isNull _HC) ExitWith{};

   { _x setGroupOwner _HC; //adding all units that aren't player or aren't already under HC to HC
   }forEach allUnits;

}] call BIS_fnc_addStackedEventHandler;

No go, same error.

For debugging I changed the script to:

if (!isServer) exitWith {};

_HC = owner HC; //"HC" denotes the name of the unit in-game

//waitUntil {!isNil _HC};

["HCS_addToHC", "onEachFrame", {

if (isPlayer) exitWith {};

if (_x in units group _HC) exitWith {};

if (isNull _HC) ExitWith{};

{ _x setGroupOwner _HC; //adding all units that aren't player or aren't already under HC to HC

}forEach allUnits;

}] call BIS_fnc_addStackedEventHandler;

Error produced:

0:34:01 Error in expression <_addToHC", "onEachFrame", {

if (isPlayer) exitWith {};

if (_x in units group _HC>

0:34:01 Error position: <) exitWith {};

if (_x in units group _HC>

0:34:01 Error unexpected )

0:34:01 File mpmissions\__CUR_MP.Bornholm\aitohc.sqf, line 17

0:34:01 Error in expression <_addToHC", "onEachFrame", {

if (isPlayer) exitWith {};

if (_x in units group _HC>

0:34:01 Error position: <) exitWith {};

if (_x in units group _HC>

0:34:01 Error unexpected )

0:34:01 File mpmissions\__CUR_MP.Bornholm\aitohc.sqf, line 17

Line 17 is if (isPlayer) exitWith {};

So possibly something wrong with the one above there ?

Share this post


Link to post
Share on other sites

Hello,

That script is mega-nasty. I want to pour gasoline on my computer and watch it go up in flames after reading that.

The allUnits command returned array can get huge if you have a mission with many, many ai. Trying to loop this onEachFrame is not an ideal solution by a longshot. A better name for this script would be "fps_massacre.sqf".

I would just like to change 1 line from his original description:

"This script will move ANY ai (ie: zeus-spawned, etc) to the headless client, while raping your frames-per-second"

There are a few simple solutions, however. I don't know how you are spawning units, whether they be from a Zeus player or through scripts, but it's not an issue because there is a solution for both. For our Zeus units, we will be using 2 Curator-only event handlers, CuratorGroupPlaced and CuratorObjectPlaced.

Copy this into the INIT box for the curator, or you can put this into a script and run it if you know how.

this addEventHandler ["CuratorGroupPlaced",
{
_HC = owner "HC";
_check = (_this select 1) setGroupOwner _HC;

if (_check) then
{
	systemChat "Group was successfully transferred to Headless Client.";
} else
{
	systemChat "Group was not transferred to Headless Client.";
};
}];

this addEventHandler ["CuratorObjectPlaced",
{
_HC = owner "HC";
_check = (group (_this select 1)) setGroupOwner _HC;

if (_check) then
{
	systemChat "Object was successfully transferred to Headless Client.";
} else
{
	systemChat "Object was not transferred to Headless Client.";
};
}];

Now for units that are spawned through script, make sure you add this code to initServer.sqf:

transfer_group_to_headless =
{
_HC = owner "HC";
_check = _this setGroupOwner _HC;

if (_check) then
{
	systemChat "Group was successfully transferred to Headless Client.";
} else
{
	systemChat "Group was not transferred to Headless Client.";
};
};

And every time your script spawns units make sure you run this code right after the units are spawned:

_myGroup call transfer_group_to_headless;

So basically that should all work or something, I have no idea.

Share this post


Link to post
Share on other sites
Should be isPlayer _x

I was just thinking that too .. thanks for the pointer.

Hello,

That script is mega-nasty. I want to pour gasoline on my computer and watch it go up in flames after reading that.

~stuff~

So basically that should all work or something, I have no idea.

I figured it'd was seriously dirty, I'll give these a try in the morning to see if I can get it to go. I know how to add scripts to units spawned from scripts so I'll tinker a bit and post it.

Share this post


Link to post
Share on other sites

transfer_group_to_headless =
{
_HC = owner "HC";
.....

I just loaded this in my sleepy brain and it instantly crashed with error. Lucky it didnt permanently corrupt my ssd (super sanity drive).

Share this post


Link to post
Share on other sites
I just loaded this in my sleepy brain and it instantly crashed with error. Lucky it didnt permanently corrupt my ssd (super sanity drive).

Even I'm not sure how that's supposed to work, that snippet was taken directly from the original posted script. Although please be aware that the mission should have a headless client somewhere and (apparently) you're supposed to put "HC" in the description field (I have no idea how that's useful at all).

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  

×