[ACS] How can I remove a spawned turret?

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
Empyre
Zandrone
Posts: 1316
Joined: Sun Jul 08, 2012 6:41 am
Location: Garland, TX, USA

[ACS] How can I remove a spawned turret?

#1

Post by Empyre » Sun Apr 09, 2017 4:53 pm

I want to create a reusable inventory item that spawns a turret. I can do that easily in DECORATE. However, I want the item to remove any existing turret the player has (but not other players' turrets) before spawning the new one, thus limiting the player to one at a time. Furthermore, I want a player's turret to be removed when the player disconnects or spectates.

I assume this will require ACS, but I don't know ACS, so I am asking for help. I know enough about coding to be able to understand what you tell me to do. I probably could also modify the code to fit my needs, but I wouldn't be able to create the code in the first place, yet. Solving this problem, with help, might be all I need to then begin exploring the possibilities of ACS.

You will, of course, be thanked in the WADINFO (and here, too).
"For the world is hollow, and I have touched the sky."

User avatar
NachtIntellect
Forum Regular
Posts: 480
Joined: Mon Jun 11, 2012 9:20 am
Location: Bienenstock, Germany

[ACS] Re: How can I remove a spawned turret?

#2

Post by NachtIntellect » Sun Apr 09, 2017 5:05 pm

Hmm alright so first, is the turret treated as a monster? Can you show me what you have so far? My idea is to get the player number and use it to give the thing an ID which will allow you to manipulate it in various wonderful ways.

Lollipop
Zandrone
Posts: 1123
Joined: Tue Jul 24, 2012 10:34 am
Location: Denmark

[ACS] Re: How can I remove a spawned turret?

#3

Post by Lollipop » Sun Apr 09, 2017 5:32 pm

You know the methodology for giving all players a unique TID, right? Use the same method with another range for the turrets. When the player uses the item, a simple acs script that deletes the actor with the tid of the turret base id + playernumber() and then spawning the new turret with that same id would do the trick. When disconnecting, just do the deletion part of it in a disconnect script.
ACS isn't all that hard, just read on the wiki and you'll be fine. ;)

User avatar
Empyre
Zandrone
Posts: 1316
Joined: Sun Jul 08, 2012 6:41 am
Location: Garland, TX, USA

[ACS] Re: How can I remove a spawned turret?

#4

Post by Empyre » Sun Apr 09, 2017 5:53 pm

The turret would be a friendly monster. I have not started code on the turret. I'm waiting to see if I can do what I want to do before I start it. I know how to make an item that would make one turret or unlimited turrets. I already have the player able to make "ghosts", with a translucent lost soul sprite with translation ice and a timer before it dies, so the player wouldn't wind up with an unlimited number of them.

I have a basic idea what a TID is, but that's about it. With some example code, I should be able to take it from there.
"For the world is hollow, and I have touched the sky."

User avatar
NachtIntellect
Forum Regular
Posts: 480
Joined: Mon Jun 11, 2012 9:20 am
Location: Bienenstock, Germany

[ACS] Re: How can I remove a spawned turret?

#5

Post by NachtIntellect » Sun Apr 09, 2017 6:00 pm

I was actually writing it out for him, but to be honest I am so tired I can't even think properly so I won't do it tonight and if Empyre's still having trouble with it tomorrow I will give him a hand but yeah, use ACS_ExecuteAlways on the first state of the Actor in Decorate you want then write a script for it that includes adding an if statement if(ThingCountName("Turret",TID+PlayerNumber())==0) underneath of that have Thing_ChangeTID(0,1+PlayerNumber()); then reference it with an if statement that checks for the TID and player number then use Thing_Remove(TID+PlayerNumber()), I get the feeling I might be missing something there so I am sorry if I confused you, I am sure if you put your mind to it though, you can find what I might be missing

Lollipop
Zandrone
Posts: 1123
Joined: Tue Jul 24, 2012 10:34 am
Location: Denmark

[ACS] Re: How can I remove a spawned turret?

#6

Post by Lollipop » Sun Apr 09, 2017 7:19 pm

I found out on the pointers wiki page that players usually don't use the master or or target pointers. I don't know, can you possibly use this information to avoid having to use ACS? It would be a hilarious hack, but it could work.

User avatar
Empyre
Zandrone
Posts: 1316
Joined: Sun Jul 08, 2012 6:41 am
Location: Garland, TX, USA

[ACS] Re: How can I remove a spawned turret?

#7

Post by Empyre » Sun Apr 09, 2017 7:56 pm

Lollipop wrote:I found out on the pointers wiki page that players usually don't use the master or or target pointers. I don't know, can you possibly use this information to avoid having to use ACS? It would be a hilarious hack, but it could work.
LOL I looked at that page this morning and thought of the same idea, but I don't know how I could do that. I would probably still have to use ACS. I think that your TID idea is more elegant.
"For the world is hollow, and I have touched the sky."

User avatar
Empyre
Zandrone
Posts: 1316
Joined: Sun Jul 08, 2012 6:41 am
Location: Garland, TX, USA

[ACS] Re: How can I remove a spawned turret?

#8

Post by Empyre » Tue Apr 11, 2017 9:34 am

You wanted to see my code for the turrets, but I hadn't written it yet. Now I have.
Here is the code for the plasma turret:

Code: Select all

ACTOR OPPlasmaTurretMaker : CustomInventory
{
  Tag "Plasma Turret Maker"
  +INVENTORY.INVBAR
  +INVENTORY.UNDROPPABLE
  Inventory.Icon "COL4A0"
  Inventory.MaxAmount 1
  States
  {
  Use:
	TNT1 A 1
	TNT1 A 0 A_PlaySound("cyber/hoof")
	TNT1 A 0 A_SPawnItemEx("OPPlasmaTurret",0,0,0,0,0,0,0,SXF_SETMASTER)
	Fail
  }
}

ACTOR OPPlasmaTurret
{
  RenderStyle "Add"
  Alpha 0.75
  Mass 1000000
  Health 1000
  Damage 1024
  DamageType "PlayerDamage"
  PainChance 0
  Species "OPPlayer"
  +FRIENDLY
  +NOBLOCKMONST
  +THRUSPECIES
  +DONTHARMSPECIES
  +NOBLOOD
  +LOOKALLAROUND
  +NOTAUTOAIMED
  +MISSILEMORE
  +MISSILEEVENMORE
  +NOFEAR
  +QUICKTORETALIATE
  Radius 16
  Height 40
  Speed 0
  Monster
  +FLOORCLIP
  ActiveSound "baby/active"
  PainSound "pain/pain"
  Obituary "%o was gibbed by a plasma turret!"
  States
  {
  Spawn:
    COL4 A 10 A_Look
    Loop
  See:
    COL4 A 3 A_Chase
    Loop
  Melee:
  Missile:
    COL4 A 1 Bright A_FaceTarget
	COL4 A 2 A_CustomMissile("OPTurretBall",28,0,0,CMF_CHECKTARGETDEAD)
    Goto See
  Pain:
    COL4 A 3
    COL4 AI 3 A_Pain
    Goto See
  Death:
    COL4 A 12 A_SpawnItemEx("OPTurretDeath",0,0,24,0,0,0,0,SXF_SETMASTER)
	Stop
  }
}

ACTOR OPTurretDeath
{
  RenderStyle "Add"
  Alpha 0.75
  Damage 1024
  DamageType "PlayerDamage"
  Species "OPPlayer"
  +DONTHARMSPECIES
  +NOGRAVITY
  Obituary "%o was caught in a plasma turret explosion!"
  States
  {
  Spawn:
    TNT1 A 1
	TNT1 A 0 A_PlaySound("world/barrelx")
    MISL B 8 Bright A_Explode(1024,256,FALSE)
    MISL C 6 Bright
    MISL D 4 Bright
	Stop
  }
}

ACTOR OPTurretBall : PlasmaBall
{
  Damage 1024
  DamageType "PlayerDamage"
  Scale 0.75
  Speed 25
  Obituary "%o couldn't get away from from %k's plasma turret."
  BounceCount 5
  BounceType "Grenade"
  BounceFactor 1.0
  WallBounceFactor 1.0
//  ReactionTime 50
//  SeeSound "NoSound"
  +MTHRUSPECIES
  +SEEKERMISSILE
  States
  {
  Spawn:
    PLS2 AB 6 Bright A_SeekerMissile(60,90,SMF_LOOK|SMF_PRECISE,256)
//	TNT1 A 0 A_CountDown
    Loop
  Death:
    PLS2 CDE 6 Bright
    Stop
  }
}
Here is the code for the rail turret:

Code: Select all

ACTOR OPRailTurretMaker : CustomInventory
{
  Tag "Rail Turret Maker"
  +INVENTORY.INVBAR
  +INVENTORY.UNDROPPABLE
  Inventory.Icon "COL2A0"
  Inventory.MaxAmount 1
  States
  {
  Use:
	TNT1 A 1
	TNT1 A 0 A_PlaySound("cyber/hoof")
	TNT1 A 0 A_SPawnItemEx("OPRailTurret",0,0,0,0,0,0,0,SXF_SETMASTER)
	Fail
  }
}

ACTOR OPRailTurret
{
  RenderStyle "Add"
  Alpha 0.75
  Mass 1000000
  Health 1000
  DamageType "PlayerDamage"
  PainChance 0
  Species "OPPlayer"
  +FRIENDLY
  +NOBLOCKMONST
  +THRUSPECIES
  +DONTHARMSPECIES
  +NOBLOOD
  +LOOKALLAROUND
  +NOTAUTOAIMED
  +MISSILEMORE
  +MISSILEEVENMORE
  +NOFEAR
  +QUICKTORETALIATE
  Radius 16
  Height 40
  Speed 0
  Monster
  +FLOORCLIP
  ActiveSound "baby/active"
  PainSound "pain/pain"
  Obituary "%o was punctured by a rail turret!"
  States
  {
  Spawn:
    COL2 A 10 A_Look
    Loop
  See:
    COL2 A 3 A_Chase
    Loop
  Melee:
  Missile:
    COL2 A 1 Bright A_FaceTarget
	TNT1 A 0 A_CustomRailgun(-1,0,NONE,"Green",RGF_SILENT,1,0,"OPTurretPuff")
	TNT1 A 0 A_PlaySound("weapons/railgf")
	COL2 A 9
    Goto See
  Pain:
    COL2 A 3
    COL2 AI 3 A_Pain
    Goto See
  Death:
    COL2 A 12 A_SpawnItemEx("OPTurretDeath",0,0,24,0,0,0,0,SXF_SETMASTER)
	Stop
  }
}

ACTOR OPTurretPuff : BulletPuff
{
  +FORCERADIUSDMG
  +NODAMAGETHRUST
  +PUFFGETSOWNER
  -ALLOWPARTICLES
  +ALWAYSPUFF
  +PUFFONACTORS
  VSpeed 0
  DamageType PlayerDamage
  Obituary "%o was punctured by a rail turret."
  States
  {
  Spawn:
  Missile:
    TNT1 A 1
	TNT1 A 1 A_Explode (1024, 16, FALSE, FALSE, 16)
	stop
  }
}
I know that these are way overpowered, but so is the rest of opweapons, so they fit right in. As-is, the player can make an unlimited number of the turrets, and I don't want it to be that way, but i do want the player to be able to move the turret an unlimited number of times (replacing the old turret with a new one at a new location). Thus, once we have the removal working, the player would be limited to one of each.

If you tell me how to remove one of them, I should be able to apply that technique to the other one.
"For the world is hollow, and I have touched the sky."

User avatar
Empyre
Zandrone
Posts: 1316
Joined: Sun Jul 08, 2012 6:41 am
Location: Garland, TX, USA

[ACS] Re: How can I remove a spawned turret?

#9

Post by Empyre » Thu Apr 13, 2017 6:59 am

I learned enough ACS to come up with this solution. The players can place unlimited turrets, but at a limited pace.

Code: Select all

#library "oplibrary"
#include "zcommon.acs"

script "OPRailTurretGiver" ENTER
{
  TakeInventory("OPRailTurretMaker",4);
  GiveInventory("OPRailTurretMaker",2);
  while (TRUE)
  {
    Delay(35*20); //seconds * 35 tics/second = tics
	GiveInventory("OPRailTurretMaker",1);
  }
}

script "OPPlasmaTurretGiver" ENTER
{
  TakeInventory("OPPlasmaTurretMaker",4);
  GiveInventory("OPPlasmaTurretMaker",2);
  while (TRUE)
  {
    Delay(35*20); //seconds * 35 tics/second = tics
	GiveInventory("OPPlasmaTurretMaker",1);
  }
}
"For the world is hollow, and I have touched the sky."

User avatar
Popsoap
 
Posts: 86
Joined: Mon Jun 04, 2012 2:38 pm
Location: Inside a wall

[ACS] Re: How can I remove a spawned turret?

#10

Post by Popsoap » Thu Apr 13, 2017 4:25 pm

Empyre wrote:If you tell me how to remove one of them, I should be able to apply that technique to the other one.
I think A_DamageChildren can specify a DamageType, if you put that function on the same items that spawn the sentries (right before the new one is placed). You can kill a specific turret type by using DamageFactor to prevent other turret types from being damaged.

User avatar
Empyre
Zandrone
Posts: 1316
Joined: Sun Jul 08, 2012 6:41 am
Location: Garland, TX, USA

[ACS] Re: How can I remove a spawned turret?

#11

Post by Empyre » Thu Apr 13, 2017 5:02 pm

Thank you for the idea. That probably would have worked.

Actually, I am happy with the solution I found. OPWeapons with this code is on my second server now. If it turns out that players still flood the server with too many turrets, I can increase the delay from 20 seconds and/or decrease the maximum they can carry from 4.
"For the world is hollow, and I have touched the sky."

User avatar
FranckyFox2468
Forum Regular
Posts: 180
Joined: Sat May 07, 2016 8:30 pm

[ACS] Re: How can I remove a spawned turret?

#12

Post by FranckyFox2468 » Fri Apr 21, 2017 2:57 am

wait, SXF_SETMASTER works on players? Cause last time i tried to apply a A_killchildren or such on a friendly summoned monsters via items it didn't work at all, guess i got something wrong?

Post Reply