Custom Action function using ZScript
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!)
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!)
-
- Posts: 10
- Joined: Sat May 11, 2019 3:50 pm
Custom Action function using ZScript
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.
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.
- Void Weaver
- Posts: 724
- Joined: Thu Dec 18, 2014 7:15 am
- Contact:
Re: Custom Action function using ZScript
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.
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.
- Graf Zahl
- Lead GZDoom+Raze Developer
- Posts: 49246
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Custom Action function using ZScript
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.
-
- Posts: 10
- Joined: Sat May 11, 2019 3:50 pm
Re: Custom Action function using ZScript
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).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.
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. )
-
- Posts: 10
- Joined: Sat May 11, 2019 3:50 pm
Re: Custom Action function using ZScript
Thanks, but can You explain a bit?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.
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 )
- Void Weaver
- Posts: 724
- Joined: Thu Dec 18, 2014 7:15 am
- Contact:
Re: Custom Action function using ZScript
Sooo, do you want to replicate A_LichIceImpact behaviour? Easy: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. )


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
}
}
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
}
}
-
- Posts: 10
- Joined: Sat May 11, 2019 3:50 pm
Re: Custom Action function using ZScript
Void Weaver wrote:Sooo, do you want to replicate A_LichIceImpact behaviour? Easy: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. )
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.

- 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
Base actor to inherit from:
and your Decorate (if you really want to do this instead of just ZScript all the way):
Code: Select all
class yourmodactor:actor{
void A_MugwumpAttack(){
//the attack functions here
...
}
}
Code: Select all
actor mugwump:yourmodactor{
...
states{
...
missile:
MUGW EF 3 A_FaceTarget
MUGW G 7 A_MugwumpAttack
goto see
}
}
-
- Posts: 10
- Joined: Sat May 11, 2019 3:50 pm
Re: Custom Action function using ZScript
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?Matt wrote:Base actor to inherit from:and your Decorate (if you really want to do this instead of just ZScript all the way):Code: Select all
class yourmodactor:actor{ void A_MugwumpAttack(){ //the attack functions here ... } }
Code: Select all
actor mugwump:yourmodactor{ ... states{ ... missile: MUGW EF 3 A_FaceTarget MUGW G 7 A_MugwumpAttack goto see } }
- 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
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.
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.
-
- Posts: 10
- Joined: Sat May 11, 2019 3:50 pm
Re: Custom Action function using ZScript
Thanks you all guys )))