[help] trying to make friendlies not harm player/s

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
orosa
Posts: 68
Joined: Mon Sep 30, 2013 11:37 pm

[help] trying to make friendlies not harm player/s

Post by orosa »

Hey all, newbie question here, recently I downloaded something from the 667 repository site, The "beacon" file.

Anyway, it spawns in marines that basically walk and shot. Nothing crazy. But I've been trying to modify it to make it not harm the player, for a little while now, and I have had no luck in doing so. Basically, what I am asking is what am I missing/doing wrong. here is my code for 2 different marines.

Code: Select all

ACTOR MarineShotgunFriend : MarineShotgun
{
	Health 500
	MONSTER
	+MISSILEEVENMORE
	+NORADIUSDMG
	+QUICKTORETALIATE
	+FLOORCLIP
	+FRIENDLY
	
	+THRUSPECIES
	+MTHRUSPECIES
	+ALLOWTHRUFLAGS
		
	+NODAMAGE
	+DONTHARMCLASS
	Species "doomplayer"
	DropItem "NewShotgun"
	States
   {
   Spawn:
      PLAY ABCD 5 A_Wander
	  PLAY ABCD 0 A_Look
      Loop
	}
}

Code: Select all

ACTOR MarineRocketFriend : MarineRocket
{
	Health 500
	MONSTER
	+MISSILEEVENMORE
	+NORADIUSDMG
	+QUICKTORETALIATE
	+FLOORCLIP
	+FRIENDLY
	
	+THRUSPECIES
	+MTHRUSPECIES
	+ALLOWTHRUFLAGS
		
	+NODAMAGE
	+DONTHARMCLASS
	Species "doomplayer"	
	
	DropItem "NewRL"
	States
   {
   Spawn:
      PLAY ABCD 5 A_Wander
	  PLAY ABCD 0 A_Look
      Loop
	}
}
and knowing me it probably one flag that I miss..... or I am going about this very very wrong.
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: [help] trying to make friendlies not harm player/s

Post by Cherno »

I don't think it can be done this easily in DECORATE. You could give the Marines attacks with a DamageType for which the Player has a DamageFactor of 0. In zScript, you could simply override DamageMobj and check of the source of the attack has the FRIENDLY flag set to true.
orosa
Posts: 68
Joined: Mon Sep 30, 2013 11:37 pm

Re: [help] trying to make friendlies not harm player/s

Post by orosa »

I fiddled around with this for a few days and had no luck. Thanks for the help anyway Cherno. But I think I am going to leave it as is.
User avatar
Caligari87
Admin
Posts: 6236
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: [help] trying to make friendlies not harm player/s

Post by Caligari87 »

Could cast a non-damaging lineattack and see if the puff returns a player, and if so abort the attack sequence. would be easier in zscript but possible with some hackery in DECORATE.

8-)
orosa
Posts: 68
Joined: Mon Sep 30, 2013 11:37 pm

Re: [help] trying to make friendlies not harm player/s

Post by orosa »

i will have a look into line attack, in the meantime how would I go about it in zscript?
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: [help] trying to make friendlies not harm player/s

Post by Cherno »

You'd need a zScript PlayerPawn. gzdoom.pk3 has zScript versions of all playerclasses. Check the wiki to use custom playerclasses and how to load zScript files.
https://zdoom.org/wiki/ZScript
https://zdoom.org/wiki/Creating_new_player_classes
Join the Discord if you need help 8-)

Add this to the Player class:

Code: Select all

	override int DamageMobj(Actor inflictor, Actor source, int damage, Name mod, int flags, double angle)
	{
               if(source != null && source.bFRIENDLY)
                {
                     return Super.DamageMobj(inflictor,source,0,mod,flags,angle);
                }
		return Super.DamageMobj(inflictor,source,damage,mod,flags,angle);
	}
User avatar
Caligari87
Admin
Posts: 6236
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: [help] trying to make friendlies not harm player/s

Post by Caligari87 »

Two clarify, there's two separate approaches being discussed here.

1. Skip damaging the player if a friendly attack hits the player
2. prevent the monster from attacking if the player is in the way (my suggestion)

Here's some (untested!) code for how I'd implement #2

Code: Select all

class FriendlySmartImp : DoomImp {
	default {
		+Friendly;
	}
	
	states {
		missile:
			TROO EF 8 A_FaceTarget(0, 0, 0, 0, FAF_MIDDLE);
			TROO G 3 A_TargetCheck;
			TROO G 3 A_TroopAttack;
			Goto See;
		skipmissile:
			TROO FE 6;
			goto See;
	}
	
	action state A_TargetCheck() {
		FLineTraceData tracedata
		linetrace(angle, 1024, pitch, offsetz: height/2, data: tracedata);
		if (tracedata.hitactor is playerpawn) { return ResolveState("skipmissile");
		return null;
	}
}
In short, a custom action function that sends a line trace from the imp's angle/pitch and checks if it hits a playerpawn, then if so jumps to a cancellation state, otherwise the attack continues normally.

8-)
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: [help] trying to make friendlies not harm player/s

Post by Apeirogon »

Did you try to set player pawn species to "doomplayer"?
Because IIRC by default its "none".
User avatar
Caligari87
Admin
Posts: 6236
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: [help] trying to make friendlies not harm player/s

Post by Caligari87 »

This checks player class hierarchy, not species.

8-)
orosa
Posts: 68
Joined: Mon Sep 30, 2013 11:37 pm

Re: [help] trying to make friendlies not harm player/s

Post by orosa »

sorry for the late response, I been working on this for quite a while now, and I still not getting anywhere I might come back to this in a few weeks and try again with a more fresh mind sorry for bugging everyone.
Post Reply

Return to “Scripting”