Wandering Monsters
Zephirius
Member Posts: 419
I've been toying with a random monster spawner -
I'm looking for suggestions on how to improve it... I'm sure You guys will let me have it... lol
I know there's plenty of systems out there, but I kind of wanted to try doing it myself, I might be in over my head... not sure.
For OnHeartbeat
Code so far...
I'm looking for suggestions on how to improve it... I'm sure You guys will let me have it... lol
I know there's plenty of systems out there, but I kind of wanted to try doing it myself, I might be in over my head... not sure.
For OnHeartbeat
Code so far...
void SpawnWanderingMonster(string sResRef, location lLoc) { CreateObject(OBJECT_TYPE_CREATURE, "", lLoc); } void main() { object oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC); if (!GetIsPC(oPC)) return; location oWay1 = GetLocation(GetWaypointByTag("WP_01")); location oWay2 = GetLocation(GetWaypointByTag("WP_02")); location oWay3 = GetLocation(GetWaypointByTag("WP_03")); location oWay4 = GetLocation(GetWaypointByTag("WP_04")); location oWay5 = GetLocation(GetWaypointByTag("WP_05")); location oWay6 = GetLocation(GetWaypointByTag("WP_06")); location oWay7 = GetLocation(GetWaypointByTag("WP_07")); if (d100() > 90 ) { switch (Random(7)) { SpawnWanderingMonster("", oWay1); // Lots more monster stuff here } } }
0
Comments
If it's a predatory beast it may be attracted to corpses and spawn near them assuming nothing else is too close.
I see the code picks a random waypoint and creates the monster, but doesn't tell it to go anywhere yet. I suppose things like random wandering, spawning in with stealth, moving/stalking to a PC's location, etc might be handled within the creature's events and not this system.
I've spent so long in my own module I can't tell you what is original or default behavior and what isn't, but the OnSpawn for creatures I think has a flag for spawning in stealth. If the creature should always do that, then that flag/variable would be set within the creature's properties.
The spawn system could set a variable (e.g. STALKER) which the creature's heartbeat script could contain the behavior for. Like moving to their location to try for a sneak attack.
Hope it's helpful.
EDIT:
Nvm... NeverwinterWights covered this already with the Random(7) explanation.
Don't forget that Random(7) returns values from 0 - 6 and not 1 - 7.
Good catch. Fixed it.