"How do I 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.

Re: "How do I ZScript?"

Postby ZZYZX » Mon Mar 06, 2017 2:55 am

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.
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: "How do I ZScript?"

Postby Graf Zahl » Mon Mar 06, 2017 3:05 am

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.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: "How do I ZScript?"

Postby ZZYZX » Mon Mar 06, 2017 3:10 am

So then that's even better if it doesn't require any modification :)

Graf Zahl wrote:Changing inventory can be done with the 'give' and 'take' CCMDs.

How does this relate to networking? Or ZDoom multiplayer doesn't have sv_cheats? Either way I'd advise against console command execution.
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: "How do I ZScript?"

Postby Graf Zahl » Mon Mar 06, 2017 3:44 am

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.)
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: "How do I ZScript?"

Postby ZZYZX » Mon Mar 06, 2017 4:47 am

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.

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.
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'.
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: "How do I ZScript?"

Postby Graf Zahl » Mon Mar 06, 2017 5:52 am

ZZYZX wrote:
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.

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.
However, I still think architecture like that is too dangerous, especially if we consider Zandronum (or c/s overall).


Agreed. But being able to do the same things through a network event is just the same, just a bit redressed.

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'.


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.
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.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: "How do I ZScript?"

Postby Nash » Mon Mar 06, 2017 6:35 am

Nash wrote:
Code: Select allExpand view

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.!= 0 || fNormal.!= 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 allExpand view
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.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: "How do I ZScript?"

Postby Graf Zahl » Mon Mar 06, 2017 6:37 am

You have to declare that class as 'play' so that it can write to play data

Code: Select allExpand view
class Z_Physics play
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: "How do I ZScript?"

Postby ZZYZX » Mon Mar 06, 2017 6:45 am

Plus specifically FWorld Get can be declared 'clearscope' because it doesn't really alter the playsim, only create a thinkeriterator.
Code: Select allExpand view
static clearscope FWorld Get()
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.
User avatar
ZZYZX
le chat du rabbin
 
 
 
Joined: 14 Oct 2012
Location: Ukraine
Discord: ZZYZX#1394
Github ID: jewalky

Re: "How do I ZScript?"

Postby Major Cooke » Mon Mar 06, 2017 7:05 am

User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: "How do I ZScript?"

Postby Ed the Bat » Mon Mar 06, 2017 10:04 am

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.
Code: Select allExpand view
class MGTauntHandler : EventHandler
{
   override void ConsoleProcess(ConsoleEvent e)
   {
      if(e.Name=='MGTauntHandler')
         players[e.Player].mo.A_PlaySound("*taunt",CHAN_VOICE);
   }
}
This now gives the error, "Can't call play function A_PlaySound from ui context"
What might I do to make this work again?
User avatar
Ed the Bat
I'm tired. I want to go home.
 
Joined: 03 May 2012
Location: Maryland, US

Re: "How do I ZScript?"

Postby Major Cooke » Mon Mar 06, 2017 10:37 am

Code: Select allExpand view
class MGTauntHandler : EventHandler play


Try that.

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.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: "How do I ZScript?"

Postby Ed the Bat » Mon Mar 06, 2017 10:38 am

Tried it. Error: "Can't change class scope in class MGTauntHandler"
User avatar
Ed the Bat
I'm tired. I want to go home.
 
Joined: 03 May 2012
Location: Maryland, US

Re: "How do I ZScript?"

Postby Major Cooke » Mon Mar 06, 2017 10:43 am

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.

Code: Select allExpand view
class Z_Physics play


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:

Code: Select allExpand view
Struct namehere play
{
};
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: "How do I ZScript?"

Postby Nash » Mon Mar 06, 2017 10:49 am

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.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: Logan MTM and 1 guest