Arma 3
[Solved] Teleport script for stuck ai
Need som help with a simple teleport script or something so i can get AI squadmates from a building. I have been testing a mod/mission that i have heavily tweaked, and i need to play it for a long time to se how the performance gets affected long sessions. But after two session about 6 hours each, atlest one of my ai squadmates gets stuck in a building.

So it just add lot frustration and halts my testing, especally since i also testing the balance economy system with recruitable AI squadmates with the currency.

Tried create a teleport scripts, but it wont activate

_squadpos = { _x setpos [getpos leader player] ; } forEach units group player;
_tr1 = createTrigger ["EmptyDetector", [0,0,0]];
_tr1 setTriggerActivation ["Charlie", "PRESENT", false];
_tr1 setTriggerStatements ["this", _squadpos, ""];


Going to look more at a teleport script later for some other thing.
Last edited by FederalRazer89; Mar 13, 2017 @ 7:44am
< >
Showing 1-14 of 14 comments
MATTXYO Oct 25, 2016 @ 5:53pm 
You could always use an addAction.

Inside the init.sqf add
player addAction ["Reset squad","squadReset.sqf"];

Then create the squadReset.sqf inside the mission folder.

Add inside of squadReset.sqf
_resetPosition = getPos player; { _x setPos _resetPosition; sleep 0.2; }forEach units group player; hint "Squad reset complete";
Last edited by MATTXYO; Oct 26, 2016 @ 7:17am
Tajin Oct 28, 2016 @ 7:22am 
Why don't you simply use zeus while testing ?
FederalRazer89 Nov 1, 2016 @ 10:31am 
MATTXYO thanks for your help


and why i dont use zeus is to avoid any possibilitis that i can see the enemy groups around my position, looking at balance aswell. And also if i enable zeus i might be tempted to use it, i use it when i test for more immediate changes.


Btw anyone know any good guides for arma 3 scripting, that handles arrays?
Tajin Nov 1, 2016 @ 11:12am 
The official wiki has pretty much all the information you need.

Here are some links (just for example):
https://community.bistudio.com/wiki/Array
https://community.bistudio.com/wiki/Category:Scripting_Commands_Arma_3



I would also recommend using the scripting section in the official forums instead of this place.

Oh and I would also recommend getting the poseidon editor for scripting, If you haven't already.:
https://forums.bistudio.com/topic/155514-poseidon-advanced-text-editor-for-scripts-configs/
Last edited by Tajin; Mar 13, 2017 @ 4:24am
RickOShay Mar 13, 2017 @ 3:59am 
Poseidon script editor is excellent.
I use a trigger for each playable unit - repeatable;
Player is p1 - playable units are called p2,p3,pn etc.
Put the following into a script called ROSaistuck.sqf;

// Teleports AI that are stuck after they fall behind team leader (the human player) - p1 in this case.
// called via repeatable trigger cond. ie. p2 distance p1 > 150 && !isplayer p2
// nul = [p2] execvm "scripts\ROSaistuck.sqf";

_unit = _this select 0;
_tleader = leader (group _unit);

if ( !isnull _tleader
&& isPlayer _tleader
&& vehicle _tleader == _tleader
&& isTouchingGround _tleader
&& !isplayer _unit
&& isTouchingGround _unit
&& vehicle _unit == _unit )

then {
_dist = random -10;
_dir = direction _tleader;
_pos = getposATL _tleader;
_position = [(_pos select 0) + (sin _dir) * _dist, (_pos select 1) + (cos _dir) * _dist, 0];
_unit setPosATL [_position select 0, (_position select 1), _position select 2];
(group _tleader) setBehaviour "AWARE";
(group _tleader) setFormation "WEDGE";
_unit setUnitPos "up";
};
Last edited by RickOShay; Feb 22, 2018 @ 12:50am
Tajin Mar 13, 2017 @ 4:27am 
If you combine "isServer" and the "player" variable like that, means it will only work right in singleplayer.
Last edited by Tajin; Mar 13, 2017 @ 4:28am
RickOShay Mar 13, 2017 @ 4:55am 
Yep I thought he was playing in SP either way wasn't required (thanks Tajin) - was pasting part from a longer script. Also added ungroup/regroup - which resolves occasional AI not teleporting. EDIT - after more testing ungroup / regroup causes other issues so I removed that process.
Last edited by RickOShay; Feb 22, 2018 @ 4:54am
FederalRazer89 Mar 13, 2017 @ 7:44am 
Forgot to change it to [Solved] but this is only for singleplayer. RickOShay you gave me an idee that i will try when the 3FPS bug is solved.
RickOShay Mar 13, 2017 @ 9:54am 
I'm using the above and it works reliably even on the ported maps where AI tend to get stuck quite a bit - mostly from what I assume being the ATL vertical pos - like npc's fall/get stuck in the terrain or buildings etc. Obviously you can change the distance to player so it forces the teleport more/less often.
Last edited by RickOShay; Feb 22, 2018 @ 4:55am
Tajin Mar 20, 2017 @ 2:42am 
you can simplify that quite a bit using some of the newer script-commands:
params ["_unit"]; if ( !isnull player && {vehicle player isEqualTo player} && {isTouchingGround player} && {getPos player select 2 < 1} ) then { [_unit] joinSilent grpnull; sleep 1; _unit setPos (player getPos [random 10, direction player - 180]); [_unit] joinSilent (group player); };
Last edited by Tajin; Mar 21, 2017 @ 1:34am
FederalRazer89 Mar 20, 2017 @ 1:32pm 
Because i have some other stuff i want script first, this is not high on my priority list.

But i intend to try to make an unstuck script that would work only on the chosen soldier and just nudge him a few meters from his current position, and apply the command "joinsilent". This would work for my purpose, tend to have my Ai squadmates spread out at different positions to cover.

i have seen that the mod antistasi have this kind of unstuck function.
RickOShay Mar 20, 2017 @ 11:11pm 
Tajin - thanks that's cleaner and faster. It throws an error btw 'error missing ;'. I editied the origin on getpos as below now it works great. Thanks for your input.

params ["_unit"];

if ( !isnull player && {vehicle player == player} && {isTouchingGround player} && {getPos player select 2 < 1} ) then {

_unit setPos (player getPos [random 10, direction player - 180]);

};
Last edited by RickOShay; Feb 22, 2018 @ 1:01am
RickOShay Nov 25, 2017 @ 1:31am 
Here's the latest version and seems to work in most COOP missions played in 'SP' mode via listen server with one player.

To setup create one trigger per playable unit in Eden editor. Doesn't matter that some units will be players - trigger cond and script doesn't run if unit == player. In this instance all units are named p1,p2,p3,p4..... with p1 the group leader and player (required position). Save the script into your scripts folder under your mission folder.

Example Trigger for p2: (make one for each playable unit)

Size: NA
Activation: Repeatable

Condition:
!isPlayer p2 && (p2 distance player) >= 150

Trigger: On Activation: (call the script)
null = [p2] execvm "scripts\ROSaistuck.sqf";

ie. you're calling the script for each AI unit via a separate trigger passing the unit name to the script. So edit trigger cond and activ above for each unit p2,p3,p4 ...etc

Create script in mission scripts folder and put this into it:

// AIstuck - by RickOShay
// Teleports AI to group leader that are stuck or fall behind
// Where units are named p1,p2,p3.... p1 is player and group leader
// called via repeatable trigger:
// condition: !isPlayer p2 && p2 distance leader p2 >= 150;
// activation: nul = [p2] execvm "scripts\ROSaistuck.sqf";

_unit = _this select 0;
_tleader = leader (group _unit);

if ( !isnull _tleader
&& isPlayer _tleader
&& vehicle _tleader == _tleader
&& isTouchingGround _tleader
&& !isplayer _unit
&& isTouchingGround _unit
&& vehicle _unit == _unit )

then {
_dist = random -10;
_dir = direction _tleader;
_pos = getposATL _tleader;
_position = [(_pos select 0) + (sin _dir) * _dist, (_pos select 1) + (cos _dir) * _dist, 0];
_unit setPosATL [_position select 0, (_position select 1), _position select 2];
(group _tleader) setBehaviour "AWARE";
(group _tleader) setFormation "WEDGE";
_unit setUnitPos "AUTO";
};
Last edited by RickOShay; Feb 22, 2018 @ 4:57am
markhansaven May 20, 2019 @ 4:47pm 
I had this chase map where this invincible Terminator would chase me around with his buggy, and I just made a 'BuggyStuckTimer', a global variable that counts up for the seconds that the guy is stuck in his buggy, and then I just setVelocity of the vehicle to burst out [0,0,10]:


Set this at start of map:
BuggyStuck = 0;

Set this in a trigger that's activated once:
call{[] spawn {

_KphSpeed = (vectorMagnitude velocity HunterBuggy) * 3.6;

hint format ["HunterBuggy _KphSpeed = %1",_KphSpeed];

if ((StuckTimer < 8) && (_KphSpeed < 3) && (MountedBuggy)) then {
StuckTimer = StuckTimer + 1;

if (StuckTimer >= 8) then {
HunterBuggy setVelocity [0,0,20];
};

} else {
StuckTimer = 0;
};

sleep 1;

}}
< >
Showing 1-14 of 14 comments
Per page: 1530 50

Date Posted: Oct 25, 2016 @ 9:14am
Posts: 14