Abuyin Sharidi
05.04.2014, 10:16
Hello again! :)
Last time I did a respawn script that should spawn a monster, while no one is on a WP.
The scripts seems to be ok, without any errors, but if I spawn too much monsters, the game crashes. When I use a standard Wld_InsertNpc() Gothic does not crash, even if I spawn monsters on the whole map.
func void B_Wld_InsertNpc (var C_NPC NPC, var string WP){ SpawnRate = Hlp_Random(MaxPercent);
if ((NPC.guild > GIL_SEPERATOR_HUM && NPC.guild < GIL_SEPERATOR_ORC) && NPC.guild != GIL_DRAGON)
{
if !(Npc_IsOnWP (NPC, WP)) && (Npc_GetDistToWp(hero, WP) < MaxRange)//(Npc_GetDistToWP (NPC, WP) > SpawnRange)
{
Wld_InsertNpc (NPC, WP);
if ((NPC.level < hero.level)
|| (NPC.guild == GIL_SCAVENGER) || (NPC.guild == GIL_WOLF) || (NPC.guild == GIL_BLOODFLY)
|| (NPC.guild == GIL_GIANT_RAT) || (NPC.guild == GIL_MOLERAT))
{
if (SpawnRate < BonusSpawn)
{
Wld_InsertNpc (NPC, WP);
Wld_InsertNpc (NPC, WP);
}
else if (SpawnRate > HerdSpawn_02 && SpawnRate < HerdSpawn_01)
{
Wld_InsertNpc (NPC, WP);
Wld_InsertNpc (NPC, WP);
Wld_InsertNpc (NPC, WP);
Wld_InsertNpc (NPC, WP);
Wld_InsertNpc (NPC, WP);
Wld_InsertNpc (NPC, WP);
if (Hlp_GetInstanceID(NPC) == Hlp_GetInstanceID(Wolf)
&& (Hlp_StrCmp(NPC.name, /*Black*/ Wolf.name) && SpawnRate > BlackChances))// && (hero.guild == GIL_NOV || hero.guild == GIL_KDF)
{
Wld_InsertNpc (BlackWolf, WP);
};
NPC.level = NPC.level + HerdBonusExp;
NPC.name = ConcatStrings (NPC.name, HerdMember);
};
Wld_InsertNpc (NPC, WP);
Wld_InsertNpc (NPC, WP);
};
};
}
else
{
if !(Npc_IsOnWP (NPC, WP))//(Npc_GetDistToWP (NPC, WP) > SpawnRange)
{
Wld_InsertNpc (NPC, WP);
};
};
};
and here are all used constants and variables
const int SpawnRange = 500;
const int MaxRange = 200000;
const int HerdSpawn_01 = 95;
const int HerdSpawn_02 = 84;
const int BonusSpawn = 35;
const int BlackChances = 50;
const int MaxPercent = 100;
const int HerdBonusExp = 10;
var int SpawnRate;
BTW! I did make a NpcGetDistToWP from hero to monster NPC, because I thought it would be better, but then I realized that it would be bad idea, because if I'll sleep in Khorinis and I'll teleport to Big Farm, monsters won't spawn at this place, because of the range (the range variable is MaxRange) and I want it to spawn monsters on the whole map while they are not on their WPs. I just want to make this script work, does not matter if there will be lag or not.
I was thinking how to make this script work like for 2 months (not non-stop, obviously), but without any results, so I chose to ask better modders than me. :)
Abuyin Sharidi
05.04.2014, 11:32
Ok, I did change the spoiler to a code.
The function should work as Wld_InsertNpc (NPC, WP);, but with some "bonuses".
I call the function like this in SleepABit.d:
B_Wld_InsertNpc (Wolf, "BIGFARM"); etc. (this one is just an example).
The whole respawn script I use is much bigger, also it spawns almost every monster from startup.d (only for NewWorld.ZEN at the moment).
I'll post this script, it's about 300 lines.
func void Respawn_Bed (){
B_Wld_InsertNpc (Waran , "FP_ROAM_INSEL_01");//
B_Wld_InsertNpc (Waran , "FP_ROAM_INSEL_03");//
B_Wld_InsertNpc (Waran , "FP_ROAM_INSEL_05");//
B_Wld_InsertNpc (Waran , "FP_ROAM_INSEL_07");//
B_Wld_InsertNpc (Waran , "FP_ROAM_INSEL_09");//
B_Wld_InsertNpc (Waran , "FP_ROAM_INSEL_11");//
B_Wld_InsertNpc (Waran , "FP_ROAM_INSEL_13");//
B_Wld_InsertNpc (YBloodfly, "NW_FARM1_PATH_SPAWN_02");
B_Wld_InsertNpc (YWolf, "NW_FARM1_PATH_SPAWN_07");
B_Wld_InsertNpc (YGobbo_Green,"NW_FARM1_PATH_CITY_19_B");
B_Wld_InsertNpc (YBloodfly, "NW_FARM1_PATH_CITY_10_B");
B_Wld_InsertNpc (YWolf, "NW_FARM1_PATH_CITY_05_B");
B_Wld_InsertNpc (YGiant_Bug, "NW_FARM1_CITYWALL_RIGHT_02");
B_Wld_InsertNpc (YGiant_Bug, "NW_FARM1_OUT_13");
B_Wld_InsertNpc (Bloodfly, "NW_FARM1_CITYWALL_02_B");
B_Wld_InsertNpc (Snapper, "NW_FARM1_CITYWALL_05");
B_Wld_InsertNpc (Wolf, "NW_FARM1_CITYWALL_FOREST_03");
B_Wld_InsertNpc (Shadowbeast, "NW_FARM1_CITYWALL_FOREST_04_B");
B_Wld_InsertNpc (Bloodfly, "NW_FARM1_CITYWALL_FOREST_06");
B_Wld_InsertNpc (Gobbo_Black, "NW_FARM1_CITYWALL_FOREST_14");
B_Wld_InsertNpc (Gobbo_Black, "NW_FARM1_CITYWALL_FOREST_15");
B_Wld_InsertNpc (Gobbo_Black, "NW_FARM1_CITYWALL_FOREST_16");
B_Wld_InsertNpc (StonePuma, "NW_BIGFARM_FARM4_FOREST_01");
B_Wld_InsertNpc (Alligator, "NW_LAKE_GREG_TREASURE_01");
B_Wld_InsertNpc (Alligator, "NW_LAKE__WATER_02");
B_Wld_InsertNpc (Alligator, "NW_LAKE__WATER_04");
B_Wld_InsertNpc (Alligator, "NW_LAKE__WATER_06");
B_Wld_InsertNpc (YWolf, "NW_XARDAS_PATH_FARM1_11");
B_Wld_InsertNpc (YGobbo_Green, "NW_XARDAS_GOBBO_01");
B_Wld_InsertNpc (YWolf, "NW_XARDAS_MONSTER_INSERT_01");
B_Wld_InsertNpc (Keiler, "FP_ROAM_XARDAS_SECRET_23");
B_Wld_InsertNpc (Waran, "FP_ROAM_XARDAS_SECRET_08");
B_Wld_InsertNpc (Waran, "FP_ROAM_XARDAS_SECRET_15");
B_Wld_InsertNpc (Waran, "FP_ROAM_XARDAS_SECRET_04");
B_Wld_InsertNpc (Giant_Rat, "FP_ROAM_XARDAS_SECRET_27");
B_Wld_InsertNpc (YGobbo_Green, "NW_XARDAS_TOWER_WATERFALL_CAVE_03");
B_Wld_InsertNpc (YGobbo_Green, "NW_XARDAS_TOWER_WATERFALL_CAVE_ENTRANCE_05");
B_Wld_InsertNpc (YGobbo_Green, "NW_XARDAS_TOWER_WATERFALL_CAVE_ENTRANCE_GOBBO");
B_Wld_InsertNpc (YGiant_Bug, "NW_XARDAS_TOWER_WATERFALL_CAVE_SIDE_02");
B_Wld_InsertNpc (YWolf, "NW_XARDAS_VALLEY_03");
B_Wld_InsertNpc (YWolf, "NW_XARDAS_VALLEY_04");
B_Wld_InsertNpc (YWolf, "NW_XARDAS_VALLEY_06");
B_Wld_InsertNpc (YGiant_Rat, "NW_XARDAS_TOWER_VALLEY_RAT");
B_Wld_InsertNpc (YWolf, "NW_XARDAS_TOWER_VALLEY_WOLF");
B_Wld_InsertNpc (YBloodfly, "NW_XARDAS_TOWER_VALLEY_08");
B_Wld_InsertNpc (YGiant_Rat, "NW_XARDAS_TOWER_SECRET_CAVE_01");
B_Wld_InsertNpc (YGiant_Rat, "NW_XARDAS_TOWER_SECRET_CAVE_01");
B_Wld_InsertNpc (YGiant_Rat, "NW_XARDAS_TOWER_SECRET_CAVE_01");
B_Wld_InsertNpc (YGiant_Rat, "NW_XARDAS_TOWER_SECRET_CAVE_03");
B_Wld_InsertNpc (Scavenger, "NW_PATH_TO_MONASTER_AREA_11");
B_Wld_InsertNpc (Scavenger, "NW_PATH_TO_MONASTER_AREA_11");
B_Wld_InsertNpc (Scavenger, "NW_PATH_TO_MONASTER_MONSTER22");
B_Wld_InsertNpc (Scavenger, "NW_PATH_TO_MONASTER_AREA_01");
B_Wld_InsertNpc (Giant_Rat, "NW_PATH_TO_MONASTER_AREA_02");
B_Wld_InsertNpc (Giant_Rat, "NW_PATH_TO_MONASTER_AREA_10");
B_Wld_InsertNpc (Giant_Rat, "NW_PATH_TO_MONASTER_AREA_10");
B_Wld_InsertNpc (Giant_Bug, "NW_PATH_TO_MONASTER_AREA_08");
B_Wld_InsertNpc (Giant_Rat, "NW_SHRINE_MONSTER");
B_Wld_InsertNpc (Scavenger, "NW_FOREST_CONNECT_MONSTER2");
B_Wld_InsertNpc (Giant_Bug, "NW_BIGFARM_FELDREUBER");
B_Wld_InsertNpc (Giant_Bug, "NW_BIGFARM_FELDREUBER2");
B_Wld_InsertNpc (Giant_Bug, "NW_BIGFARM_FELDREUBER4");
B_Wld_InsertNpc (Giant_Bug, "FP_ROAM_MONSTERMILL_11");
B_Wld_InsertNpc (Giant_Bug, "FP_ROAM_MONSTERMILL_13");
B_Wld_InsertNpc (Giant_Bug, "FP_ROAM_MONSTERMILL_04");
B_Wld_InsertNpc (Giant_Bug, "FP_ROAM_MONSTERMILL_03");
B_Wld_InsertNpc (Lurker, "NW_BIGMILL_FIELD_MONSTER_03");
B_Wld_InsertNpc (Giant_Bug, "NW_BIGMILL_FIELD_MONSTER_02");
B_Wld_InsertNpc (Giant_Bug, "NW_BIGFARM_FIELD_MONSTER_01");
B_Wld_InsertNpc (Scavenger, "NW_TAVERNE_TROLLAREA_MONSTER_01_01");
B_Wld_InsertNpc (Wolf, "NW_TAVERNE_TROLLAREA_MONSTER_04_01");
B_Wld_InsertNpc (Gobbo_Green, "NW_TAVERNE_TROLLAREA_MONSTER_05_01");
B_Wld_InsertNpc (Wolf, "NW_BIGFARM_LAKE_MONSTER_01_01");
B_Wld_InsertNpc (Lurker, "NW_BIGFARM_LAKE_MONSTER_02_01");
B_Wld_InsertNpc (Bloodfly, "NW_BIGFARM_LAKE_MONSTER_02_01");
B_Wld_InsertNpc (Wolf, "NW_BIGFARM_LAKE_MONSTER_03_01");
B_Wld_InsertNpc (Lurker, "NW_LAKE_GREG_TREASURE_01");
B_Wld_InsertNpc (Warg, "NW_FARM4_WOOD_MONSTER_01");
B_Wld_InsertNpc (Bloodfly, "NW_FARM4_WOOD_MONSTER_02");
B_Wld_InsertNpc (Bloodfly, "NW_FARM4_WOOD_MONSTER_02");
B_Wld_InsertNpc (Wolf, "NW_FARM4_WOOD_MONSTER_03");
B_Wld_InsertNpc (Wolf, "NW_FARM4_WOOD_MONSTER_05");
B_Wld_InsertNpc (Bloodfly, "NW_FARM4_WOOD_MONSTER_06");
B_Wld_InsertNpc (Bloodfly, "NW_FARM4_WOOD_MONSTER_07");
B_Wld_InsertNpc (Shadowbeast, "NW_FARM4_WOOD_MONSTER_08");
B_Wld_InsertNpc (Bloodfly, "NW_FARM4_WOOD_MONSTER_10");
B_Wld_InsertNpc (Minecrawler, "NW_CASTLEMINE_13");
B_Wld_InsertNpc (MinecrawlerWarrior, "NW_CASTLEMINE_10");
B_Wld_InsertNpc (MinecrawlerWarrior, "NW_CASTLEMINE_06");
B_Wld_InsertNpc (Gobbo_Black, "FP_ROAM_NW_BIGFARMFORESTCAVE_01");
B_Wld_InsertNpc (Gobbo_Warrior, "FP_ROAM_NW_BIGFARMFORESTCAVE_02");
B_Wld_InsertNpc (Gobbo_Black, "FP_ROAM_NW_BIGFARMFORESTCAVE_03");
B_Wld_InsertNpc (Gobbo_Black, "FP_ROAM_NW_BIGFARMFORESTCAVE_04");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_BIGFARM_LAKE_CAVE_02");
B_Wld_InsertNpc (Gobbo_Black, "FP_ROAM_BIGFARM_LAKE_CAVE_07");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_BIGFARM_LAKE_CAVE_08");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_BIGFARM_LAKE_CAVE_10");
B_Wld_InsertNpc (Gobbo_Black, "FP_ROAM_BIGFARM_LAKE_CAVE_11");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_BIGFARM_LAKE_CAVE_13");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_NW_BIGFARMFORESTCAVE_05");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_NW_BIGFARMFORESTCAVE_07");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_NW_BIGFARMFORESTCAVE_08");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_NW_BIGFARMFORESTCAVE_10");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_BIGFARM_LAKE_CAVE_01");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_BIGFARM_LAKE_CAVE_03");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_BIGFARM_LAKE_CAVE_04");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_BIGFARM_LAKE_CAVE_05");
B_Wld_InsertNpc (Gobbo_Green, "FP_ROAM_BIGFARM_LAKE_CAVE_06");
B_Wld_InsertNpc (Bloodfly, "NW_BIGFARM_LAKE_MONSTER_BLOODFLY");
B_Wld_InsertNpc (Giant_Bug, "NW_TAVERNE_TROLLAREA_MONSTER_03_01M1");
B_Wld_InsertNpc (Wolf, "NW_SAGITTA_MOREMONSTER_01");
B_Wld_InsertNpc (Giant_Bug, "NW_SAGITTA_MOREMONSTER_03");
B_Wld_InsertNpc (Bloodfly, "NW_FARM4_WOOD_NEARPEASANT7");
B_Wld_InsertNpc (Bloodfly, "NW_FARM4_WOOD_NEARPEASANT2_14");
B_Wld_InsertNpc (Bloodfly, "NW_FARM4_WOOD_NEARPEASANT2_10");
B_Wld_InsertNpc (Wolf, "NW_FARM4_WOOD_NEARPEASANT2_8");
B_Wld_InsertNpc (Scavenger, "NW_FARM4_WOOD_NEARPEASANT2_7");
B_Wld_InsertNpc (Giant_Bug, "NW_FARM4_WOOD_NEARPEASANT2_12");
B_Wld_InsertNpc (Gobbo_skeleton, "NW_FARM4_WOOD_MONSTER_MORE_02");
B_Wld_InsertNpc (Giant_Bug, "NW_FARM4_WOOD_MONSTER_MORE_01");
B_Wld_InsertNpc (Giant_Bug, "NW_FARM4_WOOD_MONSTER_N_3");
B_Wld_InsertNpc (Giant_Bug, "NW_FARM4_WOOD_MONSTER_N_2");
B_Wld_InsertNpc (Giant_Bug, "NW_BIGFARM_FOREST_02");
B_Wld_InsertNpc (Keiler, "NW_BIGFARM_FOREST_03_NAVIGATION");
B_Wld_InsertNpc (Keiler, "NW_FARM4_WOOD_NAVIGATION_09");
B_Wld_InsertNpc (Wolf, "NW_CASTLEMINE_TROLL_05");
B_Wld_InsertNpc (Giant_Bug, "NW_BIGFARM_ALLEE_08_N");
B_Wld_InsertNpc (Giant_Bug, "NW_BIGFARM_ALLEE_08_N_2");
B_Wld_InsertNpc (Scavenger, "NW_BIGMILL_05");
B_Wld_InsertNpc (Scavenger, "NW_FARM3_BIGWOOD_02");
B_Wld_InsertNpc (Keiler, "NW_FARM3_BIGWOOD_03");
B_Wld_InsertNpc (Lurker, "NW_FARM3_PATH_11_SMALLRIVER_02");
B_Wld_InsertNpc (Lurker, "NW_FARM3_PATH_11_SMALLRIVER_02");
B_Wld_InsertNpc (Lurker, "NW_FARM3_PATH_11_SMALLRIVER_04");
B_Wld_InsertNpc (Scavenger, "NW_FARM3_PATH_11_SMALLRIVER_08");
B_Wld_InsertNpc (Scavenger, "NW_FARM3_PATH_11_SMALLRIVER_10");
B_Wld_InsertNpc (Scavenger, "NW_FARM3_PATH_11_SMALLRIVER_10");
B_Wld_InsertNpc (Lurker, "NW_FARM3_PATH_11_SMALLRIVER_17");
B_Wld_InsertNpc (Lurker, "NW_FARM3_PATH_11_SMALLRIVER_17");
B_Wld_InsertNpc (Lurker, "NW_FARM3_PATH_11_SMALLRIVER_20");
B_Wld_InsertNpc (Bloodfly, "NW_FARM3_PATH_11_SMALLRIVER_24");
B_Wld_InsertNpc (Bloodfly, "NW_FARM3_PATH_11_SMALLRIVER_24");
B_Wld_InsertNpc (Lurker, "NW_FARM3_PATH_11_SMALLRIVERMID_03");
B_Wld_InsertNpc (Lurker, "NW_FARM3_PATH_11_SMALLRIVERMID_02");
B_Wld_InsertNpc (Keiler, "NW_FARM3_PATH_12_MONSTER_01");
B_Wld_InsertNpc (Keiler, "NW_FARM3_PATH_12_MONSTER_03");
B_Wld_InsertNpc (Lurker, "NW_FARM3_MOUNTAINLAKE_03");
B_Wld_InsertNpc (Lurker, "NW_FARM3_MOUNTAINLAKE_MONSTER_01");
B_Wld_InsertNpc (Keiler, "NW_BIGFARM_LAKE_03_MOVEMENT");
B_Wld_InsertNpc (Giant_Bug, "NW_BIGFARM_LAKE_03_MOVEMENT3");
B_Wld_InsertNpc (YWolf,"NW_PASS_06");
B_Wld_InsertNpc (YWolf,"NW_PASS_11");
B_Wld_InsertNpc (YWolf,"NW_PASS_SECRET_15");
B_Wld_InsertNpc (YWolf,"NW_PASS_SECRET_16");
B_Wld_InsertNpc (YWolf,"NW_PASS_SECRET_17");
B_Wld_InsertNpc (Giant_Rat,"NW_PASS_SECRET_05");
B_Wld_InsertNpc (Giant_Rat,"NW_PASS_SECRET_06");
B_Wld_InsertNpc (Giant_Rat,"NW_PASS_SECRET_07");
B_Wld_InsertNpc (Giant_Rat,"NW_PASS_SECRET_08");
B_Wld_InsertNpc (Gobbo_Green,"NW_PASS_GRAT_04");
B_Wld_InsertNpc (Gobbo_Green,"NW_PASS_GRAT_05");
B_Wld_InsertNpc (Gobbo_Green,"NW_PASS_GRAT_06");
B_Wld_InsertNpc (Giant_Rat, "FP_ROAM_MEDIUMFOREST_KAP2_12");
B_Wld_InsertNpc (Giant_Rat, "FP_ROAM_MEDIUMFOREST_KAP2_10");
B_Wld_InsertNpc (Scavenger, "FP_ROAM_MEDIUMFOREST_KAP2_28");
B_Wld_InsertNpc (Scavenger, "FP_ROAM_MEDIUMFOREST_KAP2_29");
B_Wld_InsertNpc (Scavenger, "FP_ROAM_MEDIUMFOREST_KAP2_17");
B_Wld_InsertNpc (Scavenger, "FP_ROAM_MEDIUMFOREST_KAP2_13");
B_Wld_InsertNpc (Wolf, "FP_ROAM_MEDIUMFOREST_KAP2_36");
B_Wld_InsertNpc (Wolf, "FP_ROAM_MEDIUMFOREST_KAP2_34");
B_Wld_InsertNpc (Warg, "FP_ROAM_MEDIUMFOREST_KAP3_08");
B_Wld_InsertNpc (Warg, "FP_ROAM_MEDIUMFOREST_KAP3_09");
B_Wld_InsertNpc (Warg, "FP_ROAM_MEDIUMFOREST_KAP3_11");
B_Wld_InsertNpc (Giant_Bug, "FP_ROAM_MEDIUMFOREST_KAP3_15");
B_Wld_InsertNpc (Wolf, "FP_ROAM_MEDIUMFOREST_KAP3_17");
B_Wld_InsertNpc (Keiler, "FP_ROAM_MEDIUMFOREST_KAP3_21");
B_Wld_InsertNpc (Warg, "FP_ROAM_MEDIUMFOREST_KAP3_23");
B_Wld_InsertNpc (Warg, "FP_ROAM_MEDIUMFOREST_KAP3_28");
B_Wld_InsertNpc (Warg, "FP_ROAM_MEDIUMFOREST_KAP3_29");
B_Wld_InsertNpc (Shadowbeast, "FP_ROAM_MEDIUMFOREST_KAP3_20");
B_Wld_InsertNpc (Giant_Rat, "FP_ROAM_MEDIUMFOREST_KAP3_27");
B_Wld_InsertNpc (Giant_Rat, "FP_ROAM_MEDIUMFOREST_KAP3_26");
B_Wld_InsertNpc (Bloodfly, "NW_CITY_TO_LIGHTHOUSE_03");
B_Wld_InsertNpc (Waran, "FP_ROAM_SHIPWRECK_04");
B_Wld_InsertNpc (Waran, "FP_ROAM_SHIPWRECK_01");
B_Wld_InsertNpc (Wolf, "NW_CITY_TO_FOREST_05");
B_Wld_InsertNpc (Wolf, "NW_CITY_TO_FOREST_07");
B_Wld_InsertNpc (Giant_Rat, "NW_CITY_TO_FOREST_11");
B_Wld_InsertNpc (Giant_Rat, "NW_CITY_TO_FOREST_12");
B_Wld_InsertNpc (Gobbo_Green, "NW_CITY_TO_FOREST_15"); //FPs fehlen
B_Wld_InsertNpc (Wolf, "FP_ROAM_CITY_TO_FOREST_47");
B_Wld_InsertNpc (Giant_Rat, "FP_ROAM_CITY_TO_FOREST_11");
B_Wld_InsertNpc (Giant_Rat, "FP_ROAM_CITY_TO_FOREST_10");
B_Wld_InsertNpc (Giant_Rat, "FP_ROAM_CITYFOREST_KAP3_22");
B_Wld_InsertNpc (Giant_Rat, "FP_ROAM_CITYFOREST_KAP3_20");
B_Wld_InsertNpc (Giant_Rat, "FP_ROAM_CITYFOREST_KAP3_21");
B_Wld_InsertNpc (Giant_Bug, "FP_ROAM_CITYFOREST_KAP3_23");
B_Wld_InsertNpc (Giant_Bug, "FP_ROAM_CITYFOREST_KAP3_27");
B_Wld_InsertNpc (Giant_Bug, "FP_ROAM_CITYFOREST_KAP3_28");
B_Wld_InsertNpc (Giant_Bug, "FP_ROAM_CITYFOREST_KAP3_29");
B_Wld_InsertNpc (Giant_Bug, "FP_ROAM_CITYFOREST_KAP3_30");
B_Wld_InsertNpc (Giant_Bug, "FP_ROAM_CITYFOREST_KAP3_38");
B_Wld_InsertNpc (Waran, "FP_ROAM_CITY_TO_FOREST_32");
B_Wld_InsertNpc (Waran, "FP_ROAM_CITY_TO_FOREST_29");
B_Wld_InsertNpc (Waran, "FP_ROAM_CITY_TO_FOREST_31");
B_Wld_InsertNpc (Molerat, "FP_ROAM_CITY_TO_FOREST_42");
B_Wld_InsertNpc (Shadowbeast, "FP_ROAM_CITYFOREST_KAP3_04");
B_Wld_InsertNpc (Gobbo_Black, "FP_ROAM_CITYFOREST_KAP3_07");
B_Wld_InsertNpc (Gobbo_Black, "FP_ROAM_CITYFOREST_KAP3_06");
B_Wld_InsertNpc (Gobbo_Black, "FP_ROAM_CITYFOREST_KAP3_08");
B_Wld_InsertNpc (Warg, "FP_ROAM_CITYFOREST_KAP3_09");
B_Wld_InsertNpc (Warg, "FP_ROAM_CITYFOREST_KAP3_10");
B_Wld_InsertNpc (Warg, "FP_ROAM_CITYFOREST_KAP3_11");
B_Wld_InsertNpc (Warg, "FP_ROAM_CITYFOREST_KAP3_12");
B_Wld_InsertNpc (Warg, "FP_ROAM_CITYFOREST_KAP3_14");
B_Wld_InsertNpc (Warg, "FP_ROAM_CITYFOREST_KAP3_15");
B_Wld_InsertNpc (Warg, "FP_ROAM_CITYFOREST_KAP3_17");
B_Wld_InsertNpc (Giant_Rat ,"NW_FOREST_VINOSKELLEREI_01");
B_Wld_InsertNpc (Giant_Rat, "NW_CITY_SMFOREST_05");
B_Wld_InsertNpc (Giant_Rat, "NW_CITY_SMFOREST_09");
B_Wld_InsertNpc (Giant_Rat, "NW_CITY_SMFOREST_03");
B_Wld_InsertNpc (Shadowbeast, "NW_FOREST_PATH_35_06");
B_Wld_InsertNpc (Wolf, "NW_CITY_TO_FOREST_04_09");
B_Wld_InsertNpc (Molerat, "NW_TAVERN_TO_FOREST_05_05");
B_Wld_InsertNpc (Molerat, "NW_TAVERN_TO_FOREST_05_06");
B_Wld_InsertNpc (Giant_Rat, "NW_CITYFOREST_CAVE_04");
B_Wld_InsertNpc (Molerat, "NW_CITYFOREST_CAVE_06");
B_Wld_InsertNpc (Shadowbeast, "NW_CITYFOREST_CAVE_A06");
B_Wld_InsertNpc (Giant_Rat, "NW_FARM1_CITYWALL_RIGHT_04");
B_Wld_InsertNpc (Scavenger, "NW_FOREST_PATH_38_MONSTER");
B_Wld_InsertNpc (Keiler, "NW_CITY_TO_LIGHTHOUSE_13_MONSTER");
B_Wld_InsertNpc (Wolf, "NW_FOREST_PATH_35_01");
B_Wld_InsertNpc (Warg, "NW_FOREST_PATH_31_MONSTER");
B_Wld_InsertNpc (Molerat, "NW_FOREST_PATH_21_MONSTER");
B_Wld_InsertNpc (Giant_Bug, "NW_FARM2_TO_TAVERN_09_MONSTER");
B_Wld_InsertNpc (Giant_Bug, "NW_FARM2_TO_TAVERN_09_MONSTER2");
B_Wld_InsertNpc (Giant_Bug, "NW_FARM2_TO_TAVERN_09_MONSTER3");
B_Wld_InsertNpc (Molerat, "NW_FARM2_TO_TAVERN_09_MONSTER4");
B_Wld_InsertNpc (Bloodfly, "NW_FARM2_TO_TAVERN_09_MONSTER5");
B_Wld_InsertNpc (Wolf, "NW_CITY_TO_FOREST_04");
B_Wld_InsertNpc (Wolf, "NW_FOREST_CAVE1_01");
B_Wld_InsertNpc (Giant_Bug, "NW_FOREST_PATH_75_2_MONSTER");
B_Wld_InsertNpc (Keiler, "NW_FOREST_PATH_79");
B_Wld_InsertNpc (Keiler, "NW_FOREST_PATH_80_1");
B_Wld_InsertNpc (Waran, "NW_FOREST_PATH_82");
B_Wld_InsertNpc (Waran, "NW_FOREST_PATH_82_M");
B_Wld_InsertNpc (Wolf, "NW_FOREST_PATH_66_M");
B_Wld_InsertNpc (Giant_Bug, "NW_FOREST_PATH_57");
B_Wld_InsertNpc (Bloodfly, "NW_FOREST_PATH_35_01_MONSTER");
B_Wld_InsertNpc (Giant_Bug, "NW_FOREST_PATH_80_1_MOVEMENT8_M");
B_Wld_InsertNpc (Giant_Bug, "NW_FOREST_PATH_80_1_MOVEMENTF");
B_Wld_InsertNpc (Giant_Bug, "NW_FOREST_PATH_31_NAVIGATION3");
B_Wld_InsertNpc (Giant_Bug, "NW_FOREST_PATH_31_NAVIGATION10");
B_Wld_InsertNpc (Giant_Rat, "NW_FOREST_PATH_31_NAVIGATION11");
B_Wld_InsertNpc (Snapper, "NW_FOREST_PATH_80_1_MOVEMENT6");
B_Wld_InsertNpc (Snapper, "NW_FOREST_PATH_80_1_MOVEMENT15");
B_Wld_InsertNpc (Snapper, "NW_FOREST_PATH_80_1_MOVEMENT8_M5");
B_Wld_InsertNpc (Warg, "NW_FOREST_PATH_31_NAVIGATION16");
B_Wld_InsertNpc (Snapper, "NW_FOREST_PATH_80_1_MOVEMENT8_M3");
B_Wld_InsertNpc (Warg, "NW_FOREST_PATH_04_16_MONSTER");
B_Wld_InsertNpc (Warg, "NW_FOREST_PATH_04_16_MONSTER2");
B_Wld_InsertNpc (Giant_Bug, "NW_FOREST_PATH_04_13");
B_Wld_InsertNpc (Giant_Bug, "NW_FOREST_PATH_04_3");
B_Wld_InsertNpc (Giant_Bug, "NW_FOREST_PATH_04_4");
B_Wld_InsertNpc (Warg, "NW_FOREST_PATH_72_MONSTER");
B_Wld_InsertNpc (Bloodfly, "NW_FOREST_PATH_62_06");
B_Wld_InsertNpc (Molerat, "NW_FOREST_PATH_56_MONSTER");
B_Wld_InsertNpc (Bloodfly, "NW_FOREST_PATH_27_03");
B_Wld_InsertNpc (Warg, "NW_FOREST_PATH_27_02");
B_Wld_InsertNpc (Scavenger, "NW_CITY_TO_LIGHTHOUSE_13_MONSTER7");
B_Wld_InsertNpc (Scavenger, "NW_CITY_TO_LIGHTHOUSE_13_MONSTER7");
B_Wld_InsertNpc (Bloodfly, "NW_CITY_TO_LIGHTHOUSE_13_MONSTER8");
B_Wld_InsertNpc (Bloodfly, "NW_CITY_TO_LIGHTHOUSE_13_MONSTER8");
B_Wld_InsertNpc (Keiler, "NW_FOREST_PATH_35_MONSTER");
B_Wld_InsertNpc (Warg, "NW_FOREST_PATH_72_MONSTER23");
B_Wld_InsertNpc (Molerat, "NW_FOREST_PATH_76");
B_Wld_InsertNpc (Warg, "NW_FOREST_PATH_66_MONSTER");
B_Wld_InsertNpc (Giant_Bug, "NW_FOREST_PATH_04_5");
B_Wld_InsertNpc (Keiler, "NW_FOREST_PATH_04_14_MONSTER");
B_Wld_InsertNpc (Molerat, "NW_CITY_SMFOREST_03_M");
B_Wld_InsertNpc (Molerat, "NW_FOREST_PATH_25_01_M");
B_Wld_InsertNpc (Bloodfly, "FP_ROAM_TROLLAREA_SEA_01");
B_Wld_InsertNpc (Bloodfly, "FP_ROAM_TROLLAREA_SEA_02");
B_Wld_InsertNpc (Bloodfly, "FP_ROAM_TROLLAREA_SEA_03");
B_Wld_InsertNpc (Bloodfly, "FP_ROAM_TROLLAREA_SEA_04");
B_Wld_InsertNpc (Bloodfly, "FP_ROAM_NW_TROLLAREA_RUINS_22");
B_Wld_InsertNpc (Bloodfly, "FP_ROAM_NW_TROLLAREA_RUINS_24");
B_Wld_InsertNpc (Waran, "FP_ROAM_NW_TROLLAREA_RUINS_28");
B_Wld_InsertNpc (Waran, "FP_ROAM_NW_TROLLAREA_RUINS_29");
B_Wld_InsertNpc (Waran, "FP_ROAM_NW_TROLLAREA_RUINS_30");
B_Wld_InsertNpc (Shadowbeast, "FP_ROAM_NW_TROLLAREA_RUINS_10");
B_Wld_InsertNpc (Bloodfly, "NW_TROLLAREA_PATH_38_MONSTER");
B_Wld_InsertNpc (Scavenger, "NW_TROLLAREA_PLANE_04");
B_Wld_InsertNpc (Scavenger, "NW_TROLLAREA_RUINS_17");
B_Wld_InsertNpc (Scavenger, "NW_TROLLAREA_PATH_71_MONSTER2");
B_Wld_InsertNpc (Scavenger, "NW_TROLLAREA_PATH_15_MONSTER");
B_Wld_InsertNpc (Scavenger, "NW_TROLLAREA_RITUALPATH_04");
};
The one bug in it is the Game Crash, which should not happen.
Milky-Way
05.04.2014, 19:13
How much detail do you need in terms of understanding what it does?
The general idea is the following:
In the ZS_Dead, it is checked whether an npc should be respawned (with the function MeetsRespawnCondition). If so, it is added to a array-like object by use of the function AddToRespawnArray. More precisely, the array contains handles with witch you can access objects of type RespawnObject. An object of type RespawnObject has the properties defined in its class:
class RespawnObject {
var int inst; //Die Monsterinstanz
var string wp; //Der Wegpunkt
var int respawnDay; // Der Tag des Respawns, wobei der erste Tag den Wert 0 hat... Genau wie Gothic.
};
So, the function AddToRespawnArray creates an object of that class and fills its fields with appropriate values:
func void AddToRespawnArray(var c_npc slf) {
var int hndl; hndl = new(RespawnObject@);
var RespawnObject myRespawnObject; myRespawnObject = get(hndl);
myRespawnObject.inst = Hlp_GetInstanceID(slf);
myRespawnObject.wp = slf.spawnPoint;
myRespawnObject.respawnDay = Wld_GetDay() + (slf.level/10)+2; // Irgendeine Formel
};
Now there exists a RespawnObject for each npc that should be respawned. But how is it actually respawned? In the example, it happens when sleeping. In the PC_Sleep.d (which contains the functions called when a bed is used), he calls
CheckRespawns();
the function does this:
func void CheckRespawns() {
ForEachHndl(RespawnObject@, _CheckRespawns);/* Dieser Part bedarf vielleicht einer kurzen Erklärung:
Mit ForEachHndl() führe ich eine angegebene Funktion (2. Parameter) für alle Objekte/Handles
einer angegebenen Ursprungsinstanz (1. Parameter) aus. So kann ich ganz einfach
alle RespawnObjects überprüfen :) */
};
What does it mean? (it is explained in the comment in German)
ForEachHndl will call the function that is given as the second argument once for each handle of objects of the first argument. So, since we only create handles to RespawnObject from the ZS_Dead, the function _CheckRespawns is called once for each of the RespawnObject that we created.
So what does the _CheckRespawns function do?
func void _CheckRespawns(var int hndl) { // In diesem Parameter steht, für welches Handle die Funktion gerade ausgeführt wird
var RespawnObject myRespawnObject; myRespawnObject = get(hndl);
//Jetzt haben wir unser Objekt!
if (myRespawnObject.respawnDay <= Wld_GetDay()) { // Der Tag des Respawns ist gekommen! \o/
Wld_InsertNpc(myRespawnObject.inst, myRespawnObject.wp); // Daher fügen wir einfach den NPC an seinem WP ein :)
// Allerdings müssen wir nun unser Objekt auch entfernen, sonst würde es ja beim nächsten Mal wieder eingefügt!
// Ich werde daher einfach mal die Funktion RemoveRespawnObject() aufrufen - wie die aussehen muss, schauen wir später.
RemoveRespawnObject(hndl);
return rContinue; // Wir wollen schließlich weiterhin alle Handles durchlaufen - bis wir alle haben
};
First, it gets the object of the handle. Then, it checks whether the field respawnDay of that object indicates that the npc should be respawned by today at the latest. If so, the monster is respawned. Lastly, since the npc is now respawned, we can delete the handle in the function RemoveRespawnObject.
The return rContinue means that the game will go on calling the _CheckRespawn for the next handle. (if our goal was to find a specific handle, we could stop once we found it, but here all RespawnObjects might potentially need to be respawned)
That is basically it. Only a technical thing remains:
const string RespawnObject_Struct = "auto|3";
tells the game what objects of the class RespawnObject look like. The internal scripts will use that information to associate the saved information with the correct fields of the object. Here, "auto|3" means that there are 3 fields of auto, where auto means that it is a simple value (Func, float, int, string) - if you introduce more fields (e.g. the class gets an additional integer value to indicate how many of these monsters should be respawned) you need to change the 3 e.g. into a 4. If you have "more complicated" fields, such as a pointer to another object, you need to mention it explicitly as the "auto" does not know how to handle it. E.g.
const string RespawnObject_Struct = "auto|3 RespawnObject*";
I explained all relevant code blocks except for this one:
instance RespawnObject@(RespawnObject);
RespawnObject@ is now an instance of the RespawnObject class. The instance can then be used to create actual objects. Here, that happens with the handle and new in the function AddToRespawnArray.
Similar things happen in the normal scripts as well. You have a class C_NPC that has several fields, e.g. name, id,... which you can actually see in the Classes.d - you will see the similarity to our own class RespawnObject. In the script of a Wolf for example, it uses a similar line to create an instance from that class: INSTANCE Wolf (Mst_Default_Wolf), where Mst_Default_Wolf is a prototype, a kind of template that gives default values to the fields of the class C_NPC. When you then look at the startup, this instance wolf is used to create the actual wolves (Wld_InsertNpc (Wolf, wp)).
After inserting such an NPC, you can of course change the values like name, level,... e.g. when the player has enough experience, the value of the field level is increased by one.
A problem that one faces is that one instance (Wolf) is used to create many objects (Wld_InsertNpc (Wolf,wp) is used more than once), so there is not a one-to-one correspondence. After bringing a wolf into the world, you do not have access to that particular wolf anymore, but only to the instance from which it was created. That is exactly what the handles are for, you save access to the actual individual object.
If you need more information (e.g. how handles work internally or on implementation) or if you have questions about my explanation (which I did not read again to make sure it's coherent), please let us know :)
Powered by vBulletin® Version 4.2.2 Copyright ©2025 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.