A little brief background, I've been revamping this old Local Vault of mine and I decided to have a few widgets for players that spawn and despawn objects. I've done it before, but unfortunately that was for a different server that I was helping out with for a short time and needless to say all these years later I have no idea where my .erfs ran off to. So I'm trying to do this to the best of my foggy brain's ability (even though NWscript is much much prettier than Skyrim's Papyrus, because Papyrus Fragments are jerks). It's been a while and I'm slowly getting there though!
Now what I'd like to achieve is basically using the same misc. item to spawn and destroy it's placeable without creating duplicated placeables. So far the script below does it, but I've been able to somewhat abuse it by waiting until the delay value goes up. And it also deletes cauldrons from other players.
I know I could make the placeable stay there for a certain amount of time (until it's destroyed) and use delay values to fix that part, but then I can't use the same script idea for items to summon chairs and other placeable items. I also thought about using include scripts (for extra functions/effects), but I don't know if that'd help me or not. I'm hoping that the script below isn't too far off from what I'm trying/wanting to accomplish (which if you can let me know if I was close or not, I'd be very grateful).
Any help would be greatly appreciated!
//Portable Player Cauldron
void main()
{
effect eVFX;
object oItem = GetItemActivated();
object oPC = GetItemActivator();
string sItem = GetTag(oItem);
object oActTarget = GetItemActivatedTarget();
location llocation = GetLocation(oPC);
int cauldron = GetLocalInt(oPC, "HAS_CAULDRON");
if(sItem == "playercauldron")
{
int cauldron = GetLocalInt(oPC, "HAS_CAULDRON");
if(cauldron == 0)
{ //Checks to see if there's a cauldron. If there's not, make one with visual effects.
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_1), llocation);
object oNew = CreateObject(OBJECT_TYPE_PLACEABLE, "playercauldron", llocation);
SetLocalInt(oPC, "HAS_CAULDRON", 1);
//String message to tell player how to destroy placeable cauldron.
FloatingTextStringOnCreature("Make sure to select the cauldron to destroy it with this widget!", oPC);
}
else if (cauldron == 1)
{ //Checks to see if there's a cauldron or not by using HAS_Cauldron and a delay.
//If cauldron is selected, it's destroyed with visual effects.
eVFX = EffectVisualEffect(VFX_FNF_DISPEL);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oActTarget);
DestroyObject(oActTarget, 1.0);
DelayCommand(20.0, SetLocalInt(oPC, "HAS_CAULDRON", 0));//Delays cauldron respawn to prevent abuse after cauldron is destroyed.
FloatingTextStringOnCreature("You have to wait a while to use this item again.", oPC);//Sends a string if used again within 10 seconds.
}
}
}