(SOLVED) Looking into using ZScript over DECORATE.

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
User avatar
Goldenflare5643
Posts: 122
Joined: Sat Oct 08, 2016 9:20 pm
Location: One of those stupid 2fort daycare servers

(SOLVED) Looking into using ZScript over DECORATE.

Post by Goldenflare5643 »

I know various code languages, including C++,the language ZScript is based on. But I need only one thing to start.
When I got into using DECORATE I would reference the wiki and the demonstrations of code there, I looked for a demonstration for ZScript and came back empty handed. Would somebody post the imp's code here but converted to entirely ZScript? It would make getting used to ZScript a lot easier.
~Thanks.
Last edited by Goldenflare5643 on Thu May 10, 2018 8:17 pm, edited 1 time in total.
User avatar
Mikk-
Posts: 2274
Joined: Tue Jun 30, 2009 1:31 pm

Re: Looking into using ZScript over DECORATE.

Post by Mikk- »

Either GZDoom's Github or gzdoom.pk3 that comes with the .exe has all of the actor defintions for reference.

Here's the imp's code in ZScript
User avatar
Goldenflare5643
Posts: 122
Joined: Sat Oct 08, 2016 9:20 pm
Location: One of those stupid 2fort daycare servers

Re: Looking into using ZScript over DECORATE.

Post by Goldenflare5643 »

Mikk- wrote:Either GZDoom's Github or gzdoom.pk3 that comes with the .exe has all of the actor defintions for reference.

Here's the imp's code in ZScript
This is perfect thank you! I am familiar with DECORATE already so how hard could the be?
Spoiler:
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Looking into using ZScript over DECORATE.

Post by ramon.dexter »

Zscript is not that hard. You just have to know you can modify the inside mechanics of engine.

Here is an example of duke nukem styled item - powerup that could be activated and deactivated.

Code: Select all

class NightEyeDevice : CustomInventory //23048
{
	int nighEyeSwitch;

	Default
	{
		//$Category "Items"
		//$Color 9
		//$Title "Night-Eye Device"
		
		-Solid
		+inventory.invbar
		+inventory.AlwaysPickup
		
		radius 12;
		height 24;
		scale 0.5;
		Tag "$T_NGHTEYE";
		inventory.icon "I_NEDV";
		inventory.amount 100;
		inventory.maxamount 300;
		inventory.interhubamount 300;
		inventory.PickupMessage "$NGHTEYEFND";
	}
	
	States
	{
		Spawn:
			NEDV V -1;
			Stop;

		Use: 
			TNT1 A 0
			{
				if(invoker.nighEyeSwitch == 0) {return ResolveState("Activate");}
				if(invoker.nighEyeSwitch == 1) {return ResolveState("Deactivate");}
				return ResolveState(null);
			}
			Stop;
		Activate:
			TNT1 A 0
			{
				invoker.nighEyeSwitch = 1;
				A_Giveinventory("LanternActive", 1);
			}
			Stop;
		Deactivate:
			TNT1 A 0
			{
				invoker.nighEyeSwitch = 0;
				A_TakeInventory("PowerLantern", 1);
				A_TakeInventory("LanternActive", 1);
			}
			Stop;
	}

}


//==--------------------------------------------------------------------------==
//mechanics
//==--------------------------------------------------------------------------==
class PowerLantern : PowerTorch //PowerLightAmp
{
	int lantern_tics; 

    override void attachtoowner(actor user)
    {
        lantern_tics = 0;
        super.attachtoowner(user);
    }

    override void doeffect()
    {
		Super.doEffect();
		
		if(owner.countinv("NightEyeDevice") <= 1) 
        {
            owner.takeinventory("LanternActive", 1);
			self.destroy();
			return;
		}

        lantern_tics++;

        if(lantern_tics == 70)
        {
            owner.takeinventory("NightEyeDevice", 1);
            lantern_tics = 0;
        }

    }
	
	Default
	{
		powerup.Duration 0x7FFFFFFD;
		powerup.color "6fef67", 0.05;
		//inventory conf
		//==--------------------------
		Inventory.Icon "A_NEDV";
		//==--------------------------
	}
}

class LanternActive : PowerupGiver
{
	Default
	{
		//flags
		//==--------------------------
		+INVENTORY.AUTOACTIVATE;
		+INVENTORY.FANCYPICKUPSOUND;
		//==--------------------------
		//powerup conf
		//==--------------------------
		powerup.Duration 0x7FFFFFFD;
		powerup.Type "PowerLantern";
		//==--------------------------
		//inventory conf
		//==--------------------------
		Inventory.MaxAmount 1;
		Inventory.UseSound "pickups/slowmo";
		//==--------------------------
	}
	
	States
	{
		Spawn:
			TNT1 A 0;
			Stop;
	}

}
Note the function overrides. That is impossible in DECORATE.
User avatar
Goldenflare5643
Posts: 122
Joined: Sat Oct 08, 2016 9:20 pm
Location: One of those stupid 2fort daycare servers

Re: Looking into using ZScript over DECORATE.

Post by Goldenflare5643 »

ramon.dexter wrote:Zscript is not that hard. You just have to know you can modify the inside mechanics of engine.

Here is an example of duke nukem styled item - powerup that could be activated and deactivated.

Code: Select all

class NightEyeDevice : CustomInventory //23048
{
	int nighEyeSwitch;

	Default
	{
		//$Category "Items"
		//$Color 9
		//$Title "Night-Eye Device"
		
		-Solid
		+inventory.invbar
		+inventory.AlwaysPickup
		
		radius 12;
		height 24;
		scale 0.5;
		Tag "$T_NGHTEYE";
		inventory.icon "I_NEDV";
		inventory.amount 100;
		inventory.maxamount 300;
		inventory.interhubamount 300;
		inventory.PickupMessage "$NGHTEYEFND";
	}
	
	States
	{
		Spawn:
			NEDV V -1;
			Stop;

		Use: 
			TNT1 A 0
			{
				if(invoker.nighEyeSwitch == 0) {return ResolveState("Activate");}
				if(invoker.nighEyeSwitch == 1) {return ResolveState("Deactivate");}
				return ResolveState(null);
			}
			Stop;
		Activate:
			TNT1 A 0
			{
				invoker.nighEyeSwitch = 1;
				A_Giveinventory("LanternActive", 1);
			}
			Stop;
		Deactivate:
			TNT1 A 0
			{
				invoker.nighEyeSwitch = 0;
				A_TakeInventory("PowerLantern", 1);
				A_TakeInventory("LanternActive", 1);
			}
			Stop;
	}

}


//==--------------------------------------------------------------------------==
//mechanics
//==--------------------------------------------------------------------------==
class PowerLantern : PowerTorch //PowerLightAmp
{
	int lantern_tics; 

    override void attachtoowner(actor user)
    {
        lantern_tics = 0;
        super.attachtoowner(user);
    }

    override void doeffect()
    {
		Super.doEffect();
		
		if(owner.countinv("NightEyeDevice") <= 1) 
        {
            owner.takeinventory("LanternActive", 1);
			self.destroy();
			return;
		}

        lantern_tics++;

        if(lantern_tics == 70)
        {
            owner.takeinventory("NightEyeDevice", 1);
            lantern_tics = 0;
        }

    }
	
	Default
	{
		powerup.Duration 0x7FFFFFFD;
		powerup.color "6fef67", 0.05;
		//inventory conf
		//==--------------------------
		Inventory.Icon "A_NEDV";
		//==--------------------------
	}
}

class LanternActive : PowerupGiver
{
	Default
	{
		//flags
		//==--------------------------
		+INVENTORY.AUTOACTIVATE;
		+INVENTORY.FANCYPICKUPSOUND;
		//==--------------------------
		//powerup conf
		//==--------------------------
		powerup.Duration 0x7FFFFFFD;
		powerup.Type "PowerLantern";
		//==--------------------------
		//inventory conf
		//==--------------------------
		Inventory.MaxAmount 1;
		Inventory.UseSound "pickups/slowmo";
		//==--------------------------
	}
	
	States
	{
		Spawn:
			TNT1 A 0;
			Stop;
	}

}
Note the function overrides. That is impossible in DECORATE.
I realized this when I took a look at the ZScript wiki page, it immediately struck me as some sort of C++ adaption. I just use a bit of code off to the side as a troubleshooting template. Also I wanted to use ZScript in the first place because it does more things then DECORATE, like overriding things as you said, Thanks guys!
Post Reply

Return to “Scripting”