Script help please: Referencing multiple NPCs

Post » Fri Feb 19, 2010 5:24 am

I have a script that adds a random chance for an NPC to appear out of a list of several NPCs. I want to make this script also have a chance for multiple NPCs to appear as well rather than just one at a time. How would I go about doing this?

Would I just use the same reference to set them? For example:

ref MyNPC

Set MyNPC to Man1 & Man2

In this case, Man1 and Man2 would be the two different NPCs' ids.

How would that work with a resurrect command? Would it resurrect both NPCs or just one? Same thing with other commands that are pointed to the refence.

Or is this being done completely wrong?
User avatar
Matt Gammond
 
Posts: 3410
Joined: Mon Jul 02, 2007 2:38 pm

Post » Fri Feb 19, 2010 1:00 pm

No you can't set one ref variable to two ID's at the same time. You could either have multiple variables, so you can use them all at once, or set it to the first one, do everything you need with that value, and then set it to the next value, and so on.

What's more important is to make sure you don't have more than one instance of an NPC around at the same time, as many functions work on the base ID, and would affect both "clones" if you created a second one, and you probably don't want to unravel that one.
User avatar
Gill Mackin
 
Posts: 3384
Joined: Sat Dec 16, 2006 9:58 pm

Post » Fri Feb 19, 2010 8:34 am

You could use PlaceAtMe for an actual NPC, no refs would be required and you could make multiple NPC's with different scripts inventory etc.

The PlaceAtMe bug doesn't occur with respawning NPC's and Creatures as the creature/npc is removed after it dies.

PlaceAtMe is used for all the extra summons created in OOO.
User avatar
Jodie Bardgett
 
Posts: 3491
Joined: Sat Jul 29, 2006 9:38 pm

Post » Fri Feb 19, 2010 8:16 am

I was afraid I couldn't do that. It would've made my life easier if I could. Oh well. I can still work with it. Thanks Ghastly.

Fillythebish, I was actually using the Moveto command, and when the NPC died, move them back to their "holding cell" and use the resurrect command. The thing I'm worried about is equipment loss from doing that. Wouldn't the NPC drop their weapons when killed and when resurrected, lose them? I can't recall atm. The other thing I'd be worried about is the eventual breaking from weapon degradation.

Placeatme and using spawn points would resolve this I suppose, but I don't want there to be a 3 day timer for respawning. I want the NPCs available right away after defeat again. Or at least a day at the most. Even if so, the script pulls a random number, and if the number = a certain value, then there is another random number. This random number determines the NPC that is called to the player. What happens when the script pulls a number to an NPC that is already dead? Would it cause a crash, cause the script to fail and never be used again, or nothing happen at all and the script continues again when called to work?
User avatar
CxvIII
 
Posts: 3329
Joined: Wed Sep 06, 2006 10:35 pm

Post » Fri Feb 19, 2010 3:16 am

Placeatme and using spawn points would resolve this I suppose, but I don't want there to be a 3 day timer for respawning. I want the NPCs available right away after defeat again. Or at least a day at the most. Even if so, the script pulls a random number, and if the number = a certain value, then there is another random number. This random number determines the NPC that is called to the player. What happens when the script pulls a number to an NPC that is already dead? Would it cause a crash, cause the script to fail and never be used again, or nothing happen at all and the script continues again when called to work?

When you use PlaceAtMe it generates a whole new NPC. Like if you had a spawn point that adds 3 of the same creatures, they are the same in type and inventory etc, but they are all unique as an individual creation.

You could have 20 NPC's of the same placed if you want. They will all look the same, have the same inventory etc but they will all act independently for their AI.

This way you could have NPC's set up to be called who have unique inventories, say 5 bandits who have 5 different weapons, 5 different AI, 5 different armour variations or leveled lists of items.

If they lose a weapon or a weapon breaks it will have no bearing on the next NPC that is generated, as it is a unique creation.

Think of PlaceAtMe as a spawn point you can call on when you want, to give you what you want.

If you want the dead to dissapear, as if they have magically been replaced, you just use Begin OnDeath and Disable. They will not be visible and will be removed after 3 days
User avatar
Silvia Gil
 
Posts: 3433
Joined: Mon Nov 20, 2006 9:31 pm

Post » Fri Feb 19, 2010 9:41 am

If you want to bandit to appear to have been brought back to life in the same spot, or just appear in the same spot as the dead bandit you can use this.

ref targetfloat posxfloat posyfloat poszBegin OnDeath     set target to PlaceAtMe MyNewBandit 1     Disable     set posx to getpos x     set posy to getpos y     set posz to getpos z     target.setpos x, posx     target.setpos y, posy     target.setpos z, poszEnd

User avatar
Dan Wright
 
Posts: 3308
Joined: Mon Jul 16, 2007 8:40 am


Return to IV - Oblivion