Jump to content
  • 0

How do you make Exclusive Summons?


Nihlith

Question

Hi. I've been working on a TC where I want the player to be able to work with allies. I think it would be cool to make it so that the Player can summon his allies with a spell. That way the player can have allies when they want them but they don't need to be overly concerned with their safety and they don't need to deal with them if they don't want npc help.

 

There's a big problem though, I don't want the player to be able to summon more than one ally of a particular type at any particular time because if they can do that they can spam the level with npc fodder and it'll be silly.

 

What would the code look like if the summon spell always worked but if the creature being summoned already existed on the map the first one would vanish and leave only the newest summon? Would that be better done with an event handler or a struct inside the spell? This is the code I've got for the spell, its ZScript I run on gzdoom version "4.10.0". I don't know where to start.

 

Class SUMMONMONSTER : CustomInventory
{
    int inuse;
    Default
    {
     +INVENTORY.INVBAR
     +INVENTORY.UNDROPPABLE
     +INVENTORY.UNTOSSABLE
     Inventory.Icon "FAMSA0";
     }
     
    States
    {
    Use:
        TNT1 A 0 A_Overlay(-2,"RAY");
        TNT1 A 0 A_OverlayOffset(-2,0,32);
        Fail;
    RAY:
        TNT1 A 0
{
    if (CountInv("MANA") <= 59)
        return ResolveState("NoRAY"); //if insufficent mana go to fizzled spell sequence
    return ResolveState(null); //otherwise, don't jump, move on to the next frame
}
        TOSS ABC 1;
        TNT1 A 0 {
        A_Print("SUMMON MONSTER");
        A_TakeInventory("MANA",60);
        A_SpawnItemEx("Malatrix",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0);
        A_SpawnItem("TeleportFog"); 
        A_PlaySound("familiar/throw");
        }
        TOSS D 2 ;
        TOSS CBA 2;
        TNT1 A 1;
        Fail;        
        
        NoRAY:
        TOSS ABC 1 {
        A_StartSound("NotEnoughMana", CHAN_WEAPON);
        A_Print("NOT ENOUGH MANA");
        }
        TOSS D 2;
        TOSS CBA 2;
        TNT1 A 1 A_ClearOverlays(-2,-2);
        Fail;                    
    }
}

 

 

Share this post


Link to post

2 answers to this question

Recommended Posts

  • 1

Have you tried creating a Master/child relationship between the player and the spawned minion? In this way you can call for A_RemoveChildren and get rid of them whenever you're about to summon a new one.

 

I think it should work as that, without necessarily pointing to the item owner directly (so, just add A_RemoveChildren just before the summon function and add the SXF_SETMASTER flag in A_SpawnItemEx).

Share this post


Link to post
  • 0
16 hours ago, Kan3 said:

Have you tried creating a Master/child relationship between the player and the spawned minion? In this way you can call for A_RemoveChildren and get rid of them whenever you're about to summon a new one.

 

I think it should work as that, without necessarily pointing to the item owner directly (so, just add A_RemoveChildren just before the summon function and add the SXF_SETMASTER flag in A_SpawnItemEx).

 

Oh, that is very slick. The code now reads 

 

Class SUMMONMONSTER : CustomInventory
{
	int inuse;
	Default
	{
	 +INVENTORY.INVBAR
	 +INVENTORY.UNDROPPABLE
     +INVENTORY.UNTOSSABLE
	 Inventory.Icon "FAMSA0";
	 }
	 
	States
	{
	Use:
		TNT1 A 0 A_Overlay(-2,"RAY");
		TNT1 A 0 A_OverlayOffset(-2,0,32);
		Fail;
	RAY:
		TNT1 A 0
{
    if (CountInv("MANA") <= 59)
        return ResolveState("NoRAY"); //if insufficent mana go to fizzled spell sequence
    return ResolveState(null); //otherwise, don't jump, move on to the next frame
}
		TOSS AB 1;
		TOSS C 1 A_RemoveChildren(True | RMVF_EVERYTHING);
		TNT1 A 0 {
		A_Print("SUMMON MONSTER");
		A_TakeInventory("MANA",60);
		A_SpawnItemEx("Malatrix",50,50,60,0,0,0,SXF_NOCHECKPOSITION, SXF_SETMASTER);
		A_SpawnItem("TeleportFog"); 
		A_PlaySound("familiar/throw");
		A_PlaySound("ARRIVE");
		}
		TOSS D 2 ;
		TOSS CBA 2;
		TNT1 A 1;
		Fail;		
		
		NoRAY:
		TOSS ABC 1 {
		A_StartSound("NotEnoughMana", CHAN_WEAPON);
		A_Print("NOT ENOUGH MANA");
		}
		TOSS D 2;
		TOSS CBA 2;
		TNT1 A 1 A_ClearOverlays(-2,-2);
		Fail;					
	}
}

And it works perfectly, it creates the impression of moving the summons from place to place instead of creating it from scratch AND ITS WAY EASIER than I thought it was going to be. Fuck yes, thank you and a fond cowabunga!

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...