Jump to content

I will spawn an item with SPAWN(), but how do I assign a script to it? [SOLVED]


Shkwarkel

Recommended Posts

I create an item using the SPAWN command. The item spawns in front of the player at a distance of 100 on the x-axis. I want when the player picks up it a specific scpit is executed. Can you help me to do it? I think I need to use TID?

изображение_2023-12-20_142157869.png

Edited by Shkwarkel

Share this post


Link to post

Not sure if possible purely with scripting. You could make a simple Medikit replacement actor that runs a script when picked up. 

Share this post


Link to post

Off the top of my head....

 

assuming you are only spawning one  Medikit2 and only the player can pick it up (and it's single player...maybe)

 

int aTag = UniqueTID();

 

do{

  delay(1);

  int x = GetActorX(0) + 200.0;

  int y = GetActorY(0);

  int z = GetActorZ(0);

} until (Spawn("Medikit2",x,y,z,aTag,0));

 

//might want a delay here?

 

while ( ThingCountName("Medikit2", aTag) > 0 )
{
   delay(1);
}

 

//then put your wanted code here or ACS_Execute to start the desired script

 

 

Or do it in DECORATE, making the class execute a specified script on pickup.

Share this post


Link to post
4 hours ago, Russell_P said:

Off the top of my head....

 

assuming you are only spawning one  Medikit2 and only the player can pick it up (and it's single player...maybe)

 

int aTag = UniqueTID();

 

do{

  delay(1);

  int x = GetActorX(0) + 200.0;

  int y = GetActorY(0);

  int z = GetActorZ(0);

} until (Spawn("Medikit2",x,y,z,aTag,0));

 

//might want a delay here?

 

while ( ThingCountName("Medikit2", aTag) > 0 )
{
   delay(1);
}

 

//then put your wanted code here or ACS_Execute to start the desired script

 

 

Or do it in DECORATE, making the class execute a specified script on pickup.

Yeah, it works. Thank you so much. If it's not too much trouble, could you give me a link to a tutorial on how to assign a script to an object via DECORATE? I think I could really use it in my project.

Share this post


Link to post

The way I always done it is i placed a thing outside of the map with the dormant flag checked then teleport & Thing_Activate it instead of spawning

And it had the appropriate action already attached to it that upon picking it up/killing it if it sa monster the action is performed like open a door

Share this post


Link to post

I don't know of any tutorials. I tend to bash my head against the zdoom wiki until I figure things out. Failing that I go and find a mod that does what I want and then use that as an example.

 

I'm very rusty on some of this stuff, but I had a pickup in doom raider that executed a script. Here's the DECORATE code, you should hopefully figure it out from that.

 

ACTOR ProtectionAmulet : CustomInventory 19121
{
    Inventory.PickupMessage "Amulet of protection"
    Inventory.Icon "ST_AMUL"
    +INVENTORY.FANCYPICKUPSOUND
    +INVENTORY.ALWAYSPICKUP
    +COUNTITEM
    
    Inventory.PickupFlash none 

    States
    {
        Spawn:
            AMUL A 12 //Bright
            AMUL B 6
            Loop
            
        Pickup:
            TNT1 A 0 A_GiveInventory("ProtectionArmour",1)
            TNT1 A 0  ACS_NamedExecuteAlways("blueFlash", 0)
            Stop
    }
}

 

 

edit:

 

Try this

 

ACTOR Medikit2 : CustomInventory  
{
    Inventory.PickupMessage "myMessage"
    +INVENTORY.ALWAYSPICKUP
    
    States
    {
        Spawn:
            AMUL A 12 //change this to whatever your sprites are
            AMUL B 6
            Loop
            
        Pickup:
            TNT1 A 0 A_GiveInventory("Medikit",25) //assuming this is a medikit variant and you want the same effect
            TNT1 A 0  ACS_NamedExecuteAlways("myScript", 0)
            Stop
    }
}

 

...I seem to remember that only classses that inherit from CustomInventory can have pickup states. If I'm wrong then I'm overcomplicating the whole thing

Edited by Russell_P
added code suggestion

Share this post


Link to post
On 12/21/2023 at 2:23 AM, candyman64 said:

The way I always done it is i placed a thing outside of the map with the dormant flag checked then teleport & Thing_Activate it instead of spawning

And it had the appropriate action already attached to it that upon picking it up/killing it if it sa monster the action is performed like open a door

good idea, thank you!

Share this post


Link to post
22 hours ago, Russell_P said:

I don't know of any tutorials. I tend to bash my head against the zdoom wiki until I figure things out. Failing that I go and find a mod that does what I want and then use that as an example.

 

I'm very rusty on some of this stuff, but I had a pickup in doom raider that executed a script. Here's the DECORATE code, you should hopefully figure it out from that.

 

ACTOR ProtectionAmulet : CustomInventory 19121
{
    Inventory.PickupMessage "Amulet of protection"
    Inventory.Icon "ST_AMUL"
    +INVENTORY.FANCYPICKUPSOUND
    +INVENTORY.ALWAYSPICKUP
    +COUNTITEM
    
    Inventory.PickupFlash none 

    States
    {
        Spawn:
            AMUL A 12 //Bright
            AMUL B 6
            Loop
            
        Pickup:
            TNT1 A 0 A_GiveInventory("ProtectionArmour",1)
            TNT1 A 0  ACS_NamedExecuteAlways("blueFlash", 0)
            Stop
    }
}

 

 

edit:

 

Try this

 

ACTOR Medikit2 : CustomInventory  
{
    Inventory.PickupMessage "myMessage"
    +INVENTORY.ALWAYSPICKUP
    
    States
    {
        Spawn:
            AMUL A 12 //change this to whatever your sprites are
            AMUL B 6
            Loop
            
        Pickup:
            TNT1 A 0 A_GiveInventory("Medikit",25) //assuming this is a medikit variant and you want the same effect
            TNT1 A 0  ACS_NamedExecuteAlways("myScript", 0)
            Stop
    }
}

 

...I seem to remember that only classses that inherit from CustomInventory can have pickup states. If I'm wrong then I'm overcomplicating the whole thing

I see what you mean. Thanks for your help. 

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
Reply to this topic...

×   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...