Jump to content
gfresco

Editing script to include knowsabout player issue

Recommended Posts

Howdy. I'm a lousy scripter and mostly tinker with others. I've been trying to modify a script I've found to no avail. Perhaps someone can guide me & teach me a thing or two.

 

Script in question:

//________________  Author : [GR]GEORGE F ___________ 18/12/2017 _____________

if (!isServer) exitWith {};

private ["_ReconTeams","_enemiesArray","_randomPos","_x"];
#define ReconTeam "vn_o_men_nva_15", "vn_o_men_nva_16", "vn_o_men_nva_17", "vn_o_men_nva_18","vn_o_men_nva_19","vn_o_men_nva_20","vn_o_men_nva_21","vn_o_men_nva_24"

	_enemiesArray = [grpNull];	
	_x = 0;

	_ReconTeams = createGroup opfor;
	_randomPos = [[["base4"],[]],["water","out"]] call BIS_fnc_randomPos;
	_ReconTeams = [_randomPos, opfor,[ReconTeam]] call BIS_fnc_spawnGroup;
	_ReconTeams setCombatMode "RED";	
	_enemiesArray = _enemiesArray + [_ReconTeams];
        _ReconTeams addWaypoint [(player getpos [115,45]),0];	

while {true} do {
//hint"WP ReconTeam updated";
{
	deleteWaypoint [_x, 0];	
	_waypoint1 = _x addWaypoint [(player getpos [115,45]),0];	
	_waypoint1 setWaypointType "MOVE";//SAD MOVE
	_x setCombatMode "RED";
	_x setSpeedMode "FULL";
	_x allowFleeing 0;	
		}foreach [_ReconTeams];
	 sleep 10;
 };

For the latter part of the script that updates I'm trying to insert a check so it only runs that second half to update the waypoint if the player is detected by east/opfor. Its basically a script that spawns a unit to hunt a player down (triggered by a detected by opfor trigger) but I'd rather the group it generates only get updates if the player is detected, so its possible to elude/evade the group.

 

I've been trying to insert a "((east knowsabout Player) >0)" segment alongside the while {true} command but I have the scripting knowledge of an illiterate gibbon so every different form of doing so has run back repeated errors for me. Anyone able to offer some pointers?

Share this post


Link to post
Share on other sites

Hello, knowsAbout can also be used by a group object, and for the value, when an AI sees a player it usually goes up from 1 to 4 directly that is the maximum according to the knowsAbout wiki.

You could use it this way in your script:

if (_ReconTeams knowsAbout player > 1) then {

    // your code when the group detects the player
};

Try it and play with the value, 2 should work fine too.

  • Like 2

Share this post


Link to post
Share on other sites

Tweak just a waypoint and change its position. Add it if no current move. Forget the while true loop and use an EH:

 

_ReconTeams addEventHandler ["KnowsAboutChanged", { 
  params ["_grp", "_target", "_newKA","_oldKA"]; 
  if (_target == vehicle player && _newKA > 1.5 ) then {
    _grp allowFleeing 0;
    private _currWp = currentWaypoint _grp;
    if (_currWp == count waypoints _grp or {_currWp == 0}) then {private _wp =_grp addWaypoint [getPos player,0]};
    [_grp,currentWaypoint _grp] setWaypointPosition [player,0];
    if (isNil {_grp getVariable "timer"}) then {
      _grp setVariable ["timer",diag_tickTime];
      _grp spawn {
        waitUntil {diag_tickTime > (_this getVariable "timer") + 180}; // for 3 minutes. Set as you want
        _this forgetTarget player;
        _this setVariable ["timer",nil]
      };
    };
  }; 
}];

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Alright, thanks for the help guys very much appreciated, making progress. But as a self described half-wit who can't code I'm still having some issues.

Using just what @Erwin23p suggested without editing the code otherwise the group seems to autoupdate no matter what, regardless of the detection state. I've played with inserting the "if (_ReconTeams knowsAbout player > 1) then" in a few different spots:

while {true} do    {
hint"WP ReconTeam updated";
{
        if (east knowsAbout player > 3) then
	deleteWaypoint [_x, 0];	
	_waypoint1 = _x addWaypoint [(player getpos [115,45]),0];	
	_waypoint1 setWaypointType "MOVE";//SAD MOVE
	_x setCombatMode "RED";
	_x setSpeedMode "FULL";
	_x allowFleeing 0;	
		}foreach [_ReconTeams];
        sleep 10;
 };

It will just auto update to the player location on whatever I set the timing of the sleep command to. (note I'm using east vs a specified group so ideally any east/opfor unit spotting the player will direct this group to this location. Think of it as a specific group tasked with hunting the player group down, directed by any other opfor forces intel)

 

I have also attempted to use @pierremgi code but while I get no RPT errors it doesn't seem to update the groups directed waypoint once the player has been detected again/at a new location. They seem to head to the first location and then stay put. 

 

if (east knowsAbout player > 0) then
{
_ReconTeams addEventHandler ["KnowsAboutChanged", { 
  params ["_grp", "_target", "_newKA","_oldKA"]; 
  if (_target == vehicle player && _newKA > 1.5 ) then {
    private _currWp = currentWaypoint _grp;
    if (_currWp == count waypoints _grp or {_currWp == 0}) then {private _wp =_grp addWaypoint [getPos player,0]};
    [_grp,currentWaypoint _grp] setWaypointPosition [player,0];
    if (isNil {_grp getVariable "timer"}) then {
      _grp setVariable ["timer",diag_tickTime];
      _grp spawn {
        waitUntil {diag_tickTime > (_this getVariable "timer") + 5}; // for 3 minutes. Set as you want
        _this forgetTarget player;
        _this setVariable ["timer",nil]
      };
    };
  }; 
}];
};

I'm so close but I'm missing whatever the magic is to get these updates to trigger only upon redetection. I've played with setting the timer at different values the "5" is just the latest in making sure that wasn't my issue. I've also tested it just using the code as is above, removing the "if (east knowsAbout player > 0) then" portion and relevant bracket, to no real difference.

 

Share this post


Link to post
Share on other sites

if (east knowsAbout player > 0) then.... You don't need that.

 

2 hours ago, gfresco said:

 

I have also attempted to use @pierremgi code but while I get no RPT errors it doesn't seem to update the groups directed waypoint once the player has been detected again/at a new location. They seem to head to the first location and then stay put.

 

I tested this code and it works; It can take a long time to make the AIs move again. So, add the allowFleeing command, set the timer to 30 sec (not less) and condition _newKA > 1 instead of 1.5 (more reactive with lower value)
 

_ReconTeams allowFleeing 0;
_ReconTeams addEventHandler ["KnowsAboutChanged", {  
  params ["_grp", "_target", "_newKA","_oldKA"];  
  if (_target == vehicle player && _newKA > 1 ) then {
    private _currWp = currentWaypoint _grp;
    if (_currWp == count waypoints _grp or {_currWp == 0}) then {private _wp =_grp addWaypoint [getPos player,0]};
    [_grp,currentWaypoint _grp] setWaypointPosition [player,0];
    if (isNil {_grp getVariable "timer"}) then {
      _grp setVariable ["timer",diag_tickTime];
      _grp spawn {
        waitUntil {diag_tickTime > (_this getVariable "timer") + 30};
        _this forgetTarget player;
        _this setVariable ["timer",nil]
      };
    };
  };  
}];

 

Marker & KA test (if needed):
_ReconTeams spawn {private _mk = createMarker [str random 1, getpos leader _this]; _mk setMarkerType "mil_dot"; _mk setMarkerColor "colorRed"; while {true} do {sleep 1; _mk setMarkerpos getpos leader _this; hintSilent str (_this knowsAbout player)}}

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

×