ACS script that will check if player pressed the button twice

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!)
userofthataccount
Posts: 2
Joined: Sun Dec 15, 2024 12:10 pm

ACS script that will check if player pressed the button twice

Post by userofthataccount »

Hello everyone I am currently looking for an ACS script that will give the player an item if he pressed the button twice

I want it the ACS script to work like:
Player: *Presses forward button twice* --> Script *Gives player inventory "ForwardToken"* ---- delay ---> Script *Takes the inventory token back*

and I want it to use like:
Player: *Fires weapon* ------> *An animation starts playing*
Player: *Presses the forward button twice and then fires* ------> *Other animation starts playing*

And also I want it to work on every direction (forward, backward, left and right)

I LOVE YAAAAAL
Jarewill
 
 
Posts: 1845
Joined: Sun Jul 21, 2019 8:54 am

Re: ACS script that will check if player pressed the button twice

Post by Jarewill »

GetPlayerInput will be your friend here.
For example:

Code: Select all

//ACS
Script "DoubleTap" ENTER{ //An ENTER script starts when a player enters the map and it runs for each player in multiplayer
	int forward, back, left, right; //Those variables will be used for storing delays between pressses
	While(true){
		int buttons = GetPlayerInput(-1,MODINPUT_BUTTONS); //Save the currently pressed buttons
		int oldbuttons = GetPlayerInput(-1,MODINPUT_OLDBUTTONS); //Save the buttons pressed a tic before
		If(!(oldbuttons & BT_FORWARD) && buttons & BT_FORWARD){ //If the forward key was just pressed, execute the following
			If(forward>0){ //If the forward delay is above 0
				TakeInventory("DoubleTapForward",1); //Take away the token item (for resetting the duration)
				GiveInventory("DoubleTapForward",1); //Give it again
			}
			forward=7; //Set the delay to look for double taps, tweak it to your liking
		}
		If(!(oldbuttons & BT_BACK) && buttons & BT_BACK){....} //Repeat the same code for BT_BACK, BT_LEFT and BT_RIGHT
		If(forward>0){forward--;} //Tick down the delay, repeat it for the remaining 3
		Delay(1); //Delay the loop to not terminate the script
	}
}

//DECORATE
Actor DoubleTapForward : Powerup{
	Powerup.Duration 14 //A powerup will automatically tick down and get removed, tweak the duration to your liking
}
Then for your weapon you can just use A_JumpIfInventory with the token powerup items.
userofthataccount
Posts: 2
Joined: Sun Dec 15, 2024 12:10 pm

Re: ACS script that will check if player pressed the button twice

Post by userofthataccount »

Thank you so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
i was suffering w this for a month

Return to “Scripting”