Micromanaging the AI

  1. 8 years ago

    Whilst messing around with ideas, I came up with a way to kind of re-create STALKER's "rules." A survival game with few vehicles, gathering supplies, avoiding being killed by enemies, blow outs that change varying zones of lethal radiation, etc.

    So I started putting together the scripts that required the commands and functions I knew the least about which had me start with the zones of radioactivity. These are just randomly placed and sized triggers that deal anywhere from 0.01 to 0.075 points of damage ever tick a unit is inside the zone unless they have some kind of anti-rad protection.

    After getting it all working, I realized that any AI spawned or wandering around won't be aware that they are being killed by the trigger (if they even know they are dying lol). Since I planned on using Alive to generate the AI in the first place, I figure it might help to ask if/how I could keep the OPCOM informed about the zones and tell his units to avoid them and not spawn things in them; it would be even cooler if the OPCOM (and any units he controls holding a radio) only knew about each zone once a unit he controls holding a radio takes X damage from it, so they can spawn/wander in at first, and only once they actually know about the zone will they avoid it.

    The zones not only are placed and sized randomly, but every 30 minutes to 3 hours, they will be deleted and re-created, making once safe areas dangerous and dangerous areas safe once more, so anything I can try to do what I want needs to account for a random number of triggers, but they are conveniently placed into an array.

    If it helps, here's the script I made to generate the zones:

    //This script will spawn random zones of varying levels of radioactivity (slow death zones with varying degrees of how quickly they kill)
    //It is designed to be used with a Blow Out script to re-create the changes of anomalies after such an event in STALKER,
    //but can be used for other things as well. 
    //This particular example is set up for the size of Altis, creating between 10 to 25 zones ranging from 50m to 1.5km in size in a 15,000x15,000 square from the center of the map.
    
    DecayZones = [];
    {deleteVehicle _x;} forEach DecayZones; //"DecayZones" is a global variable defined at init. Either in the init.sqf or from an object's init field from the editor.
    
    _rndZones = [10,25] call BIS_fnc_randomInt;
    for "_i" from 1 to _rndZones do
    {
    	_rndDis = floor (random 15000); //Set the radius to place the markers
    	_rndHead = floor (random 360); //Set the compass bearing to create markers from center point
    	_rndX = [50,750] call bis_fnc_randomInt; //Set the X size of the marker
    	_rndY = [50,750] call bis_fnc_randomInt; //Set the Y size of the marker
    	_rndDir = floor (random 360); //Set the marker's direction, separately from the original compass bearing used to place the marker.
    	_mapPos = [getMarkerPos "MapCenter", _rndDis, _rndHead] call BIS_fnc_relPos; //Set the point from which to create the zones around.
    	_trg = createTrigger ["EmptyDetector", _mapPos];
    	_trg setTriggerArea [_rndX,_rndY, _rndDir, false];
    	_trg setTriggerActivation [ "ANY", "PRESENT", true];
    	_trg setTriggerStatements ["call {if (count thislist > 0) then {{if ((alive _x) && (_x hasGeiger == false)) then {_toxicity = random 0.075; _x setDamage (damage _x + _toxicity)}} forEach thislist};false}", "", ""];
    	DecayZones pushback _trg;	
    };
  2. Edited 8 years ago by PillowTalk

    I found a function that might help, but I can't find the place I would need to put it in one of the ALIVE modules to pass the script to the spawned groups.

    That's still in the addon, right? I can't remember if it was an older module that is now defunct or what.

    EDIT: NVM found it. It was a code snippet on the wiki not a field on a module.

  3. Curious with what you actually used.

  4. Edited 8 years ago by PillowTalk

    Well, the idea was to use BIS_fnc_taskPatrol to add the radiation zones array as it's blacklist, but I don't think I fully understand the function because I pass it to the guys ALIVE is spawning, and they just stand in place forever. The OPCOM can't even control them nor are they actually patrolling. I think I need to give them a waypoint first. Not sure.

    The description of the function sounds like it gives them a bunch of random waypoints in a radius around the starting point and has them walk it (which is fine for this mode; I am only using Alive to generate AI forces as background stuff, so having them randomly patrol instead of fighting over irrelevant objectives is fine with me). The starting point I set is the spawning unit, the radius was 5000m. However, the examples are slightly contradictory. It says I can use it on a unit's init, which is what I am doing basically, but then below that it says it would be better to put it in the on act field of a waypoint.

    I suppose the next thing to try would be giving the spawned unit a waypoint 5m away, setting that waypoint's onact to be the taskPatrol function and see if that helps.

  5. Edited 8 years ago by SpyderBlack723

    Firstly, I would probably disable OPCOM as it's orders might conflict with any given waypoints. Secondly, you might need to disable the ALiVE commands that are given to units such as "Ambient Movement" which uses doMove. After that you might be able to give them reliable-custom waypoints. I'll see if I can get the gather some code tonight and post again.

  6. Edited 8 years ago by SpyderBlack723

    Sorry, forums were down and I forgot about this.
    I'll leave this here for later though

    description.ext:

    class Extended_Init_EventHandlers {
     class Man {
      init = "_this call (compile preprocessFileLineNumbers 'my_script.sqf')";
     };
    };

    my_script.sqf:

    params ["_unit"];
    
    if (side _unit == EAST) then {
    	//-- Clear ambient movement command on the profile
    	[_profile, "clearActiveCommands"] call ALIVE_fnc_profileEntity;
    
    	//-- Clear any waypoints and ambient movement command
    	{
    		[_x, "clearActiveCommands"] call ALIVE_fnc_profileEntity;
    		[_x, "clearWaypoints"] call ALIVE_fnc_profileEntity;
    	} forEach ([getPos player, 100] call ALIVE_fnc_getNearProfiles);
    
    	//-- call your script that executes the BIS_fnc_taskPatrol or call it directly in the script
    	[_unit] call custom_patrol.sqf
    };

    Obviously you an manipulate it however you want, I figured I would include a side check so you could limit it to the enemy side. This should free up ALiVE spawned units for custom movement commands.

    This would only support units spawned in. In theory you could try to have profiles that aren't spawned in still take damage if they come into a toxic area but good lucky trying to make them avoid it.

  7. Since profiled units are not actually on the map, and from the sound of it I can't move them around to avoid the traps, I would just allow them to not take damage while profiled. Adds something to the atmosphere, I think, if you run across a bunch of guys who spawned in the zone and are desperately trying to escape before dying. :D

  8. Just realized this won't work in MP since it needs to be ran on the server and there is no player on the server. If it's not a problem let me know otherwise I'll think of an MP compatible way to do it.

  9. Would just waiting for a player before doing anything else work?

  10. Ok wow im stupid.. change the getPos player to getPos _unit and it should work fine unless I missed something.

  11. Got it. Gonna have to try it later today.

 

or Sign Up to reply!