Jump to content
Sign in to follow this  
AdirB

AI spawns twice

Recommended Posts

Hello,

I have a script that spawns AI, the problem is that the script spawns the AI twice.

I've looked everywhere and there's no copy of the script.
Maybe it's something I don't know that does that.

Please may you help me? :D

//Office Guard boss NPC
_pos = [14602.1,16773.7,5.09502];
_guardboss = createVehicle ["Exile_Guard_02", _pos, [], 0, "CAN_COLLIDE"];
_guardboss setDir 270;
_guardboss setPosATL _pos;
_guardboss allowDamage false;

//Guard boss behaviours
_guardboss disableAI "ANIM";

_guardboss disableAI "MOVE";

_guardboss disableAI "FSM";

_guardboss disableAI "AUTOTARGET";

_guardboss disableAI "TARGET";

_guardboss disableAI "CHECKVISIBLE";

_guardboss allowDamage false;
_guardboss removeAllEventHandlers "HandleDamage";
_guardboss setVariable ["BIS_fnc_animalBehaviour_disable", true];

The script executes from the init.sqf by 'execVM'.

 

Share this post


Link to post
Share on other sites

Let me guess: you have two computers/players connected in a MP mission? The script is executed on both machines, and they will create one unit each. Connect three players and you will have three units. Change the execution line of the script so it is only executed on one machine - the server.

In init.sqf:

if (isServer) then {
  execVM "scriptfile.sqf";
};
(Or put it in initserver.sqf.)

Also: add the third parameter to the setVariable command so that it is set on all machines, i.e. if you want to be able to read the variable on other machines than the server:

_guardboss setVariable ["BIS_fnc_animalBehaviour_disable", true, true];

Share this post


Link to post
Share on other sites

Let me guess: you have two computers/players connected in a MP mission? The script is executed on both machines, and they will create one unit each. Connect three players and you will have three units. Change the execution line of the script so it is only executed on one machine - the server.

In init.sqf:

if (isServer) then {
  execVM "scriptfile.sqf";
};
(Or put it in initserver.sqf.)

Also: add the third parameter to the setVariable command so that it is set on all machines, i.e. if you want to be able to read the variable on other machines than the server:

_guardboss setVariable ["BIS_fnc_animalBehaviour_disable", true, true];

NICE! it worked, thank you!

I have two more question, if you may answer :)

 

1. When I'm getting really close to that AI it's like I'm pushing him, is there a way to make him completely static?

2. The Exile mod is familiar to you? because you knew that there's the initServer.sqf

Share this post


Link to post
Share on other sites

1. I tried this. The unit look alive, but it behaves like a statue:

theUnit = "B_soldier_M_F" createVehicle getMarkerPos "themarker";
theUnit allowDamage false;

I don't succeed in "pushing him" at all. But maybe you can use attachTo to attach him to something static (e.g. to an underground barrel).

 

2. The "Exile mod" is not familiar to me, but I've read this: https://community.bistudio.com/wiki/Initialization_Order.

Share this post


Link to post
Share on other sites

1. I tried this. The unit look alive, but it behaves like a statue:

theUnit = "B_soldier_M_F" createVehicle getMarkerPos "themarker";
theUnit allowDamage false;

I don't succeed in "pushing him" at all. But maybe you can use attachTo to attach him to something static (e.g. to an underground barrel).

 

2. The "Exile mod" is not familiar to me, but I've read this: https://community.bistudio.com/wiki/Initialization_Order.

 

Alright, I made him sitting on a chair and know he's not moving :)

 

but there's another problem, the addAction command is not working for some reason, I can't see the "Hire Guards" lable on him.

_guardboss addAction ["Hire Guards", "base_ai_guards\spawnguards.sqf"];

it's in the save file you told me to execute in the init.sqf file with the isServer if statment.

Share this post


Link to post
Share on other sites

1. I tried this. The unit look alive, but it behaves like a statue:

theUnit = "B_soldier_M_F" createVehicle getMarkerPos "themarker";
theUnit allowDamage false;

I don't succeed in "pushing him" at all. But maybe you can use attachTo to attach him to something static (e.g. to an underground barrel).

 

2. The "Exile mod" is not familiar to me, but I've read this: https://community.bistudio.com/wiki/Initialization_Order.

I deleted the isserver if statment and it worked but it's not good ^^

Share this post


Link to post
Share on other sites

Wouldn't you be better off using createunit

mygrp = creategroup west;
theunit = mygrp createUnit ["B_soldier_M_F",getMarkerPos "themarker",[],0,"form"];
theunit allowdamage false;

unless you tell him to do something he won't do much though

Share this post


Link to post
Share on other sites

Wouldn't you be better off using createunit

mygrp = creategroup west;
theunit = mygrp createUnit ["B_soldier_M_F",getMarkerPos "themarker",[],0,"form"];
theunit allowdamage false;

unless you tell him to do something he won't do much though

I want to spawn AIs that will patrol around a specific loaction.

I don't really know what's better (createUnit or createVehicle), until now I only used createVehicle.

Share this post


Link to post
Share on other sites

createVehicle is for empty vehicles. createUnits is for ai units (men). createVehicle works for men too, but they seem to miss ai. If you want to spawn vehicles with crew in it, use BIS_fnc_spawnVehicle (https://community.bistudio.com/wiki/BIS_fnc_spawnVehicle).

 

About the addAction issue you had. That must be executed on the machine with the player that will have it. So when you removed "if (isServer)..." the script is executed on all machines, as you have already figured out. Whan you could do (and maybe should do) is to keep the "if (isServer)..." and at the last line in your guard script you set a global variable:

GuardBoss = _guardBoss;
publicVariable "GuardBoss";

And for the clients (below script execution in init.sqf) you can add:

[] spawn {
  waitUntil { !isNill "GuardBoss" };
  GuardBoss addAction (...);
};

Now, guard will be created on server, and addAction will be added on all clients when the guard exists. First thing I do here is to set your guard boss in a public variable, since a local variable cannot be publicVariabled, and you need the GuardBoss var on all machines.

Share this post


Link to post
Share on other sites

I want to spawn AIs that will patrol around a specific loaction.

I don't really know what's better (createUnit or createVehicle), until now I only used createVehicle.

 

 

You will need to script some waypoints or download a patrol script and pass the unit name to that script.

Can you still push them when using createunit?

Share this post


Link to post
Share on other sites

createVehicle is for empty vehicles. createUnits is for ai units (men). createVehicle works for men too, but they seem to miss ai. If you want to spawn vehicles with crew in it, use BIS_fnc_spawnVehicle (https://community.bistudio.com/wiki/BIS_fnc_spawnVehicle).

 

About the addAction issue you had. That must be executed on the machine with the player that will have it. So when you removed "if (isServer)..." the script is executed on all machines, as you have already figured out. Whan you could do (and maybe should do) is to keep the "if (isServer)..." and at the last line in your guard script you set a global variable:

GuardBoss = _guardBoss;
publicVariable "GuardBoss";

And for the clients (below script execution in init.sqf) you can add:

[] spawn {
  waitUntil { !isNill "GuardBoss" };
  GuardBoss addAction (...);
};

Now, guard will be created on server, and addAction will be added on all clients when the guard exists. First thing I do here is to set your guard boss in a public variable, since a local variable cannot be publicVariabled, and you need the GuardBoss var on all machines.

WOW ok thank you for the explanation!

So addAction have to be global as it suppose to work on all machines unlike the addVehicle/Unit which will multiply on every machine joins the server.

 

You will need to script some waypoints or download a patrol script and pass the unit name to that script.

Can you still push them when using createunit?

Yeah, I know that, I'll figure out something.

I didn't use the create unit already, I'll tell you when I do.

Share this post


Link to post
Share on other sites

createVehicle is for empty vehicles. createUnits is for ai units (men). createVehicle works for men too, but they seem to miss ai. If you want to spawn vehicles with crew in it, use BIS_fnc_spawnVehicle (https://community.bistudio.com/wiki/BIS_fnc_spawnVehicle).

 

About the addAction issue you had. That must be executed on the machine with the player that will have it. So when you removed "if (isServer)..." the script is executed on all machines, as you have already figured out. Whan you could do (and maybe should do) is to keep the "if (isServer)..." and at the last line in your guard script you set a global variable:

GuardBoss = _guardBoss;
publicVariable "GuardBoss";

And for the clients (below script execution in init.sqf) you can add:

[] spawn {
  waitUntil { !isNill "GuardBoss" };
  GuardBoss addAction (...);
};

Now, guard will be created on server, and addAction will be added on all clients when the guard exists. First thing I do here is to set your guard boss in a public variable, since a local variable cannot be publicVariabled, and you need the GuardBoss var on all machines.

 

 

You will need to script some waypoints or download a patrol script and pass the unit name to that script.

Can you still push them when using createunit?

I don't understand why or how but it's still not working.

I've done everything you (enigma) said.

This is the init.sqf:

if (isServer) then {
execVM "base_ai_guards\hireguards.sqf";
};

[] spawn {
  waitUntil { !isNill "GuardBoss" };
  GuardBoss addAction ["Hire Guards", "base_ai_guards\spawnguards.sqf"];
};

This is the _guardboss file:

//Office Guard boss NPC
_pos = [14602.1,16773.7,5.09502];
_guardboss = createUnit ["Exile_Guard_02", _pos, [], 0, "CAN_COLLIDE"];
_guardboss setDir 270;
_guardboss setPosATL _pos;
_guardboss allowDamage false;

//Guard boss behaviours
_guardboss disableAI "ANIM";

_guardboss disableAI "MOVE";

_guardboss disableAI "FSM";

_guardboss disableAI "AUTOTARGET";

_guardboss disableAI "TARGET";

_guardboss disableAI "CHECKVISIBLE";

_guardboss allowDamage false;
_guardboss removeAllEventHandlers "HandleDamage";
_guardboss setVariable ["BIS_fnc_animalBehaviour_disable", true, true];


GuardBoss = _guardBoss;
publicVariable "GuardBoss";

The addAction is still not working  :unsure:

 

About the addUnit I looked in the bohemia wiki and it seems it's like the addVehicle so I only change the addVehicle to addUnit but it's not working too.

Share this post


Link to post
Share on other sites

If you take another look you will find the createunit requires a gorup.

 

I'd take a chance and say you haven't enabled showscripterrors and that the action is working but the code is crashing and not displaying a script  error.

Share this post


Link to post
Share on other sites

If you take another look you will find the createunit requires a gorup.

 

I'd take a chance and say you haven't enabled showscripterrors and that the action is working but the code is crashing and not displaying a script  error.

Ok thank you the group is working.

 

I actually had the -showscripterros in the arma launch options, but no error shown up in-game, I also tried to add this line in the extra parameter section in the "Tophe's Arma Dedicated Server Tool" but it didn't work either.

I could find erros in the RPT file.

19:56:59 Error in expression <qf";
};

[] spawn {
waitUntil { !isNill "GuardBoss" };
GuardBoss addAction ["Hir>

19:56:59   Error position: <"GuardBoss" };
GuardBoss addAction ["Hir>

19:56:59   Error Missing ;

Share this post


Link to post
Share on other sites

A misspelling! "isNill" should be "isNil". Sorry about that...

Share this post


Link to post
Share on other sites

A misspelling! "isNill" should be "isNil". Sorry about that...

I actually thought it's "nill" too.

Thank you :)

Share this post


Link to post
Share on other sites

If you take another look you will find the createunit requires a gorup.

 

I'd take a chance and say you haven't enabled showscripterrors and that the action is working but the code is crashing and not displaying a script  error.

Hello,

I've tried to use createUnit but I couldn't get it working since I'm new to this.

 

This is the script:

if (isServer) then {
guardgrp = creategroup west;

_pos = [14745.541,17.91,16732.02];
guard1 = guardgrp createUnit ["Exile_Guard_01", _pos ,[],0,"form"];
guard1 setDir 270;
guard1 setPosATL _pos;

_pos = [14732.757,17.91,16731.408];
guard2 = guardgrp createUnit ["Exile_Guard_02", _pos ,[],0,"form"];
guard2 setDir 270;
guard2 setPosATL _pos;

_pos = [14737.639,17.91,16731.543];
guard3 = guardgrp createUnit ["Exile_Guard_03", _pos ,[],0,"form"];
guard3 setDir 270;
guard3 setPosATL _pos;

_pos = [14741.549,17.91,16731.746];
guard4 = guardgrp createUnit ["Exile_Guard_01", _pos ,[],0,"form"];
guard4 setDir 270;
guard4 setPosATL _pos;
};

Which called from an addAction command.

Everything else I'm adding to the script above is working, that means the commands are wrong.

I have no errors both in from the showScriptErrors and the RPT file.

I'd apperciate it if you help me to solve it  :)

Share this post


Link to post
Share on other sites

No need to setPosATL after the unit is already created on that position in the first place, and just for sake of, since I'm not sure if it makes a difference or not, the "special" parameter options are in all caps, so lets make that so:

 

_pos = [14745.541,17.91,16732.02];
guard1 = guardgrp createUnit ["Exile_Guard_01", _pos ,[],0,"FORM"];
guard1 setDir 270;

Share this post


Link to post
Share on other sites

I think of three possible causes:

1. The "Exile_Guard_XX" class does not exist.

2. In Arma 2 you needed a side command center to spawn units. That is created automatically for units placed in editor. Try again after adding a west unit in the editor to find out.

3. Script is not called properly.

Share this post


Link to post
Share on other sites

4. The position is not where you think it is. I don't know how you found out the exact position, but I always use markers for that:

_pos = getMarkerPos "TheMarker".

Share this post


Link to post
Share on other sites

 

No need to setPosATL after the unit is already created on that position in the first place, and just for sake of, since I'm not sure if it makes a difference or not, the "special" parameter options are in all caps, so lets make that so:

 

_pos = [14745.541,17.91,16732.02];
guard1 = guardgrp createUnit ["Exile_Guard_01", _pos ,[],0,"FORM"];
guard1 setDir 270;

 

I've tried to change it from "form" to "FORM", it didn't work.

 

I think of three possible causes:

1. The "Exile_Guard_XX" class does not exist.

2. In Arma 2 you needed a side command center to spawn units. That is created automatically for units placed in editor. Try again after adding a west unit in the editor to find out.

3. Script is not called properly.

I've tried  everything.

The unit classname doest exist but I tried another one, it didn't work.

The custom unit side is independet and the group side was west, I've tried to change it to independet, it didn't work.

The script is calling the SQF properly, I know because other commands (like "hint") is working in that SQF.

 

SQF:

if (isServer) then {
guardgrp = creategroup independent;

_pos = [14745.541,17.91,16732.02];
guard1 = guardgrp createUnit ["Exile_Guard_01", _pos ,[],0,"FORM"];
guard1 setDir 270;

_pos = [14732.757,17.91,16731.408];
guard2 = guardgrp createUnit ["Exile_Guard_02", _pos ,[],0,"FORM"];
guard2 setDir 270;

_pos = [14737.639,17.91,16731.543];
guard3 = guardgrp createUnit ["Exile_Guard_03", _pos ,[],0,"FORM"];
guard3 setDir 270;

_pos = [14741.549,17.91,16731.746];
guard4 = guardgrp createUnit ["Exile_Guard_01", _pos ,[],0,"FORM"];
guard4 setDir 270;
};

init.sqf (addAction):

[] spawn {
  waitUntil { !isNil "GuardBoss" };
  GuardBoss addAction ["Hire Guards", "base_ai_guards\spawnguards.sqf"];
};

Share this post


Link to post
Share on other sites

Ok, what about this:

Your spawn position is 16731 meters up in the air. Maybe you just don't wait enough time to see them hit the ground. :)

Share this post


Link to post
Share on other sites

Ok, what about this:

Your spawn position is 16731 meters up in the air. Maybe you just don't wait enough time to see them hit the ground. :)

I changed now the height to something lower so the fall will be shorter but they are not spawning again.

Share this post


Link to post
Share on other sites
guard1 = group player  createUnit [type player, getpos player ,[],0,"FORM"];

Try just that line on an empty map, place it in the players init and preview, it should create a unit. if it doesn't then your game is broke.

 

if it works try it with the correct unit type that your trying to use.

guard1 = group player  createUnit ["Exile_Guard_01",getpos player ,[],0,"FORM"];

Share this post


Link to post
Share on other sites
guard1 = group player  createUnit [type player, getpos player ,[],0,"FORM"];

Try just that line on an empty map, place it in the players init and preview, it should create a unit. if it doesn't then your game is broke.

 

if it works try it with the correct unit type that your trying to use.

guard1 = group player  createUnit ["Exile_Guard_01",getpos player ,[],0,"FORM"];

Both of the commands worked.

I've tried to use "group player" and "getpos player" on my lines and it worked, but only after I deleted the "isServer" if statement (THIS STATEMENT IS RECOMMANDED?)

Then I used the original positions, they are really far away from the position I wanted them to be. is there a way to get the right X Y Z?

The way I did take the X Y Z is saving a mission with these units and then searching their position in the mission.sqm.

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  

×