Jump to content
Sign in to follow this  
Stalkarn

Trying do make enemy hunt player script.

Recommended Posts

[sOLVED] Look at my last post for the result!

I'm trying to make a script to make an enemy group hunt the player group.

I ran in to some problems and need help with the code.

This is the script:

_hunter = _this select 0;
_hunted = _this select 1;
_nfound = 1;				


testplayer sideChat "add waypoint";
_wp = _hunter addWaypoint [getPos _hunted, 0,(currentWaypoint _hunter)];
hintsilent format ["hunter: %1",_hunter];
testplayer sideChat "waypoint added";

while(_nfound) {
hint "in while";
if (((leader _hunted) distance (leader _hunter)) > 250) then
{
hint "in if";
_wp = _hunter addWaypoint [position _hunted, 0,((currentWaypoint _hunter))];
sleep 30;
};

else
{
hint "in else";
_wp = _hunter addWaypoint [position _hunted, 0,((currentWaypoint _hunter) +1)];
[_hunter, ((currentWaypoint _hunter) +1)] setWaypointType "TR UNLOAD";
_nfound = 0;
};

};

and to use it I have two groups:

"hunter = group this"

and

"hunted = group this"

I execute the code in a trigger to make them chase the player when they are detected and the trigger works.

to execute the script I use this in on act:

hnt = [hunter, hunted] execVM "hunterscript.sqf";

I only get to line 6 and the test player says "add waypoint" in the game. This is just a printf to show where in my code I am (for testing).

The reason I says getPos on line 7 is because I had "position" but wanted to try to see if I had to use getPos even thoug they do the same thing.

Any ideas what I'm doing wrong?

Edited by Stalkarn

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Hello again!

I'm sorry I missed the sticky about -showScriptErrors! That helpt me find my problems and fix them.

The biggest reason that I wannted help was because I want to learn to script for this game.

The second reason was to get it to work. Or maybe they are equal:-)

Anyway, I made the script work so to make this post not be in vain I will post my script here and feel free to use it if you want.

What it does:

When a trigger is triggered and executes this script a group will start to hunt the player. They will first go to the position where the player or target group last was "seen".

Then they will continue to hunt for the group. When they are within 350 metres (if it is not feet the command distance give) they will get out of the vehicle if they are in one and start seek and destroy at player position.

To make it work:

1. Create a group to be the hunting group and name it. e.g. Create group --> grp1 = group this; // "grp = group this;" should go in the init field of the group leader.

Note: grp1 is the name of the group.

2. Create a group to be hunted/chased. Same way as above.

3. Create a trigger and make it trigger the way you want. E.g make it trigger when the group to be hunted is detected by enemy side.

4. In the trigger "On Act:" write this:

nul = [hunter, hunted, 2] execVM "nameOfFile.sqf";

Note: Replace hunter with the name of the group that is hunting and replace hunted with the group name of the hunted group and replace 2 with the number of waypoints you already have given the hunter group. Btw, I think you can type what ever you want instead of "nul".

5. Make a file in your favorite text editor and paste in this code:

_hunter = _this select 0;
_hunted = _this select 1;
_nrwaypt = _this select 2;
_nfound = true;				
_running = true;

sleep 3;
testplayer sideChat format ["Number of waypoints: %1",  _nrwaypt];

_wp = _hunter addWaypoint [(position (leader _hunted)), 0,currentWaypoint _hunter +1];
sleep 15;

while {_running} do
{
if((currentWaypoint _hunter) > (_nrwaypt + 1)) then {  //If hunter has arived where hunted was detected (this trigger triggered..)
   sleep 5;    // Simulate they are investigating the area
while {_nfound} do {

	if (((leader _hunted) distance (leader _hunter)) > 350) then
	{

	// Hunter heading for hunteds current position
	_wp = _hunter addWaypoint [position (leader _hunted), 0,((currentWaypoint _hunter))]; 
	sleep 30; // To update hunteds position every 30 seconds.
	}

	else  // If hunter is withing 350 metres of hunted
	{

	/*
	Make the hunter group disembark and then make a "SEEK AND DESTROY" waypoint at hunteds 
	current position. This is the last step in the hunting prosses. If they don't find you now they loose you, or
	you killed them :-)		
	*/
	_wp = _hunter addWaypoint [position (leader _hunter), 0,((currentWaypoint _hunter))];
	[_hunter, (currentWaypoint _hunter)] setWaypointType "GETOUT";
	sleep 5;
	_wp = _hunter addWaypoint [position (leader _hunted), 0,((currentWaypoint _hunter) +1)];
	[_hunter, ((currentWaypoint _hunter) +1)] setWaypointType "SAD";
	_nfound = false;   // Get out of while-loop
	_running = false;  // Get out of while-loop
	}

}
}
}

Save the file as .sqf

6. Place the file in your mission folder.

7. Try it.

And finally, if you have problems or comments on the script feel free to ask!

I have probably missted out on some important things like exit the script or something but I will look in to that to morrow.

Regards!

Share this post


Link to post
Share on other sites

Hey,

I'm really new to the Arma series and to the whole scripting. I have clocked only 158 hours in Arma 3 yet.

What I'm trying to do is create a missions where a small demolitions diver team insert by SDV to the objective. What I want is an Assault boat diver team to patrol the area and if they detect the SDV they will disembark and attack the SDV.

Your script works fine with land units but I have a hard time to make it work with the scenario. Using only your script, the patrol just reacts to the trigger and then just speeds away from the SDV without disembarking the divers.

I have tried with the patrol team to "get in" an empty assault boat. I have tried to change your script so the "get out" is "TR Unload" so the assault boat would drop the divers near the SDV.

Thx for the help, your script will be a part in many of my missions.

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  

×