Jump to content

Need help setting up random summon


Syn3r

Recommended Posts

I'm trying to make a mod that spawns a random creature/npc when you throw a grenade or hit a target or something like that. I know how to do a single creature but am interested in whether this is possible or not.

Link to comment
Share on other sites

I've done Summoning Grenades, and although I haven't done them, a random is easily achievable.  You need to make a note of all the NPCs you want to spawn (preferably making a duplicate for your mod), and then add them as properties (actorbase IIRC) in a script.  When the grenade explodes get it to spawn a small object that has an OnLoad() event attached to it, and attach the script to it.  You could then do a Utility.Random(1, X) replacing X with however many NPCs you have, and then write a script that matches the number to the NPC and summon it.  You could just do a load of If/ElseIf statements to do it or work out an array to do it.  If you're confident enough to spot mistakes then ChatGPT may be able to tidy up any code (I know it has issues with creating arrays sometimes, although if you cut and paste the compiler error it usually works out it's mistake). 

There are two things I would heavily suggest.

Don't summon named NPCs directly.  Named NPCs are generally unique and there's only meant to be one in the world, so if you want them clone them.  Remember to remove the unique flag if you do this.

Make sure there's a time out or someway to disable and delete the NPC.  Some NPCs will wander off, sometimes with weird effects later down the line.  If you set a timeout, all you need to do is set a timer for X seconds, and then when that trips just call a disable and delete on it.  That will need to be attached to the NPC.

Link to comment
Share on other sites

OK Damn, thats good info and tells me what I couldn't figure out. I'm a scripting newb so I need to get to figuring that out, though now I know what I need to do.

Not summoning Named/ Unique NPCs is common sense in modding isn't it?

Thank you for the info. I will be getting to making my random summon thing( Haven't decided what weapon to attach it to yet)

Link to comment
Share on other sites

To avoid trashing FPS and bloating savegames when spawning persistent actors always consider their lifecycle:

(a) what happens to them when they die (have you fully released all persistence on them).

(b) what happens when they unload alive (leave them alone to bloat up or clean them up).

Reading up on object persistence should be job #2, right after successfully working out how to spawn stuff.

Link to comment
Share on other sites

Ok after several hours of trying to figure it out I have something that I can't get to work, it's supposed to work according to the bethesda ChatGPT modding thing.

Heres the script it says should work, I think its outdated and is trying to have me use an old method.
 

Scriptname SpawnCreatureOnFire extends ObjectReference

; Properties
ObjectReference Property CreatureToSpawn Auto
Float Property SpawnRadius = 200.0 Auto
Keyword Property WeaponKeyword Auto
Spell Property DespawnSpell Auto

Event OnEquipped(Actor akActor)
    RegisterForSingleUpdate(1.0) ; Check every second
EndEvent

Event OnUnequipped(Actor akActor)
    UnregisterForUpdate()
EndEvent

Event OnUpdate()
    ; Check if the player has fired the weapon
    Actor player = Game.GetPlayer()
    if player.IsWeaponDrawn()
        ObjectReference spawnedCreature = SpawnRandomCreature()
        ; Apply despawn spell to the spawned creature
        if spawnedCreature
            DespawnSpell.Cast(spawnedCreature)
        endif
    endif
    RegisterForSingleUpdate(1.0) ; Continue checking every second
EndEvent

Function ObjectReference SpawnRandomCreature()
    Actor player = Game.GetPlayer()
    Float randomAngle = Math.RandomFloat(0, 360)
    Float randomDistance = Math.RandomFloat(0, SpawnRadius)
    Float xOffset = randomDistance * Math.Cos(randomAngle)
    Float yOffset = randomDistance * Math.Sin(randomAngle)
    Float zOffset = player.GetHeight()

    Float spawnX = player.GetPositionX() + xOffset
    Float spawnY = player.GetPositionY() + yOffset
    Float spawnZ = player.GetPositionZ() + zOffset

    ObjectReference newCreature = CreatureToSpawn.PlaceAtMe(spawnX, spawnY, spawnZ)
    return newCreature
EndFunction

 

Here's what it says when I try to compile it.

 

Papyrus Compiler Version 2.8.0.4 for Fallout 4
Copyright (C) ZeniMax Media. All rights reserved.
Starting 1 compile threads for 1 files...
Compiling "A0SynSpawnRandomScript.psc"...
C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\Scripts\Source\User\A0SynSpawnRandomScript.psc(4,25): const scripts may only contain const auto properties. Property CreatureToSpawn cannot be defined
C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\Scripts\Source\User\A0SynSpawnRandomScript.psc(4,25): const scripts may not contain data, script variable ::CreatureToSpawn_var cannot be defined
C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\Scripts\Source\User\A0SynSpawnRandomScript.psc(5,15): const scripts may only contain const auto properties. Property SpawnRadius cannot be defined
C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\Scripts\Source\User\A0SynSpawnRandomScript.psc(5,15): const scripts may not contain data, script variable ::SpawnRadius_var cannot be defined
C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\Scripts\Source\User\A0SynSpawnRandomScript.psc(6,17): const scripts may only contain const auto properties. Property WeaponKeyword cannot be defined
C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\Scripts\Source\User\A0SynSpawnRandomScript.psc(6,17): const scripts may not contain data, script variable ::WeaponKeyword_var cannot be defined
C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\Scripts\Source\User\A0SynSpawnRandomScript.psc(7,15): const scripts may only contain const auto properties. Property DespawnSpell cannot be defined
C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\Scripts\Source\User\A0SynSpawnRandomScript.psc(7,15): const scripts may not contain data, script variable ::DespawnSpell_var cannot be defined
C:\Program Files (x86)\Steam\steamapps\common\Fallout 4\Data\Scripts\Source\User\A0SynSpawnRandomScript.psc(30,25): extraneous input 'SpawnRandomCreature' expecting LPAREN
No output generated for A0SynSpawnRandomScript.psc, compilation failed.

Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on A0SynSpawnRandomScript.psc

Also, how do I clean up to Papyrus script manager? I create numerous scripts and I deleted the file in the scripts folder but they still show up and I can't use the script name anymore.

Link to comment
Share on other sites

You could do this without scripts, use the explosion to spawn an object, like the mirelurk queen eggs ...

then use a leveled NPC list to collect all the actors you would like to have as possible spawns.

the actor base will use the leveld NPC actor list as template and therefore the spawned NPC will use the appearance of one of the actors in that list as well as any other template you have attached.

done.

01.png

02.png

Link to comment
Share on other sites

4 hours ago, Syn3r said:

"Ok after several hours of trying to figure it out I have something that I can't get to work, it's supposed to work according to the bethesda ChatGPT modding thing."

I do not believe the ChatGPT is sufficient for Papyrus scripting.  While not exactly the same as what you are after, you might give kinggath's Bethesday Mod School a watch, specifically the vids on deployable turrets mod.  kinggath discusses the scripting required for this particular mod so hopefully understanding that will help you in your journey.

 

Link to comment
Share on other sites

I can spawn them now thanks Qrsr your advice really helped me get it figured out. Now I just need to figure out hot to get them to leave after a couple minutes, I was going to do a simple timer script to kill the creature, but the script area is all grayed out and I can't figure it out.

Link to comment
Share on other sites

Have a look in the templates tab of the NPC, and see if Use Script is checked.  If it is that means the NPC is using a template from another NPC and that will cause the script box to be greyed out.  Simply uncheck that box and you should be able to add a script.

If whatever it's templated from uses a script that you need (settlers have a script that's used for various settlement related things for example), then you'll need to see what it's called and just add it to the script list (I can't remember whether it keeps any templated scripts or removes them).

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...