Shoot from weapon "without" player

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
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Shoot from weapon "without" player

Post by Apeirogon »

Lets take a simple doom pistol. Is it possible to make it shoot without using it as player ready weapon?
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Shoot from weapon "without" player

Post by Void Weaver »

What do you mean "make it shoot without using it as player ready weapon"? :? How it supposed to acts directly in game?
Do you mean doing call A_FireBullets outer of 'Fire' state or something else?
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Shoot from weapon "without" player

Post by Apeirogon »

Execute weapon "fire" state without using them as Psprite.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Shoot from weapon "without" player

Post by Void Weaver »

... what about replacing fire-Psprites by other custom ones or even TNT1?

For ex.:

Code: Select all

ACTOR InvPistol : Pistol replaces Pistol
{
  Weapon.SlotNumber 2
  Weapon.SlotPriority 1
  States
  {
  Ready:
    TNT1 A 1 A_WeaponReady
    Loop  
  Fire:
    TNT1 A 4
    TNT1 B 6 A_FirePistol
    TNT1 C 4
    TNT1 B 5 A_ReFire
    Goto Ready
  Flash:
    TNT1 A 7 Bright A_Light1
    Goto LightDone
    TNT1 A 7 Bright A_Light1
    Goto LightDone
   }
}
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Shoot from weapon "without" player

Post by Apeirogon »

Such possible in zscript without replacing actor.
I need a way, if it possible of course, to shoot from weapon directly from inventory. Like panic button to shoot from shotgun/pistol/etc without picking them up as weapon.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Shoot from weapon "without" player

Post by Void Weaver »

Oh, seems I've got it. :D I guess this can be easily done at ZScript, but unfortunately I can provide only decor example.

That Shotgun can fire Missiles when alt-fire pressed at any part of Ready\Fire sequence without breaking shooting sequence or playing any RLauncher sprites:

Code: Select all

ACTOR AssaultShotgun : Shotgun replaces Shotgun
{
Weapon.SlotNumber 3
Weapon.SlotPriority 1
States
{
Ready:
SHTG A 1 
{
A_WeaponReady(WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
Loop
  
Fire:
SHTG A 3 
{
A_WeaponReady(WRF_NOPRIMARY|WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_OLDBUTTONS)&BT_ATTACK&&GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
SHTG A 7 
{
A_FireShotgun;
A_WeaponReady(WRF_NOPRIMARY|WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_OLDBUTTONS)&BT_ATTACK&&GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
SHTG BC 5
{
A_WeaponReady(WRF_NOPRIMARY|WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_OLDBUTTONS)&BT_ATTACK&&GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
SHTG D 4 
{
A_WeaponReady(WRF_NOPRIMARY|WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_OLDBUTTONS)&BT_ATTACK&&GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
SHTG CB 5 
{
A_WeaponReady(WRF_NOPRIMARY|WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_OLDBUTTONS)&BT_ATTACK&&GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
SHTG A 3 
{
A_WeaponReady(WRF_NOPRIMARY|WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_OLDBUTTONS)&BT_ATTACK&&GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
SHTG A 7 A_ReFire
Goto Ready
	
AltFire:
Stop
	
MissileShot:
TNT1 A 8 A_GunFlash("Flash.MissileShot")
TNT1 A 0 A_TakeInventory("RocketAmmo",1)
TNT1 A 12 A_FireProjectile("Rocket",0,0)
Stop	

Flash.MissileShot:
TNT1 A 3 Bright A_Light1
TNT1 A 4 Bright
TNT1 AA 4 Bright A_Light2
Goto LightDone	
}
}
As variant instatnt attack can be called from CustomInventory item.

Code: Select all

Actor InvMissileShooter : CustomInventory
{
+INVENTORY.ALWAYSPICKUP
Inventory.MaxAmount 0
States
{
Spawn:
POSS A -1
Pickup:
TNT1 A 0 A_JumpIf(CountInv("RocketAmmo")<=0,3)
TNT1 A 0 A_TakeInventory("RocketAmmo",1)
TNT1 A 0 A_SpawnItemEx("Rocket",0,0,Height/2,cos(pitch)*20,0,-sin(pitch)*20,0,SXF_TRANSFERPITCH)
TNT1 A 0
Stop	
}
}
Btw, in a one of those threads you can also find a some useful related stuff for current task, I guess:
CustomInventory Overlays - How To?!
[Decorate] Do X if button pressed for < 0.5 s, do Y if > 0.5
Last edited by Void Weaver on Thu Jul 11, 2019 10:05 pm, edited 2 times in total.
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: Shoot from weapon "without" player

Post by Matt »

Can a player sprite be given to an actor that has no controlling player?
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Shoot from weapon "without" player

Post by Apeirogon »

Void Weaver wrote:Oh, seems I've got it. :D I guess this can be easily done at ZScript, but unfortunately I can provide only decor example.

That Shotgun can fire Missiles when alt-fire pressed at any part of Ready\Fire sequence without breaking shooting sequence or playing any RLauncher sprites:

Code: Select all

ACTOR AssaultShotgun : Shotgun replaces Shotgun
{
Weapon.SlotNumber 3
Weapon.SlotPriority 1
States
{
Ready:
SHTG A 1 
{
A_WeaponReady(WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
Loop
  
Fire:
SHTG A 3 
{
A_WeaponReady(WRF_NOPRIMARY|WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_OLDBUTTONS)&BT_ATTACK&&GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
SHTG A 7 
{
A_FireShotgun;
A_WeaponReady(WRF_NOPRIMARY|WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_OLDBUTTONS)&BT_ATTACK&&GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
SHTG BC 5
{
A_WeaponReady(WRF_NOPRIMARY|WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_OLDBUTTONS)&BT_ATTACK&&GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
SHTG D 4 
{
A_WeaponReady(WRF_NOPRIMARY|WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_OLDBUTTONS)&BT_ATTACK&&GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
SHTG CB 5 
{
A_WeaponReady(WRF_NOPRIMARY|WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_OLDBUTTONS)&BT_ATTACK&&GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
SHTG A 3 
{
A_WeaponReady(WRF_NOPRIMARY|WRF_ALLOWRELOAD|WRF_ALLOWUSER#);
If(GetPlayerInput(INPUT_OLDBUTTONS)&BT_ATTACK&&GetPlayerInput(INPUT_BUTTONS)&BT_ALTATTACK)
{A_Overlay(2,"MissileShot");Return state("");}
Else{Return state("");}
}
SHTG A 7 A_ReFire
Goto Ready
	
AltFire:
Stop
	
MissileShot:
TNT1 A 8 A_GunFlash("Flash.MissileShot")
TNT1 A 0 A_TakeInventory("RocketAmmo",1)
TNT1 A 12 A_FireProjectile("Rocket",0,0)
Stop	

Flash.MissileShot:
TNT1 A 3 Bright A_Light1
TNT1 A 4 Bright
TNT1 AA 4 Bright A_Light2
Goto LightDone	
}
}
As variant instatnt attack can be called from CustomInventory item.

Code: Select all

Actor InvMissileShooter : CustomInventory
{
+INVENTORY.ALWAYSPICKUP
Inventory.MaxAmount 0
States
{
Spawn:
POSS A -1
Pickup:
TNT1 A 0 A_JumpIf(CountInv("RocketAmmo")<=0,3)
TNT1 A 0 A_TakeInventory("RocketAmmo",1)
TNT1 A 0 A_SpawnItemEx("Rocket",0,0,Height/2,cos(pitch)*20,0,-sin(pitch)*20,0,SXF_TRANSFERPITCH)
TNT1 A 0
Stop	
}
}
Btw, in a one of those threads you can also find a some useful related stuff for current task, I guess:
CustomInventory Overlays - How To?!
[Decorate] Do X if button pressed for < 0.5 s, do Y if > 0.5
That require changing weapon code, while I need a way to do so without changing weapon code.
Matt wrote:Can a player sprite be given to an actor that has no controlling player?
No, since psprite class nailed to playerinfo struct and you cant "deattach" it and/or create new psprite class/playerinfo struct.



Problem with weapon, that a_fireprojectile, and similar weapon functions, works only if player available. So I can change weapon state, when it lie on the ground, to "fire" and it play it states and animations, but dont actually shoot. And in inventory I cant call states of it without using it as reference to psprite.
So looks like this is impossible.
User avatar
Void Weaver
Posts: 724
Joined: Thu Dec 18, 2014 7:15 am
Contact:

Re: Shoot from weapon "without" player

Post by Void Weaver »

Apeirogon wrote:That require changing weapon code, while I need a way to do so without changing weapon code.
It's quite significant detail. Anyway
Void Weaver wrote:As variant, instatnt attack can be called from CustomInventory item.
Give the similar item via ACS or, that's even better, write it on ACS entirely. This way doesn't bother about weapon or player actors altering.
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: Shoot from weapon "without" player

Post by Matt »

Apeirogon wrote:Such possible in zscript without replacing actor.
I need a way, if it possible of course, to shoot from weapon directly from inventory. Like panic button to shoot from shotgun/pistol/etc without picking them up as weapon.
Do you mean something like:

1. I am holding BFG
2. I need to shoot pistol
3. I am still holding BFG but a pistol shot comes out of me

If so, is it acceptable to replace the pistol, or do you need a solution that uses the vanilla pistol actor?
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Shoot from weapon "without" player

Post by Apeirogon »

Second, vanilla BFG and vanilla pistol.

I ant to make it applicable to any weapon in general.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Shoot from weapon "without" player

Post by Graf Zahl »

To make it short: All weapon actions directly access the PlayerInfo. Good luck trying to set it up so that it works without one. Some may just work without handling ammo consumption but others will just do nothing without a player.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Shoot from weapon "without" player

Post by Apeirogon »

Not without playerinfo, without using weapon states as reference for psprite.
Post Reply

Return to “Scripting”