Seems like you have a good grip on what to do, but here's how my mad scientist brain would do it...
This was mostly scratched off in notepad, so there may be some minor compile errors:
//for onmoduleload
void SpawnRandomNPC(){
string sNPCResRef = "yournpcresref";
string sWPTag = "YourWPTag";
//count the waypoints
int iWPCount = 0;
while(GetIsObjectValid(GetObjectByTag(sWPTag, iWPCount))){
iWPCount++;
}
//Grab one at random
int iRandomWP = Random(iWPCount);
object oRandomWP = GetObjectByTag(sWPTag, iRandomWP);
//Spawn the NPC there
object oSpawnedNPC = CreateObject(OBJECT_TYPE_CREATURE,sNPCResRef,GetLocation(oRandomWP));
//Cache WP Tag/Count/Spawn Point
Object oCacheOn = GetModule();
SetLocalString(oCacheOn,"randmob_wp_tag",sWPTag);
SetLocalInt(oCacheOn,"randmob_wp_count",iWPCount);
SetLocalInt(oCacheOn,"randmob_spawned_at",iRandomWP);
}
//for ondeath
void RespawnSelf(string sResRef, location lSpawnPoint){
object oSpawnedNPC = CreateObject(OBJECT_TYPE_CREATURE,sResRef,lSpawnPoint);
}
void main(){
float fRespawnDelay = 30.0;
if (!GetIsPC(GetLastKiller())) return;
object oCachedOn = GetModule();
string sWPTag = GetLocalString(oCachedOn,"randmob_wp_tag");
int iWPCount = GetLocalInt(oCachedOn,"randmob_wp_count");
int iLastWP = GetLocalInt(oCachedOn,""randmob_spawned_at");
//pick a new one at random, but not the current one
int iRandomWP = iLastWP;
while(iRandomWP == iLastWP){
iRandomWP = Random(iWPCount);
}
object oRandomWP = GetObjectByTag(sWPTag, iRandomWP);
//Spawn the NPC there in X.0 seconds
DelayCommand(fRespawnDelay,RespawnSelf(GetResRef(OBJECT_SELF),GetLocation(oRandomWP));
//update cache
SetLocalInt(oCachedOn,"randmob_spawned_at",iRandomWP);
}
Modifié par Ne0nx3r0, 20 octobre 2010 - 05:48 .