new to zscript need help with detecting bind in a script

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
specterrev
Posts: 7
Joined: Sun Feb 25, 2024 11:59 am
Preferred Pronouns: He/Him

new to zscript need help with detecting bind in a script

Post by specterrev »

im trying to make a script that detects if the bind for secondary fire is pressed it activates a function but i cant figure out how to detect it can anyone help?
Last edited by specterrev on Tue Feb 27, 2024 9:25 am, edited 2 times in total.
yum13241
Posts: 875
Joined: Mon May 10, 2021 8:08 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): EndeavorOS (basically Arch)
Graphics Processor: Intel with Vulkan/Metal Support
Contact:

Re: new to zscript need help with detecting bind in a script

Post by yum13241 »

Is this "script" a weapon? If so, use the AltFire: state label.
User avatar
specterrev
Posts: 7
Joined: Sun Feb 25, 2024 11:59 am
Preferred Pronouns: He/Him

Re: new to zscript need help with detecting bind in a script

Post by specterrev »

nope I'm using it in a actual script kinda as a placeholder because I couldn't figure out custom key binds for stuff and even if I did id need to figure out this anyway, so because I don't plan for weapons to have altfires I'm using it for this script
7Soul
Posts: 44
Joined: Sat Mar 13, 2021 6:47 pm

Re: new to zscript need help with detecting bind in a script

Post by 7Soul »

Here's an example from the GZDoom engine itself of player buttons being checked:
https://github.com/ZDoom/gzdoom/blob/eb ... r.zs#L1239

And to check a specific button you'd use (player.cmd.buttons & BT_ALTATTACK)

Other buttons here: https://zdoom.org/wiki/Player_input_buttons

And these are other cmd properties you can use: https://github.com/ZDoom/gzdoom/blob/47 ... ayer.zs#L2
User avatar
specterrev
Posts: 7
Joined: Sun Feb 25, 2024 11:59 am
Preferred Pronouns: He/Him

Re: new to zscript need help with detecting bind in a script

Post by specterrev »

7Soul wrote: Mon Feb 26, 2024 3:39 pm Here's an example from the GZDoom engine itself of player buttons being checked:
https://github.com/ZDoom/gzdoom/blob/eb ... r.zs#L1239

And to check a specific button you'd use (player.cmd.buttons & BT_ALTATTACK)

Other buttons here: https://zdoom.org/wiki/Player_input_buttons

And these are other cmd properties you can use: https://github.com/ZDoom/gzdoom/blob/47 ... ayer.zs#L2
i dont know if this is the correct way to reply but, i tried using "(player.cmd.buttons & BT_ALTATTACK)" in a if statement in my script and it gave me a error saying player: identifier has not been declared.
7Soul
Posts: 44
Joined: Sat Mar 13, 2021 6:47 pm

Re: new to zscript need help with detecting bind in a script

Post by 7Soul »

You need a player pawn variable, but it depends where you're using this script. If it's a weapon you can create one with
let player = Invoker.owner;

And I think in other cases you can do
let player = players[consoleplayer].mo; (assuming it's a single player mod)

You can learn more here: https://github.com/jekyllgrim/ZScript_B ... ata-access
User avatar
specterrev
Posts: 7
Joined: Sun Feb 25, 2024 11:59 am
Preferred Pronouns: He/Him

Re: new to zscript need help with detecting bind in a script

Post by specterrev »

7Soul wrote: Mon Feb 26, 2024 6:08 pm You need a player pawn variable, but it depends where you're using this script. If it's a weapon you can create one with
let player = Invoker.owner;

And I think in other cases you can do
let player = players[consoleplayer].mo; (assuming it's a single player mod)

You can learn more here: https://github.com/jekyllgrim/ZScript_B ... ata-access
when I try to use the code your telling me to use it just says player not defined or players not defined, so is there anything I have to add to my wad or change with my wad to get what your telling me to use to work? because my script is just a basic standard script in my wad I haven't really messed around with adding anything because I'm new to scripting with acs and coding as a whole.
7Soul
Posts: 44
Joined: Sat Mar 13, 2021 6:47 pm

Re: new to zscript need help with detecting bind in a script

Post by 7Soul »

You said you were using ZScript, not ACS so I posted the solution for ZScript

I'm not super familiar with ACS but this seems to be what you're looking for: https://zdoom.org/wiki/GetPlayerInput
User avatar
specterrev
Posts: 7
Joined: Sun Feb 25, 2024 11:59 am
Preferred Pronouns: He/Him

Re: new to zscript need help with detecting bind in a script

Post by specterrev »

7Soul wrote: Tue Feb 27, 2024 6:59 am You said you were using ZScript, not ACS so I posted the solution for ZScript

I'm not super familiar with ACS but this seems to be what you're looking for: https://zdoom.org/wiki/GetPlayerInput
sorry for not being clearer i got the two confused, also i have tried getplayerinput and it just wouldnt work for me
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: new to zscript need help with detecting bind in a script

Post by Jarewill »

Please show your code so we can see what you did.
User avatar
specterrev
Posts: 7
Joined: Sun Feb 25, 2024 11:59 am
Preferred Pronouns: He/Him

Re: new to zscript need help with detecting bind in a script

Post by specterrev »

Jarewill wrote: Tue Feb 27, 2024 7:28 am Please show your code so we can see what you did.
so far all the code is is a empty if statement becuase i cant figure out how to use binds in it
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: new to zscript need help with detecting bind in a script

Post by Jarewill »

Then try this:

Code: Select all

#library "mymod"
#include "zcommon.acs"

Script "GetAltfire" ENTER
{
	While(true)
	{
		int buttons = GetPlayerInput(-1,MODINPUT_BUTTONS);
		
		If(buttons & BT_ALTATTACK)
		{
			//Your code here
		}
		
		Delay(1);
	}
}
User avatar
specterrev
Posts: 7
Joined: Sun Feb 25, 2024 11:59 am
Preferred Pronouns: He/Him

Re: new to zscript need help with detecting bind in a script

Post by specterrev »

Jarewill wrote: Tue Feb 27, 2024 9:16 am Then try this:

Code: Select all

#library "mymod"
#include "zcommon.acs"

Script "GetAltfire" ENTER
{
	While(true)
	{
		int buttons = GetPlayerInput(-1,MODINPUT_BUTTONS);
		
		If(buttons & BT_ALTATTACK)
		{
			//Your code here
		}
		
		Delay(1);
	}
}
thanks that worked.
Post Reply

Return to “Scripting”