ZScript Console Print for only 1 Player in coop

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
peewee_RotA
Posts: 364
Joined: Fri Feb 07, 2014 6:45 am

ZScript Console Print for only 1 Player in coop

Post by peewee_RotA »

I am having a lot of trouble making heads or tails of all of the console print commands. I just want to print a string to the screen of one player if I have a reference to their actor. For example in TakeSpecialDamage I have the source actor, and I want to print a message only to that player's screen.

Pretty much only the ACS versions of print commands are fully documented. The majority of all printing to the screen (like item pickups) seems to be behind native functions, and the remaining examples are in the StatusBar code and seem to be a dead end. All of the existing versions of Print I can find print to all players in the coop game. So I'm wondering if there is any resource anywhere that explains how the console print commands work in ZSCRIPT and how they can be scoped only to a single actor (if that actor is a player of course)

Here's the code snippet so far:

Code: Select all

const SNEAK_ATTACK_BONUS = 3.0;
class MyBaseMonsterClass : Actor
{
...
	override int TakeSpecialDamage(Actor inflictor, Actor source, int damage, Name damagetype)
	{
		let hereticPlayer = CustomPlayerClass(source);
		if (hereticPlayer)
		{
			//Sneak attack
			if (target != hereticPlayer)
			{
				damage *= SNEAK_ATTACK_BONUS;
				Console.Printf("Surprise Attack!"); //Want this to print only to the hereticPlayer actor
					
				sneakDelay = 0;
			}
		}
		
		return Super.TakeSpecialDamage(inflictor, source, damage, damagetype);
	}	
...
}
Jarewill
 
 
Posts: 1766
Joined: Sun Jul 21, 2019 8:54 am

Re: ZScript Console Print for only 1 Player in coop

Post by Jarewill »

ZScript can also make use of DECORATE's A_Print functions.
You can try using this:

Code: Select all

source.A_Print("Surprise Attack!");
This will make the source actor use the A_Print function, printing a text on their screen.
peewee_RotA
Posts: 364
Joined: Fri Feb 07, 2014 6:45 am

Re: ZScript Console Print for only 1 Player in coop

Post by peewee_RotA »

Awesome! Thanks!
Post Reply

Return to “Scripting”