[ZScript] spawn something in valid map space only

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.

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!)
gramps
Posts: 300
Joined: Thu Oct 18, 2018 2:16 pm

Re: [ZScript] spawn something in valid map space only

Post by gramps »

Graf Zahl wrote:Anyone want to take a shot at such a function? ;)
Did anyone start on this yet? I might take a crack at it, sounds like a good beginner exercise ;p

It would be nice if you could just pass it a vector, instead of an actor needing to be there, since use case is deciding whether to spawn something somewhere. You'd have to create the thing first and move it around until you find a good spot for it, instead of finding a spot first and creating it there. I guess putting a temporary thing at that position would be too much of a hack on the engine side, though...

So would this be a method of global "level," maybe level.isActorInVoid(a) or level.isActorInBounds(a)?
User avatar
Nash
 
 
Posts: 17500
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [ZScript] spawn something in valid map space only

Post by Nash »

I agree on passing a Vector3 into it, instead of Actor. The latter would involve spawning an Actor first and introduces all of the overhead that comes with it, whereas with a direct position check, one could skip even spawning an Actor completely.

(And yes, this makes a huge difference for large-scale use)
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [ZScript] spawn something in valid map space only

Post by Graf Zahl »

This doesn't need a full-blown actor, especially if you just want to verify a location for a spawn.
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: [ZScript] spawn something in valid map space only

Post by Gez »

And a vector is more generic anyway. It could be used for other purposes than spawning, such as for example testing if a position is valid for pathing.
gramps
Posts: 300
Joined: Thu Oct 18, 2018 2:16 pm

Re: [ZScript] spawn something in valid map space only

Post by gramps »

Yeah, vector would be best... was considering something like level.containsPoint(mob.pos) earlier.
Graf Zahl wrote:To determine whether a point is valid all that needs to be done is finding the subsector an actor is in and do a PointOnSide check with every one-sided seg of the subsector.
I guess this is the part that made me think something might need to actually be there. Can we easily find which subsector encloses an arbitrary point instead?

On another note, here's another sort of hacky idea that could work now for spawning stuff on the floor (but not in the void). You could probably have a custom bullet attack that leaves behind the thing you want to spawn as a puff, and just fire that straight down at arbitrary positions.
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
Contact:

Re: [ZScript] spawn something in valid map space only

Post by Matt »

PointOnSide has a v3 input, no actor needed as long as you can get the subsector.

If you need an actor to get the subsector (I have no idea how to do this, I didn't even remember subsectors were a thing until this thread) I think one can get away with spawning a single dummy actor (or even using the player) and using SetXYZ to move the actori into the required test position, do the check and immediately move back (or move onto the next test position(s) before moving back).
gramps
Posts: 300
Joined: Thu Oct 18, 2018 2:16 pm

Re: [ZScript] spawn something in valid map space only

Post by gramps »

Alright, searching through the code turned up P_PointInSubsector(), which takes a 2D point and returns a subsector. Should be able to use this to get the subsector for an arbitrary point, then do the check Graf described.

API-wise, I'm still leaning towards attaching this thing to global "level" as something like level.containsPoint(). Any thoughts on that?

Was starting to think maybe some lower-level stuff should be exposed instead, and the check Graf described could be done in zscript, but then I saw this, which makes sense... Just want to be sure we're not targeting an overly specific use case instead of doing something more broadly useful.
User avatar
Nash
 
 
Posts: 17500
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: [ZScript] spawn something in valid map space only

Post by Nash »

Putting the method in the Level struct makes sense to me.
User avatar
Ichor
Posts: 1784
Joined: Wed Jul 23, 2003 9:22 pm

Re: [ZScript] spawn something in valid map space only

Post by Ichor »

Another idea might be to give every single sector a non-zero tag (they can all be the same). Then have it check if the sector tag is greater than 0. If it is, it has a chance to spawn in it. If not, then nothing will spawn. Any 0 tag sector might then be considered outside the map and be ignored.
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: [ZScript] spawn something in valid map space only

Post by Gez »

I don't think that'd work. You're always in a sector regardless of where you are, that's why you can get damaged by nukage floors while noclipping in the void.
User avatar
Ichor
Posts: 1784
Joined: Wed Jul 23, 2003 9:22 pm

Re: [ZScript] spawn something in valid map space only

Post by Ichor »

Gez wrote:I don't think that'd work. You're always in a sector regardless of where you are, that's why you can get damaged by nukage floors while noclipping in the void.
Would surrounding the perimeter of the map with a 0 tag sector prevent that?
Gez
 
 
Posts: 17946
Joined: Fri Jul 06, 2007 3:22 pm

Re: [ZScript] spawn something in valid map space only

Post by Gez »

You'd have to surround every voidspace with 0 tag sectors if you want that to work. Meaning that there would be no one-sided wall at all in playable space; any one-sided wall would be in the dummy sectors that serve as lining for the rest of the map. And of course there'd be problems with things like doors and any other effect that look at neighboring sectors.

It's really hacky and cumbersome. A built-in function that looks at the given subsector's segs would be much simpler and it would work in every case instead of requiring maps to be built in a bizarre way.
User avatar
Rachael
Posts: 13954
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: [ZScript] spawn something in valid map space only

Post by Rachael »

I think it's best to note, at this point, that a native solution has been established as not only possible, but preferred, and possibly already being implemented. These hack-arounds are not going to help at this point.
gramps
Posts: 300
Joined: Thu Oct 18, 2018 2:16 pm

Re: [ZScript] spawn something in valid map space only

Post by gramps »

But hacking stuff together is half the fun!

I haven't actually written anything yet, in fact I need to set up a github first (moved to gitlab after MS acquisition). Will probably get on it late tonight.
gramps
Posts: 300
Joined: Thu Oct 18, 2018 2:16 pm

Re: [ZScript] spawn something in valid map space only

Post by gramps »

Well, I'm having some issues getting this thing to build. It's been over a decade since I've tried to build anything on Windows, so I'm probably doing something stupid. It looks like there's an unmet lzma dependency, and the pk3s aren't building either. Hoping these are related, and whenever I figure out where to stick lzma dev package it'll sort itself out (what's Windows equivalent of /usr/include anyway?).

If someone else who's already set up for it wants to tackle this, go ahead, I might not be able to get back to it this weekend.
Post Reply

Return to “Scripting”