"How do I 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: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
This can be done through networked event handlers, if there's no facility for that in menu itself.
Although I think network events are still not synchronized to the world ticks, I'll have to do something about that later and make a PR.
Right now it will fire immediately no matter if the game is paused or not.
Although I think network events are still not synchronized to the world ticks, I'll have to do something about that later and make a PR.
Right now it will fire immediately no matter if the game is paused or not.
-
- Lead GZDoom+Raze Developer
- Posts: 49179
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
There's no need to use event handlers here. Changing inventory can be done with the 'give' and 'take' CCMDs.
Event handlers may be useful if some stuff needs to be done that isn't supported by the stock protocol.
About synchronization - if the command is routed through the network one should assume that the receiving end knows what to do and if it executes the command immediately, that should be ok. The important thing is that it's the network that does the manipulation on the play side to ensure that things remain synchronized and we have a recordable and transferrable network stream. But it should make the particular use case here easier to handle.
And thinking about it, type 'kill' into the console. The screen will turn red immediately, suggesting that the network command is executed without delay.
Event handlers may be useful if some stuff needs to be done that isn't supported by the stock protocol.
About synchronization - if the command is routed through the network one should assume that the receiving end knows what to do and if it executes the command immediately, that should be ok. The important thing is that it's the network that does the manipulation on the play side to ensure that things remain synchronized and we have a recordable and transferrable network stream. But it should make the particular use case here easier to handle.
And thinking about it, type 'kill' into the console. The screen will turn red immediately, suggesting that the network command is executed without delay.
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
So then that's even better if it doesn't require any modification
How does this relate to networking? Or ZDoom multiplayer doesn't have sv_cheats? Either way I'd advise against console command execution.Graf Zahl wrote:Changing inventory can be done with the 'give' and 'take' CCMDs.
-
- Lead GZDoom+Raze Developer
- Posts: 49179
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
The menu should have some means to override sv_cheats anyway. If modders are supposed to create gameplay related menus they will need an option to override the cheat block.
And how do these commands relate to networking? Have you ever checked what they do? They actually send a network command, after verifying that there's no cheat block in place.
Which reminds me: The network event is a first grade feature to get around the cheat protection if not all players have the same stuff loaded. There definitely needs to be a check that all players use the same script data (i.e. a ZSCRIPT/DECORATE checksum needs to be present somewhere.)
And how do these commands relate to networking? Have you ever checked what they do? They actually send a network command, after verifying that there's no cheat block in place.
Which reminds me: The network event is a first grade feature to get around the cheat protection if not all players have the same stuff loaded. There definitely needs to be a check that all players use the same script data (i.e. a ZSCRIPT/DECORATE checksum needs to be present somewhere.)
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
My point was that executing give command is generally guaranteed to not work online due to sv_cheats. But if it's somehow unblocked, then it's ok.Graf Zahl wrote:And how do these commands relate to networking? Have you ever checked what they do? They actually send a network command, after verifying that there's no cheat block in place.
However, I still think architecture like that is too dangerous, especially if we consider Zandronum (or c/s overall).
If we rely on give/take commands in menus, it means that any mods made for GZDoom will be incompatible with Zandronum once they try to implement ZScript, because Zandronum will never allow issuing an arbitrary give command by the client, even if the client is damn sure that it originates from the menus.
The same can be done with p2p as well (that is, crafting give packets in a way that remote peers would think that they are originating from the menus), although with ZDoom's multiplayer cheating doesn't really matter.
Options for cheating should be minimized, hence the SendNetworkMessage suggestion above, even for things that are seemingly already implemented.
Then, even if someone alters SendNetworkMessage in a way that it always sends IsManual=false, the options for cheating would still be restricted by whatever is written in the network event handler. Not comparable to endless possibilities with 'give'.
-
- Lead GZDoom+Raze Developer
- Posts: 49179
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
Agreed. But being able to do the same things through a network event is just the same, just a bit redressed.ZZYZX wrote:My point was that executing give command is generally guaranteed to not work online due to sv_cheats. But if it's somehow unblocked, then it's ok.Graf Zahl wrote:And how do these commands relate to networking? Have you ever checked what they do? They actually send a network command, after verifying that there's no cheat block in place.
However, I still think architecture like that is too dangerous, especially if we consider Zandronum (or c/s overall).
That is a valid concern. But unless you checksum the script code a user could still inject some malicious stuff here and do evil things.ZZYZX wrote: Options for cheating should be minimized, hence the SendNetworkMessage suggestion above, even for things that are seemingly already implemented.
Then, even if someone alters SendNetworkMessage in a way that it always sends IsManual=false, the options for cheating would still be restricted by whatever is written in the network event handler. Not comparable to endless possibilities with 'give'.
Speaking of Zandronum, it uses an entirely different network protocol, so obviously no low level network related stuff may be exposed to scripting, not only for security but also for compatibility.
And needless to say, modifying the player directly from the menu is never going to fly in a C/S environment because the real player is on an entirely different computer. And that's one thing I do not want to block. I hope that at some point in the future the current networking can be transitioned to genuine C/S, even for single player games (but that has to be a lot cleaner than what Skulltag did and Zandronum inherited.), and at that point at the very latest all those cross-interactions between subsystems are dead anyway.
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: "How do I ZScript?"
Nash wrote:Code: Select all
Script error, ":zscript/engine/engine_physics.zsc" line 18: Expression must be a modifiable value Script error, ":zscript/engine/engine_physics.zsc" line 19: Expression must be a modifiable value Script error, ":zscript/engine/engine_physics.zsc" line 20: Expression must be a modifiable value class Z_Physics { static void AlignToSlope(Actor self, double dAng, double dPitch) { vector3 fNormal = self.CurSector.FloorPlane.Normal; vector2 fNormalP1 = (fNormal.X != 0 || fNormal.Y != 0) ? (fNormal.X, fNormal.Y).Unit() : (0, 0); vector2 fNormalP2 = ((fNormal.X, fNormal.Y).Length(), fNormal.Z); double fAng = atan2(fNormalP1.Y, fNormalP1.X); // floor angle (not pitch!) double fPitch = -atan2(fNormalP2.X, fNormalP2.Y); // floor pitch double dDiff1 = sin(fAng - (dAng + dPitch)); double dDiff2 = cos(fAng - dAng); self.Pitch = fPitch * dDiff2 + dPitch; ////////////////// <-- LINE 18 self.Roll = fPitch * dDiff1; self.Angle = dAng; } }
Code: Select all
Script error, ":zscript/bumi/time.zsc" line 100: Can't call play function get from data context Script error, ":zscript/bumi/time.zsc" line 101: Unknown identifier 'bumi' class FWorld : Thinker { static FWorld Get() { ThinkerIterator it = ThinkerIterator.Create("FWorld", STAT_STATIC); let p = FWorld(it.Next()); if (p == null) { p = new("FWorld").Init(); } return p; } } class Z_Time { /* * Gets current second of minute. */ static int T_GetSecond(void) { let bumi = FWorld.Get(); /////////// <-- LINE 100 return bumi.timeSecond; }
Just these for now. Any advice would be appreciated.
[I edited the post to show where the "get" function is coming from. This is the global thinker solution Graf Zahl gave me a while back]
Any help? I can't help test the new stuff for bugs if I can't even get my game to run.
-
- Lead GZDoom+Raze Developer
- Posts: 49179
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: "How do I ZScript?"
You have to declare that class as 'play' so that it can write to play data
Code: Select all
class Z_Physics play
-
-
- Posts: 1384
- Joined: Sun Oct 14, 2012 1:43 am
- Location: Ukraine
Re: "How do I ZScript?"
Plus specifically FWorld Get can be declared 'clearscope' because it doesn't really alter the playsim, only create a thinkeriterator.Unlike the other things that were added the play-ui separation is not intuitively obvious in any way, I'll document it somewhere eventually since it's now in GZDoom.
For now, you can refer to the last longass post of mine in Render events thread: viewtopic.php?p=978268#p978268
But anyway, by putting clearscope here you will make the method inside a play class 'data', so it won't be able to alter playsim, but it will also be callable from data context.
Code: Select all
static clearscope FWorld Get()
For now, you can refer to the last longass post of mine in Render events thread: viewtopic.php?p=978268#p978268
But anyway, by putting clearscope here you will make the method inside a play class 'data', so it won't be able to alter playsim, but it will also be callable from data context.
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: "How do I ZScript?"
By the way, this is extremely annoying.
-
- Posts: 3060
- Joined: Thu May 03, 2012 1:18 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Maryland, US
Re: "How do I ZScript?"
Somewhat similar to Nash, I have a class that needs to be updated for the new changes, but it's all a bit over my head.This now gives the error, "Can't call play function A_PlaySound from ui context"
What might I do to make this work again?
Code: Select all
class MGTauntHandler : EventHandler
{
override void ConsoleProcess(ConsoleEvent e)
{
if(e.Name=='MGTauntHandler')
players[e.Player].mo.A_PlaySound("*taunt",CHAN_VOICE);
}
}
What might I do to make this work again?
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: "How do I ZScript?"
Code: Select all
class MGTauntHandler : EventHandler play
Also is your handler introduced via mapinfo or other?
Last edited by Major Cooke on Mon Mar 06, 2017 10:39 am, edited 1 time in total.
-
- Posts: 3060
- Joined: Thu May 03, 2012 1:18 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Maryland, US
Re: "How do I ZScript?"
Tried it. Error: "Can't change class scope in class MGTauntHandler"
-
- Posts: 8196
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Re: "How do I ZScript?"
Turns out ZZYZX changed it. We'll have to wait for comment on that.
@Nash: Try adding play to the end of your class declaration.
If you're using event handlers, this won't fix anything there, but it'll at least take care of most. Same thing applies to structs:
@Nash: Try adding play to the end of your class declaration.
Code: Select all
class Z_Physics play
Code: Select all
Struct namehere play
{
};
-
-
- Posts: 17465
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: "How do I ZScript?"
Spoiler:I added clearscope to my FWorld and am still getting all of these errors. Man, I'm almost at the edge of giving up. ZScript wasn't hard, but this whole ui/play/clearscope business is just something I don't understand at all, and yes I already read the longass post. I don't understand when and where things need to be, what even is clearscope, etc.