ZScript Discussion

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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!)
User avatar
Nash
 
 
Posts: 17512
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: ZScript Discussion

Post by Nash »

Xaser wrote:@Nash: the term you're looking for is "type casting" (or just "casting"). See here (and also here -- zscript casting is basically c++'s dynamic_cast) for some info.

Without going too far into programmer geekdom, the gist is that ZScript knows that the variable "sh" is an Actor (since that's what Spawn returns), but it doesn't know that your Actor is also a Shadow_Zombieman until you explicitly tell it that it is -- which you'll have to do in order for the code to find any of the new stuff (like ownerRef) you've defined in the Shadow_Zombieman class.

Thank you Xaser, precise and simple answer. :D

Also, The Zombie Killer, after looking at your fixed Hotline script:

TFW you realize you can already do hacky fake GUIs with Weapon Overlays :O :O :O
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: ZScript Discussion

Post by The Zombie Killer »

Nash wrote:TFW you realize you can already do hacky fake GUIs with Weapon Overlays :O :O :O
You definitely could, but I think writing an entire GUI that way would drive a person insane. I only used PSprites for the crosshair because it's the only way to move things around onscreen with interpolation, currently :D
User avatar
Nash
 
 
Posts: 17512
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: ZScript Discussion

Post by Nash »

Of course, and I wouldn't even consider it a serious solution, even when done with convenient wrapper functions.

However, I am now very curious when is someone going to make, like, I don't know - a Super Mario or Tetris clone using PSprites as their drawing API... :mrgreen: :twisted: :mrgreen: :twisted:
User avatar
kodi
 
 
Posts: 1361
Joined: Mon May 06, 2013 8:02 am

Re: ZScript Discussion

Post by kodi »

There's a guy who's making a roguelike with acs, HudMessage and zandro databases.
THE HORROR.
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: ZScript Discussion

Post by Major Cooke »

Don't count on it. Sprites can show up ludicrously large and without any proper way to resize them, that'd take a long time.

Buuuut if someone were to make an orthogonal camera view...
User avatar
Nash
 
 
Posts: 17512
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: ZScript Discussion

Post by Nash »

So what's the secret to seamlessly position something to the moving player? Internally I see that A_Warp uses SetOrigin, but when I do this in ZScript:

Code: Select all

    override void Tick(void)
    {
        Super.Tick();

        if (!p)
        {
            p = Spawn("Z_Car", pos, NO_REPLACE);
        }

        if (p)
        {
            p.Angle = Angle;
            p.SetOrigin(Pos, true);
        }
    }
 
the positioning and angle turning is jittery as hell relative to the player.
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm

Re: ZScript Discussion

Post by Xaser »

Tick() only gets called 35 times a second (it's one Tick per Tic :P ); from a quick look through Major Cooke's fixed version of TZK's camera stuff,my guess is that you can achieve smoothness by updating the spawned object's 'vel' (velocity) property to get it to move between tics. MC would be the best confirminator here; can't really play with it myself at present.
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: ZScript Discussion

Post by Major Cooke »

As I said, you have one actor control the movement of another. Look inside the base_player.zs file inside scripts/zs.

Code: Select all

void HandleControls()
{
	let input = camera.GetPlayerInput(INPUT_BUTTONS);
	
	// reset velocity
	// player stops moving instantly in Hotline Miami
	vel = (0, 0, vel.z);
	
	// velocities for moving forward & left
	let frwdvel = (speed * cos(camera.angle), speed * sin(camera.angle), 0);
	let leftvel = (speed * cos(camera.angle + 90), speed * sin(camera.angle + 90), 0);
	
	Vector3 tempvel;
	
	if (input & BT_FORWARD)
		tempvel += frwdvel;
	if (input & BT_BACK)
		tempvel -= frwdvel;
	if (input & BT_MOVELEFT)
		tempvel += leftvel;
	if (input & BT_MOVERIGHT)
		tempvel -= leftvel;
	
	if (tempvel == (0, 0, 0))	
	{
		if (legs.pos != pos)	legs.SetOrigin(pos,true);
		if (body.pos != pos)	body.SetOrigin(pos,true);
		if (camera.pos.x != pos.x || camera.pos.y != pos.y)
			camera.SetOrigin(Vec3Offset(tempvel.x, tempvel.y, camera.CamZ), true);
			//camera.SetOrigin((pos.x, pos.y, camera.pos.z), true);
		legs.vel = body.vel = camera.vel = tempvel;
		return;
	}
	
	Vector3 oldpos = (pos.x, pos.y, pos.z);
	Vector2 newpos = Vec2Offset(tempvel.x, tempvel.y);
	
	vel = tempvel;
	
	if (!A_CheckBlock("Null",CBF_ABSOLUTEPOS,AAPTR_DEFAULT,newpos.x,newpos.y,0,0))
	{
		Vector2 diffpos = (pos.x - oldpos.x,pos.y - oldpos.y);
		
		legs.vel = body.vel = vel = tempvel;
		camera.vel = (tempvel.x, tempvel.y, camera.vel.z);
		
	}
	else
	{
		legs.SetOrigin(pos, true);
		body.SetOrigin(pos, true);
		vel = tempvel;
		legs.vel = body.vel = (0, 0, vel.z);
	}
	camera.SetOrigin(Vec3Offset(vel.x, vel.y, camera.CamZ), true);
}
Only use ONE ACTOR to do the updating. That's the key part.

However, I suggest you drag TheZombieKiller in here to post his even more recently revised one as that one takes care of some further issues which mine had.
User avatar
The Zombie Killer
Posts: 1528
Joined: Thu Jul 14, 2011 12:06 am
Location: Gold Coast, Queensland, Australia

Re: ZScript Discussion

Post by The Zombie Killer »

Major Cooke wrote:However, I suggest you drag TheZombieKiller in here to post his even more recently revised one as that one takes care of some further issues which mine had.
Already available here
User avatar
NeuralStunner
 
 
Posts: 12328
Joined: Tue Jul 21, 2009 12:04 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: capital N, capital S, no space

Re: ZScript Discussion

Post by NeuralStunner »

Quick question: Will it be possible to dynamically change a non-player actor's max health? I'm thinking mainly of boosting boss health for higher difficulties and/or larger player counts.
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

Re: ZScript Discussion

Post by Matt »

What does "crouchsprite" do in PlayerPawn? Is there any prospect of being able to change this on the fly?
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript Discussion

Post by ZZYZX »

I think chrouchsprite should be SpriteID. Not entirely sure though.
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: ZScript Discussion

Post by Major Cooke »

NeuralStunner wrote:Quick question: Will it be possible to dynamically change a non-player actor's max health? I'm thinking mainly of boosting boss health for higher difficulties and/or larger player counts.
You'll have to set that up in PostBeginPlay. Currently you cannot change the spawn health.

Code: Select all

int RealMaxHealth;

override void PostBeginPlay()
{
	Switch (skill)
	{
	Case 1:
		RealMaxHealth = 2000;	break;
	Case 2:
		RealMaxHealth = 4000;	break;
	Default:
		RealMaxHealth = 6000;	break;
	// ...
	}
	A_SetHealth(RealMaxHealth);
}
If you're trying to cover respawning cases, use +NEVERRESPAWN, check for the appropriate respawn cvars being enabled or not, post-death count up to spawn a copy of itself at the starting position, transfer important information like TID/specials/arguments, and destroy itself.
User avatar
Major Cooke
Posts: 8221
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town

Re: ZScript Discussion

Post by Major Cooke »

Graf Zahl wrote:That part won't work that well, you still have to call P_ChangeSector to handle actor placement in the sector. That and the flagging of the sector for updating the GL structures are really everything that's missing right now.

I'd still implement a ChangePlane function that takes care of the necessary bookkeeping than doing it all script side. If then something needs adjustment it can be done in a function that's on the safe side.
This got me thinking... What about a set of vertex function as well? I know they most likely wouldn't change the vertex itself, instead changing the slopes all around. Guess I could call it 'slope point'. This could be a much easier solution for places where applicable vertices are.

I.e.
  • GetNearestSlopePoint(Vector2 vpos, double range, bool ceiling = false); -- Gets the closest vertex to vpos.
  • SetSlopePointHeight(vert v, int newheight); -- Changes the slope point and all slopes around it immediately, like using GZDoom's editable vertex mode where one moves it up and down.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine

Re: ZScript Discussion

Post by ZZYZX »

When the generic slope setting function (which takes normal and center point) is available, it will be possible to simply calculate the normal using three points of the triangle sector (like this). That function is not needed in ZScript itself IMO.
Closest vertex to vpos will be available as well, once PointInSector or BlockLineIterator is ported, so you can query sector or line list around the given point and then find the closest vertex.
Or, if the sector is already known, then you have sector line list in... forgot. Wait. Right, this:

Code: Select all

	sectorstruct->AddNativeField("lines", NewPointer(NewResizableArray(NewPointer(linestruct, false)), false), myoffsetof(sector_t, Lines), VARF_Native);
sector.lines for enumerating lines in a sector, then you can check lines' vertices and see which one is the closest.

Return to “Scripting”