how to find texture of the sector player's in

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!)
Post Reply
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

how to find texture of the sector player's in

Post by ramon.dexter »

So, how do I check for the texture of the sector player's currently in?
I tried using this function, but it looks like it checks for all textures available...

Code: Select all

action void W_useFilter() {
		int SectorNumber;
		let pawn = wastelandRanger(self);
		
		for (SectorNumber = 0; SectorNumber < level.sectors.size(); SectorNumber++) {
			if (level.sectors[SectorNumber].damageamount > 0) {
				textureid foo = level.sectors[SectorNumber].GetTexture(sector.floor);
				string floorTexture = TexMan.GetName(foo);
				A_Log(floorTexture);
				if (floorTexture == "F_WTRA1" || floorTexture == "F_WTRA2" || floorTexture == "F_WTRA3" || floorTexture == "F_WTRA4") {
					pawn.GiveInventory("foodCistaVoda", 1);
					pawn.A_Log("\c[green][ Filtered some water! ]");
					break;
				} else {
					pawn.A_Log("\c[green][ You must stand in water in order to use water filter!] ");
				}			
			}
		}
	}
So, how exactly do I check for the floor texture of sector player is currently in?
User avatar
randi
Site Admin
Posts: 7749
Joined: Wed Jul 09, 2003 10:30 pm
Contact:

Re: how to find texture of the sector player's in

Post by randi »

Every actor has a floorpic member variable. You can use that.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: how to find texture of the sector player's in

Post by Graf Zahl »

Keep in mind that the floorpic can come from a 3D floor so it's not necessarily the sector's own floortexture. But normally it's what you want.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: how to find texture of the sector player's in

Post by Jarewill »

While the topic already has been answered, I just wanted to add for the future that to access the sector the player is currently in you can access the cursector variable inside the actor class.
Your current code iterates through all sectors in the map, while cursector will return a pointer to the current sector the player is in.
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: how to find texture of the sector player's in

Post by ramon.dexter »

randi wrote: Sun Jul 02, 2023 9:25 am Every actor has a floorpic member variable. You can use that.
I thought there is some easy way. Thanks a lot, Randi ;)

Now, I got another question...

Is there a way to put some kind of delay into an custom action?
I tried doing this:

Code: Select all

action void W_useFilter() {
		
		let pawn = wastelandRanger(self);
		if ( pawn.floorpic == TexMan.CheckForTexture("F_WTRA1", 0, 0) || pawn.floorpic == TexMan.CheckForTexture("F_WTRA2", 0, 0) || pawn.floorpic == TexMan.CheckForTexture("F_WTRA3", 0, 0) || pawn.floorpic == TexMan.CheckForTexture("F_WTRA4", 0, 0) ) {
			//pawn.GiveInventory("foodCistaVoda", 1);
			//pawn.A_Log("\c[green][ Filtered some water! ]");
			int counter;
			counter = 0;
			pawn.A_Log(stringtable.localize("$TXT_waterFilter_start")); //\c[green][ Začínám filtrovat vodu. ]
			do {
				counter++;
			} until ( counter == 35*100 ) {
				pawn.GiveInventory("foodCistaVoda", 1);
				pawn.A_Log(stringtable.localize("$TXT_waterFilter_finish")); //"\c[green][ Filtered some water! ]"
			}
			 
		} else {
			pawn.A_Log(stringtable.localize("$TXT_waterfilter_standinwater")); //stringtable.localize("$M_envSuit_filtersLeft1") //"\c[green][ You must stand in water in order to use water filter!]"
		}
	}
But no matter how high value I put in (counter == 35*100, which should be 100 seconds), the code finishes instantly with no delay...So, is there w way to put delay into (custom) function?

Aand, how do I check for player being inside swimmable 3D floor (water)? Actually, the floorpic dont work with swimmable sectors...
ArchAngel777
Posts: 19
Joined: Sat Jun 10, 2023 1:06 am
Preferred Pronouns: He/Him
Operating System Version (Optional): W10
Graphics Processor: nVidia (Modern GZDoom)

Re: how to find texture of the sector player's in

Post by ArchAngel777 »

That delay won't work because you are incrementing the counter in a loop, so you basically just counted up to 35*100 in a single frame. The way I setup delays is to have the actor initialize the counter, and increment it in Tick(), than you can check the counter in your action function. Just be aware of who is using the function so you don't get any unknown variable errors.

Also, I think you are looking for the actor variables: waterlevel and waterdepth. I haven't used them myself but they should return information about being in 3d water sectors.
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: how to find texture of the sector player's in

Post by ramon.dexter »

ArchAngel777 wrote: Mon Jul 03, 2023 5:55 pm That delay won't work because you are incrementing the counter in a loop, so you basically just counted up to 35*100 in a single frame. The way I setup delays is to have the actor initialize the counter, and increment it in Tick(), than you can check the counter in your action function. Just be aware of who is using the function so you don't get any unknown variable errors.
Could you post some example of this, please?
ArchAngel777
Posts: 19
Joined: Sat Jun 10, 2023 1:06 am
Preferred Pronouns: He/Him
Operating System Version (Optional): W10
Graphics Processor: nVidia (Modern GZDoom)

Re: how to find texture of the sector player's in

Post by ArchAngel777 »

Hmm so I assume for this function you want to start some process (filtering water) and have it take 10 seconds to achieve? Do you want the player to stay in the water the whole time? The first approach I can think of would be to use ACS for this instead, since it has the delay() function which is perfect for these sorts of timed events. You could simplify the action function to just calling the ACS script if the player is in the water. Than when the ACS script is complete, add whatever item is the result of this process to the player inventory. If you wanted the player to remain in the water the whole time, you could probably check through the ACS script several times if the player is still in water, if not, abort the script and display a message "Filtering failed." or something like that.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: how to find texture of the sector player's in

Post by Jarewill »

ramon.dexter wrote: Tue Jul 04, 2023 12:15 pm Could you post some example of this, please?
Here's an example of what ArchAngel meant:

Code: Select all

	int delay; //This is the variable which keeps the timer
	Override void Tick(){
		Super.Tick();
		If(delay>0){ //If the timer isn't zero
			delay--; //Start counting down
			If(delay==0){DoAction();} //And the moment it hits zero, do the action
		}
		If(player.cmd.buttons&BT_RELOAD){ //This is just an example on how to start the timer, here it's a Reload button press
			delay=70; //Initialize the timer to 70 tics
			player.cheats^=CF_TOTALLYFROZEN; //Optional: Freeze the player for the entire duration if you wanted them to stay still and play an animation
		}
	}
	void DoAction(){
		player.cheats^=CF_TOTALLYFROZEN; //Unfreeze the player
		console.printf("My action"); //Do what you wanted it to do
	}
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: how to find texture of the sector player's in

Post by ramon.dexter »

Heh, strange. I tried doing something like this:

Code: Select all

override void Tick() {
		Super.Tick();		
		/*while ( inuse ) {
			counter++;
			if ( counter == 35 * 10 ) {
				A_GiveInventory("foodCistaVoda", 1);
				A_Log(stringtable.localize("$TXT_waterFilter_finish"));
				counter = 0;
				inuse = false;
			}
		}*/
		if ( inuse ) {
			do {
				counter++;
			} until ( counter == 35*10 ) {
				owner.A_GiveInventory("foodCistaVoda", 1);
				A_Log(stringtable.localize("$TXT_waterFilter_finish"));
				counter = 0;
				inuse = false;
			}
 		}
	}
I tried both while() and do-until loops and booth loops are executed instantly even in the Tick().
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: how to find texture of the sector player's in

Post by Jarewill »

You can't use a loop because it will execute it all on the same tic.
You need to let Tick run normally for the delay to happen.
Try this:

Code: Select all

		if ( inuse ) {
			counter++;
			if ( counter == 35*10 ) {
				owner.A_GiveInventory("foodCistaVoda", 1);
				A_Log(stringtable.localize("$TXT_waterFilter_finish"));
				counter = 0;
				inuse = false;
			}
 		}
You can still use loops in the Tick function, for example for iterating through an array, but if you want to make a timer then loops won't work.
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: how to find texture of the sector player's in

Post by ramon.dexter »

Oh yeah, I just forgot that Tick() is a loop itself :oops:

Many thanks for pointing out 8-)
Post Reply

Return to “Scripting”