Custom Action function using ZScript

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
Heretic_Crossbowman
Posts: 10
Joined: Sat May 11, 2019 3:50 pm

Custom Action function using ZScript

Post by Heretic_Crossbowman »

Hi all! I'm new to scripting so forgive me for stupid questions )
I' ve tried to do some things with DECORATE and then went to try something with ZScript.
So my question is: how can i create some custom Action function in ZScript to use it when creating something in DECORATE?
For example, i need to create action that spawns 6 projectiles around some point and call it A_ManyProjectiles to use it somewhere.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Custom Action function using ZScript

Post by Void Weaver »

Which specific "some point" is supposed to be?
Who is supposed to be the f-tion caller?
Because in some cases the similar task can be executed entirely on decorate via anonymous function feature.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49246
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Custom Action function using ZScript

Post by Graf Zahl »

You have to define a subclass of Actor where you can define your functions, then derive everything you want these functions to use from that subclass.
Heretic_Crossbowman
Posts: 10
Joined: Sat May 11, 2019 3:50 pm

Re: Custom Action function using ZScript

Post by Heretic_Crossbowman »

Void Weaver wrote:Which specific "some point" is supposed to be?
Who is supposed to be the f-tion caller?
Because in some cases the similar task can be executed entirely on decorate via anonymous function feature.
That's just for example, but in that case i want to create a function that will produce few "shards" like an Heretic's Lich Ice Ball (when it hits something it explodes and 8 shards appear around it).
I haven't found something similar to it in decorate but i found IronLich class written in ZScript and here was the thing i want. But i don't want use ZSCript for everything in my project and i prefer to use it only where Decorate can't help. )
Heretic_Crossbowman
Posts: 10
Joined: Sat May 11, 2019 3:50 pm

Re: Custom Action function using ZScript

Post by Heretic_Crossbowman »

Graf Zahl wrote:You have to define a subclass of Actor where you can define your functions, then derive everything you want these functions to use from that subclass.
Thanks, but can You explain a bit?
So here is my example (just example)
1. I want to replace Heretic's ophidian projectile with explosive one and i create actor in decorate
Spoiler:
2. Because function A_OphBallShard doesn't exist, i need to create it
3. So i use ZScript and have this code (it was taken from IronLich class; ice shards replaced by BeastBall)
Spoiler:
So, how to link that with decorate? Which class should i create?
*and another one question about that: what exactly does string shard.target = target? As i read in ZDoom wiki it's a pointer which says that creator of initial projectile is a target for shard, so these shards don't damage player but they damage monsters. And when i removed that string everything was right and shards now damage everything )
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Custom Action function using ZScript

Post by Void Weaver »

Heretic_Crossbowman wrote:
Spoiler:
That's just for example, but in that case i want to create a function that will produce few "shards" like an Heretic's Lich Ice Ball (when it hits something it explodes and 8 shards appear around it).
I haven't found something similar to it in decorate but i found IronLich class written in ZScript and here was the thing i want. But i don't want use ZSCript for everything in my project and i prefer to use it only where Decorate can't help. )
Sooo, do you want to replicate A_LichIceImpact behaviour? Easy:
Image Image

Var 1 (shorter and easy for adjusting but less compatible because uses uservar):

Code: Select all

Actor DB : DoomImpBall replaces DoomImpBall
{

var float user_MAngle;

States
{
Death:
    BAL1 C 6 Bright
    BAL1 D 6 Bright 
	{
	For(A_SetUserVarFloat(user_MAngle,0); user_MAngle<360; A_SetUserVarFloat(user_MAngle,user_MAngle+45))
        {
            A_SpawnItemEx("HeadFX2",0,0,Height/2,8,0,-0.6,user_MAngle,SXF_NOCHECKPOSITION);
        }
	}
    BAL1 E 6 Bright
    Stop
}
}
Var 2 (longer but more compatible because without uservar):

Code: Select all

Actor DB : DoomImpBall replaces DoomImpBall
{
States
{
Death:
    BAL1 C 6 Bright
    BAL1 D 6 Bright 
	{
	A_SpawnItemEx("HeadFX2",0,0,Height/2,8,0,-0.6,0,SXF_NOCHECKPOSITION);
	A_SpawnItemEx("HeadFX2",0,0,Height/2,8,0,-0.6,45,SXF_NOCHECKPOSITION);
	A_SpawnItemEx("HeadFX2",0,0,Height/2,8,0,-0.6,90,SXF_NOCHECKPOSITION);
	A_SpawnItemEx("HeadFX2",0,0,Height/2,8,0,-0.6,135,SXF_NOCHECKPOSITION);
	A_SpawnItemEx("HeadFX2",0,0,Height/2,8,0,-0.6,180,SXF_NOCHECKPOSITION);
	A_SpawnItemEx("HeadFX2",0,0,Height/2,8,0,-0.6,225,SXF_NOCHECKPOSITION);
	A_SpawnItemEx("HeadFX2",0,0,Height/2,8,0,-0.6,270,SXF_NOCHECKPOSITION);
	A_SpawnItemEx("HeadFX2",0,0,Height/2,8,0,-0.6,315,SXF_NOCHECKPOSITION);
	}
    BAL1 E 6 Bright
    Stop
}
}
Heretic_Crossbowman
Posts: 10
Joined: Sat May 11, 2019 3:50 pm

Re: Custom Action function using ZScript

Post by Heretic_Crossbowman »

Void Weaver wrote:
Heretic_Crossbowman wrote:
Spoiler:
That's just for example, but in that case i want to create a function that will produce few "shards" like an Heretic's Lich Ice Ball (when it hits something it explodes and 8 shards appear around it).
I haven't found something similar to it in decorate but i found IronLich class written in ZScript and here was the thing i want. But i don't want use ZSCript for everything in my project and i prefer to use it only where Decorate can't help. )
Sooo, do you want to replicate A_LichIceImpact behaviour? Easy:

Thanks, that will be helpful )
But maybe i don't explain what i want correctly (sorry for bad english ). Whole question is how to create a part of code in ZScript (in that case - lich ball explosion, but this is just for example) and give it a name like A_MyAction for further use in DECORATE. Maybe i want to make few different projectiles with this explosive effect but i don't want to code each of them in ZScript. :)
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Custom Action function using ZScript

Post by Matt »

Base actor to inherit from:

Code: Select all

class yourmodactor:actor{
    void A_MugwumpAttack(){
        //the attack functions here
        ...
    }
} 
and your Decorate (if you really want to do this instead of just ZScript all the way):

Code: Select all

actor mugwump:yourmodactor{
    ...
    states{
    ...
    missile:
        MUGW EF 3 A_FaceTarget
        MUGW G 7 A_MugwumpAttack
        goto see
    }
} 
Heretic_Crossbowman
Posts: 10
Joined: Sat May 11, 2019 3:50 pm

Re: Custom Action function using ZScript

Post by Heretic_Crossbowman »

Matt wrote:Base actor to inherit from:

Code: Select all

class yourmodactor:actor{
    void A_MugwumpAttack(){
        //the attack functions here
        ...
    }
}
and your Decorate (if you really want to do this instead of just ZScript all the way):

Code: Select all

actor mugwump:yourmodactor{
    ...
    states{
    ...
    missile:
        MUGW EF 3 A_FaceTarget
        MUGW G 7 A_MugwumpAttack
        goto see
    }
}
So, as i understand, in that example class "yourmodactor" inherits from actor, than we create void A_MugwumpAttack inside that class and then we create another class in DECORATE that inherits from our ZScript class? And there is no way to create custom function for use with decorate like any other action function like A_Face target that we can use inside any actor we create?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Custom Action function using ZScript

Post by Matt »

That is correct.

There was some talk about being able to go back and add functions to Actor but IIRC there were some really important technical reasons (that I forgot the details of) that would block this development for the foreseeable future.
Heretic_Crossbowman
Posts: 10
Joined: Sat May 11, 2019 3:50 pm

Re: Custom Action function using ZScript

Post by Heretic_Crossbowman »

Thanks you all guys )))
Post Reply

Return to “Scripting”