Make an actor stay within the radius of a player?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
Epōllon
Posts: 3
Joined: Thu Jul 12, 2018 4:24 pm

Make an actor stay within the radius of a player?

Post by Epōllon »

Hi, I am currently working on a marine ally actor which fights alongside you, the problem is that they generally run directly into large groups of monsters without the logic of a player, and as a result die easily. Is there any way to implement code in DECORATE that would make the actor always stay within a radius of the player?
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Make an actor stay within the radius of a player?

Post by Void Weaver »

Definetily yes, but it depends on pointers relations between player nd mrine lly.

For ex. in cse if that marine is player's friendly summon (lets assume tht it was spwned via A_SpawnItemEx(0,0,0,0,0,0,0,SXF_SETMSTER)) then mke some check longside of its See stte:

Code: Select all

States
{
See:
TNT1 A 0 A_Chase
ABCD AA 1 
{
If(GetDistance(1,AAPTR_MASTER)>Radius+1024)
    {
    A_ClerTarget //Optionlly
    Return A_Warp(AAPTR_MASTER,frandom(-Radius,Radius));
    }
Else{Return state("");}
}
TNT1 A 0 A_Chase
ABCD BB 1
{
If(GetDistance(1,AAPTR_MASTER)>Radius+1024)
    {
    A_ClerTarget //Optionlly
    Return A_Warp(AAPTR_MASTER,frandom(-Radius,Radius));
    }
Else{Return state("");}
}
TNT1 A 0 A_Chase
ABCD CC 1
{
If(GetDistance(1,AAPTR_MASTER)>Radius+1024)
    {
    A_ClerTarget //Optionlly
    Return A_Warp(AAPTR_MASTER,frandom(-Radius,Radius));
    }
Else{Return state("");}
}
TNT1 A 0 A_Chase
ABCD DD 1
{
If(GetDistance(1,AAPTR_MASTER)>Radius+1024)
    {
    A_ClerTarget //Optionlly
    Return A_Warp(AAPTR_MASTER,frandom(-Radius,Radius));
    }
Else{Return state("");}
}
Loop
Epōllon
Posts: 3
Joined: Thu Jul 12, 2018 4:24 pm

Re: Make an actor stay within the radius of a player?

Post by Epōllon »

Void Weaver wrote:Definetily yes, but it depends on pointers relations between player nd mrine lly.

For ex. in cse if that marine is player's friendly summon (lets assume tht it was spwned via A_SpawnItemEx(0,0,0,0,0,0,0,SXF_SETMSTER)) then mke some check longside of its See stte:

Code: Select all

States
{
See:
TNT1 A 0 A_Chase
ABCD AA 1 
{
If(GetDistance(1,AAPTR_MASTER)>Radius+1024)
    {
    A_ClerTarget //Optionlly
    Return A_Warp(AAPTR_MASTER,frandom(-Radius,Radius));
    }
Else{Return state("");}
}
TNT1 A 0 A_Chase
ABCD BB 1
{
If(GetDistance(1,AAPTR_MASTER)>Radius+1024)
    {
    A_ClerTarget //Optionlly
    Return A_Warp(AAPTR_MASTER,frandom(-Radius,Radius));
    }
Else{Return state("");}
}
TNT1 A 0 A_Chase
ABCD CC 1
{
If(GetDistance(1,AAPTR_MASTER)>Radius+1024)
    {
    A_ClerTarget //Optionlly
    Return A_Warp(AAPTR_MASTER,frandom(-Radius,Radius));
    }
Else{Return state("");}
}
TNT1 A 0 A_Chase
ABCD DD 1
{
If(GetDistance(1,AAPTR_MASTER)>Radius+1024)
    {
    A_ClerTarget //Optionlly
    Return A_Warp(AAPTR_MASTER,frandom(-Radius,Radius));
    }
Else{Return state("");}
}
Loop
Thanks, I will either implement this or maybe have the ally check the distance from player at the end of the see state, and clear targets if so, so they return to the player automatically.
Post Reply

Return to “Scripting”