"How do I ZScript?"

Discuss all aspects of editing for ZDoom.
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 ZzZombo » Sun Jun 18, 2017 11:35 pm

"goto" is static, thus it never considers any child overrides of the target state. You should use a jumping function, as they resolve dynamically. Like A_Jump(256,<state>).
ZzZombo
 
Joined: 16 Jul 2012

Re: "How do I ZScript?"

Postby Pink Baron » Mon Jun 19, 2017 4:41 am

ZzZombo wrote:"goto" is static, thus it never considers any child overrides of the target state. You should use a jumping function, as they resolve dynamically. Like A_Jump(256,<state>).

"Return ResolveState" instead of "Goto" statements

It worked! Thanks :D
Pink Baron
 
Joined: 16 Mar 2016

Re: "How do I ZScript?"

Postby Major Cooke » Mon Jun 19, 2017 8:16 am

Kinsie, I did some further digging. I'm not entirely positive about this but hopefully Graf can put in some words of wisdom to correct me where I'm wrong.

Code: Select allExpand view
native static vector3, int G_PickDeathmatchStart();
native static vector3, int G_PickPlayerStart(int pnum, int flags = 0);


Both of these will return the angle and the coordinates of the player start. If the player starts do not exist, it returns a vector of (0,0,0) and an angle of 0.

G_PickPlayerStart's pnum is the player number. I.e. a player start of 1 will get the player's playing start, but be careful -- this will include the players actual spawn point. This also includes voodoo dolls, so it wouldn't hurt to do a safety check for playerpawns being at those locations upon map start.

There's two flags for this:
Code: Select allExpand view
PPS_FORCERANDOM
PPS_NOBLOCKINGCHECK

I believe it's self explanatory enough but if you need clarification on the flags, let me know.

So if you just want the very base player starts I think it's reasonable to call that function for players 1-4 and that should be good.
User avatar
Major Cooke
Like space chicken, but dumber.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: "How do I ZScript?"

Postby Zergeant » Mon Jun 19, 2017 3:15 pm

Is there any way to have your own variables with Weapons? I could really use int and bool to check a few things, and also not have to rely on dummy inventory items.

Currently attempting to access variables inside states just gives a "Self pointer used in ambiguous context; VM execution may abort!".
User avatar
Zergeant
 
Joined: 31 Aug 2010
Location: Sweden

Re: "How do I ZScript?"

Postby D2JK » Mon Jun 19, 2017 3:21 pm

It will work when you add an invoker. prefix whenever you refer to your variable in the weapon states:

Code: Select allExpand view
Class MyWeapon : Weapon
 {
  int MyVariable;
  States
   {
    Fire:
     TNT1 A 0 A_LogInt(invoker.MyVariable);
     ...
   }
 }
D2JK
 
Joined: 30 Aug 2014

Re: "How do I ZScript?"

Postby Zergeant » Mon Jun 19, 2017 3:47 pm

D2JK wrote:It will work when you add an invoker. prefix whenever you refer to your variable in the weapon states:

Code: Select allExpand view
Class MyWeapon : Weapon
 {
  int MyVariable;
  States
   {
    Fire:
     TNT1 A 0 A_LogInt(invoker.MyVariable);
     ...
   }
 }

Thanks dude, managed to figure it out just as soon as you posted.
User avatar
Zergeant
 
Joined: 31 Aug 2010
Location: Sweden

Re: "How do I ZScript?"

Postby JPL » Tue Jun 20, 2017 12:24 pm

Is there a reason DropItem.Probability is marked as read-only in base.txt? I tried to modify it from some ZScript (to turn off all enemy drops by setting it to 0) and found I couldn't. I removed the readonly keyword from it in base.txt and it worked fine, are there any negative repercussions to doing so? I assume it was set that way on purpose for some reason. Otherwise I could submit a PR but it's a trivial change...
User avatar
JPL
 
Joined: 09 Apr 2012

Re: "How do I ZScript?"

Postby Vaecrius » Wed Jun 21, 2017 2:25 am

I just learned today that if you have multiple different instances of a pickup each call attachtoowner() directly, you'll end up with each of them as a separate entry on printinv. I want to exploit this for reasons.

What's the fastest way to tell how many separate instances of the same inventory item are attached to the same owner?
User avatar
Vaecrius
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: "How do I ZScript?"

Postby Nash » Wed Jun 21, 2017 3:15 am

Vaecrius wrote:I just learned today that if you have multiple different instances of a pickup each call attachtoowner() directly, you'll end up with each of them as a separate entry on printinv


Can you post some code?
User avatar
Nash
Nash Muhandes [Audio Engineer | Game Designer | Scripting]
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia

Re: "How do I ZScript?"

Postby Graf Zahl » Wed Jun 21, 2017 4:00 am

JPL wrote:Is there a reason DropItem.Probability is marked as read-only in base.txt? I tried to modify it from some ZScript (to turn off all enemy drops by setting it to 0) and found I couldn't. I removed the readonly keyword from it in base.txt and it worked fine, are there any negative repercussions to doing so? I assume it was set that way on purpose for some reason. Otherwise I could submit a PR but it's a trivial change...


DropItems are per-class data, not per-item. If you change it, you change it for all instances of a given class. Per-class data should always be considered read-only by a mod.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: "How do I ZScript?"

Postby zrrion the insect » Wed Jun 21, 2017 4:18 am

It sounds like changing it for all instances of a given class is exactly what JPL wants to do though, so why should that sort of thing always be considered read-only?
User avatar
zrrion the insect
Like a fish in a child's hands.
 
Joined: 25 Jun 2009
Location: Time Station 1: Moon of Glendale

Re: "How do I ZScript?"

Postby Graf Zahl » Wed Jun 21, 2017 4:35 am

The proper way to disable item drops is to replace the class with a non-dropping variant.
But regardless, class data being immutable is something I won't change.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: "How do I ZScript?"

Postby Vaecrius » Wed Jun 21, 2017 10:42 am

Nash wrote:
Vaecrius wrote:I just learned today that if you have multiple different instances of a pickup each call attachtoowner() directly, you'll end up with each of them as a separate entry on printinv
Can you post some code?
Summon a bunch of these and let them hit you:
Code: Select allExpand view
class parasite:inventory{
   override void touch(actor other){}
   default{
      +rollsprite
      monster;
      speed 4;height 4;radius 4;
      inventory.pickupmessage "A parasite has latched on to you. Check printinv for details.";
   }
   override void postbeginplay(){
      super.postbeginplay();
      speed=random(1,8);
      scale=(frandom(0.3,1.3),frandom(0.3,1.3));
      roll=random(-20,20);
   }
   states{
   spawn:
      BAL1 A 10 A_Look();
      wait;
   see:
      BAL1 AB 2 {vel.z+=4;}
      BAL1 ABAB 2;
   see2:
      BAL1 AB 2 A_Chase();
      loop;
   melee:
      BAL1 CDE 3;
      BAL1 A 0{
         if(target&&!target.bkilled&&target.health>0){
            AttachToOwner(target);
            target.A_Log(string.format("\cg%s",pickupmessage()),true);
         }
      }goto see;
   }
}
EDIT: Added some randomization for the appearance of each one to show that when you try to drop one, it's the same one that had attached itself to you and that its variable settings remain intact.
User avatar
Vaecrius
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

Re: "How do I ZScript?"

Postby JPL » Wed Jun 21, 2017 11:31 am

Graf Zahl wrote:But regardless, class data being immutable is something I won't change.


That makes sense.

Graf Zahl wrote:The proper way to disable item drops is to replace the class with a non-dropping variant.


This is what I was trying to avoid... I don't want to have to include a ShotgunGuy, ChaingunGuy etc replacement because other mods could replace those, when all I want is for them not to drop weapon pickups. Is that my only option?
User avatar
JPL
 
Joined: 09 Apr 2012

Re: "How do I ZScript?"

Postby Vaecrius » Wed Jun 21, 2017 2:32 pm

Those mods might well rely on the existing dropping behaviour for other functions, so if you changed it upstream like that you'd break those mods.

This sort of guessing-game for the sake of compatibility with other possible-but-unascertained mods is a game no one wins.
User avatar
Vaecrius
Putting the XD into *xdeath since 2007
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

PreviousNext

Return to Editing

Who is online

Users browsing this forum: No registered users and 6 guests