Respawning chests script doubt
fot1
Member Posts: 74
So, I got back to some scripting, and I have this problem that I just can't understand. My objective is just to respawn chests. I have been successfully respawning chests on my module up to now, but one chest has a different tag from its resref, and I have been using the tag to derivate the resref. So instead, I simply used the GetResRef function. But for some reason, this breaks all respawns, even the ones that have been working.
This is the code of the function I used to recreate an object. using sResRefWorks, it works, but if I try to switch to sResRef it does not work. By work, I mean one chest is respawn, but instead of the current resref, it uses the tag of the chest to decide de resref.
void recreateObject(object oCont, string sTag, int iType, location lLoc)
{
DestroyObject(oCont, 0.0);
string sResRef = GetStringLeft(GetResRef(oCont),16);
string sResRefWorks = GetStringLowerCase(GetStringLeft(sTag, 16));
CreateObject(iType, sResRefWorks, lLoc);
}
I did some debugging with talking chests, and it seems that the strings are equal. So two questions: 1) Why my GetResRef is not working? And 2) is there a way to respawn the chests based on the resref instead of the tag?
This is the code of the function I used to recreate an object. using sResRefWorks, it works, but if I try to switch to sResRef it does not work. By work, I mean one chest is respawn, but instead of the current resref, it uses the tag of the chest to decide de resref.
void recreateObject(object oCont, string sTag, int iType, location lLoc)
{
DestroyObject(oCont, 0.0);
string sResRef = GetStringLeft(GetResRef(oCont),16);
string sResRefWorks = GetStringLowerCase(GetStringLeft(sTag, 16));
CreateObject(iType, sResRefWorks, lLoc);
}
I did some debugging with talking chests, and it seems that the strings are equal. So two questions: 1) Why my GetResRef is not working? And 2) is there a way to respawn the chests based on the resref instead of the tag?
0
Comments
string sResref = GetResRef(oCont); CreateObject(iType, sResRef, lLoc);
Check using the view menu option "preview" what the reference value is, and check that the object in your area has the same resref and isn't a copy, a copy will have an altered reference like "001" on the end. Also check that the scripts used in the object in your area are the same scripts used in your chest in the palette.
If it's the same then it will work.
This function `recreateObject` is set up on the object opening, with a delay. If the object is destroyed in the meantime, the GetResRef fails, while the sTag still works because it is being passed as a parameter. To fix it, I passed the resRef as parameter itself.
Thanks for the help, and sorry for the noise.
When the server would load, it would pick a time for the first spawn in order to prevent players from charging all known chest locations immediately upon server startup. Once all chests were spawned, a new time would be selected for all the remaining chests to be destroyed and new locations chosen to spawn chests.
There are lots and lots of ways you can make self spawning and random treasure and monster scripts. I personally think non-designed or machine generated dungeons can be interesting because not even the builder will know what happens where.