I am using the code below witch I am going to change the while to an if and so on this works fine the problem i am having is I need a way to remove the mob from the zone via the m_mobList because if I keep adding to the zone they will stay there and keep respawning and I fear this may lag the server after a ton of them are spawned I want to be able to remove them to keep the server rescources down and all that stuff.
Code: Select all
uint16 mobtozone(uint32 mobid, float mob_x, float mob_y, float mob_z, uint8 mob_r, uint8 ZoneID)
	{
		uint32 mob_returnID = 0;
		//CZone* PZone = new CZone(ZoneID, conquest::GetCurrentRegion(ZoneID));
		///CZone* PZone2 = zoneutils::GetZone(ZoneID);
		//ShowDebug(CL_GREEN"PZone: %u \n" CL_RESET, PZone);
		ShowDebug(CL_GREEN"PZone2: %u \n" CL_RESET, zoneutils::GetZone(ZoneID));
		const int8* fmtQuery = "SELECT name, mobid, pos_rot, pos_x, pos_y, pos_z, \
					respawntime, spawntype, dropid, HP, MP, minLevel, maxLevel, \
					modelid, mJob, sJob, cmbSkill, cmbDelay, behavior, links, mobType, \
					systemid, mobsize, speed, \
					STR, DEX, VIT, AGI, `INT`, MND, CHR, EVA, DEF, \
					Slash, Pierce, H2H, Impact, \
					Fire, Ice, Wind, Earth, Lightning, Water, Light, Dark, Element, \
					mob_pools.familyid, name_prefix, unknown \
					FROM mob_groups, mob_pools, mob_spawn_points, mob_family_system \
					WHERE mob_groups.poolid = mob_pools.poolid \
					AND mob_groups.groupid = mob_spawn_points.groupid \
					AND mob_family_system.familyid = mob_pools.familyid \
					AND mob_groups.zoneid = %u;";
					
		int32 ret = Sql_Query(SqlHandle, fmtQuery, ZoneID);
		if( ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0) 
		{	
			while(Sql_NextRow(SqlHandle) == SQL_SUCCESS) 
			{
				CloneID = CloneID + 1; 
				//CloneID = rand()%65534; 
				uint32 getmobid = Sql_GetUIntData(SqlHandle,1);
			if (getmobid == mobid){
				CMobEntity* PMob = new CMobEntity;
				uint32 newmobid = (mobid / 2) + CloneID;
				PMob->name.insert(0,Sql_GetData(SqlHandle,0));
				//PMob->id = CloneID;
				PMob->id = (uint32)Sql_GetUIntData(SqlHandle,1);
				//PMob->targid = (uint16)PMob->id & 0x0FFF;
				PMob->targid = CloneID & 0x0FFF;
				
				ShowDebug(CL_GREEN"NewMobID: %u \n" CL_RESET, PMob->id);
				PMob->m_SpawnPoint.rotation = mob_r;
				PMob->m_SpawnPoint.x = mob_x;
				PMob->m_SpawnPoint.y = mob_y;
				PMob->m_SpawnPoint.z = mob_z;
				PMob->m_RespawnTime = (uint32)25 * 1000;
				//PMob->m_RespawnTime = Sql_GetUIntData(SqlHandle,6) * 1000;
				//PMob->m_SpawnType   = (SPAWNTYPE)Sql_GetUIntData(SqlHandle,7);
				PMob->m_SpawnType   = (SPAWNTYPE)SPAWNTYPE_NORMAL;
				PMob->m_DropID		= Sql_GetUIntData(SqlHandle,8);
				PMob->HPmodifier = (uint32)Sql_GetIntData(SqlHandle,9);
				PMob->MPmodifier = (uint32)Sql_GetIntData(SqlHandle,10);
				PMob->m_minLevel = (uint8)Sql_GetIntData(SqlHandle,11);
				PMob->m_maxLevel = (uint8)Sql_GetIntData(SqlHandle,12);
				memcpy(&PMob->look,Sql_GetData(SqlHandle,13),22);
				PMob->SetMJob(Sql_GetIntData(SqlHandle,14));
				PMob->SetSJob(Sql_GetIntData(SqlHandle,15));
				PMob->m_Weapons[SLOT_MAIN]->setSkillType(Sql_GetIntData(SqlHandle,16));
				PMob->m_Weapons[SLOT_MAIN]->setDelay((Sql_GetIntData(SqlHandle,17) * 1000)/60);
				//PMob->m_Behaviour  = (uint16)Sql_GetIntData(SqlHandle,18);
				PMob->m_Behaviour  = (BEHAVIOUR)BEHAVIOUR_AGGRO_TRUESIGHT;
                PMob->m_Link       = (uint8)Sql_GetIntData(SqlHandle,19);
				PMob->m_Type       = (MOBTYPE)MOBTYPE_FISHED;
				PMob->m_EcoSystem  = (ECOSYSTEM)Sql_GetIntData(SqlHandle,21);
				PMob->m_ModelSize += (uint8)Sql_GetIntData(SqlHandle,22);
				
				PMob->speed    = (uint8)Sql_GetIntData(SqlHandle,23);
				PMob->speedsub = (uint8)Sql_GetIntData(SqlHandle,23);
				PMob->setModifier(MOD_SLASHRES, (uint16)(Sql_GetFloatData(SqlHandle,33) * 1000));
				PMob->setModifier(MOD_PIERCERES,(uint16)(Sql_GetFloatData(SqlHandle,34) * 1000));
				PMob->setModifier(MOD_HTHRES,   (uint16)(Sql_GetFloatData(SqlHandle,35) * 1000));
				PMob->setModifier(MOD_IMPACTRES,(uint16)(Sql_GetFloatData(SqlHandle,36) * 1000));
                PMob->setModifier(MOD_FIREDEF,    (int16)((Sql_GetFloatData(SqlHandle, 37) - 1) * -1000)); // These are stored as floating percentages 
                PMob->setModifier(MOD_ICEDEF,     (int16)((Sql_GetFloatData(SqlHandle, 38) - 1) * -1000)); // and need to be adjusted into modifier units.
                PMob->setModifier(MOD_WINDDEF,    (int16)((Sql_GetFloatData(SqlHandle, 39) - 1) * -1000)); // Higher DEF = lower damage.  
                PMob->setModifier(MOD_EARTHDEF,   (int16)((Sql_GetFloatData(SqlHandle, 40) - 1) * -1000)); // Negatives signify increased damage.
                PMob->setModifier(MOD_THUNDERDEF, (int16)((Sql_GetFloatData(SqlHandle, 41) - 1) * -1000)); // Positives signify reduced damage.
                PMob->setModifier(MOD_WATERDEF,   (int16)((Sql_GetFloatData(SqlHandle, 42) - 1) * -1000)); // Ex: 125% damage would be 1.25, 50% damage would be 0.50
                PMob->setModifier(MOD_LIGHTDEF,   (int16)((Sql_GetFloatData(SqlHandle, 43) - 1) * -1000)); // (1.25 - 1) * -1000 = -250 DEF
                PMob->setModifier(MOD_DARKDEF,    (int16)((Sql_GetFloatData(SqlHandle, 44) - 1) * -1000)); // (0.50 - 1) * -1000 = 500 DEF
                PMob->setModifier(MOD_FIRERES,    (int16)((Sql_GetFloatData(SqlHandle, 37) - 1) * -100)); // These are stored as floating percentages 
                PMob->setModifier(MOD_ICERES,     (int16)((Sql_GetFloatData(SqlHandle, 38) - 1) * -100)); // and need to be adjusted into modifier units.
                PMob->setModifier(MOD_WINDRES,    (int16)((Sql_GetFloatData(SqlHandle, 39) - 1) * -100)); // Higher RES = lower damage.  
                PMob->setModifier(MOD_EARTHRES,   (int16)((Sql_GetFloatData(SqlHandle, 40) - 1) * -100)); // Negatives signify lower resist chance.
                PMob->setModifier(MOD_THUNDERRES, (int16)((Sql_GetFloatData(SqlHandle, 41) - 1) * -100)); // Positives signify increased resist chance.
                PMob->setModifier(MOD_WATERRES,   (int16)((Sql_GetFloatData(SqlHandle, 42) - 1) * -100)); 
                PMob->setModifier(MOD_LIGHTRES,   (int16)((Sql_GetFloatData(SqlHandle, 43) - 1) * -100)); 
                PMob->setModifier(MOD_DARKRES,    (int16)((Sql_GetFloatData(SqlHandle, 44) - 1) * -100)); 
				PMob->m_Element = (uint8)Sql_GetIntData(SqlHandle,45);
				PMob->m_Family = (uint16)Sql_GetIntData(SqlHandle,46); 
				PMob->m_name_prefix = (uint8)Sql_GetIntData(SqlHandle,47); 
				PMob->m_unknown = (uint32)Sql_GetIntData(SqlHandle,48); 
				PMob->PBattleAI = new CAIMobDummy(PMob);
				//PMob->PBattleAI->SetCurrentAction(PMob->m_SpawnType == SPAWNTYPE_NORMAL ? ACTION_SPAWN : ACTION_NONE,CloneID);
				PMob->PBattleAI->SetCurrentAction(ACTION_SPAWN,CloneID);
			
				// Killer Effect
                switch (PMob->m_EcoSystem)
	            {
		            case SYSTEM_AMORPH:   PMob->addModifier(MOD_BIRD_KILLER,     5); break;
		            case SYSTEM_AQUAN:    PMob->addModifier(MOD_AMORPH_KILLER,   5); break;
		            case SYSTEM_ARCANA:   PMob->addModifier(MOD_UNDEAD_KILLER,   5); break;
		            case SYSTEM_BEAST:    PMob->addModifier(MOD_LIZARD_KILLER,   5); break;
		            case SYSTEM_BIRD:     PMob->addModifier(MOD_AQUAN_KILLER,    5); break;
		            case SYSTEM_DEMON:    PMob->addModifier(MOD_DRAGON_KILLER,   5); break;
		            case SYSTEM_DRAGON:   PMob->addModifier(MOD_DEMON_KILLER,    5); break;
		            case SYSTEM_LIZARD:   PMob->addModifier(MOD_VERMIN_KILLER,   5); break;
                    case SYSTEM_LUMINION: PMob->addModifier(MOD_LUMORIAN_KILLER, 5); break;
                    case SYSTEM_LUMORIAN: PMob->addModifier(MOD_LUMINION_KILLER, 5); break;
		            case SYSTEM_PLANTOID: PMob->addModifier(MOD_BEAST_KILLER,    5); break;
		            case SYSTEM_UNDEAD:   PMob->addModifier(MOD_ARCANA_KILLER,   5); break;
		            case SYSTEM_VERMIN:   PMob->addModifier(MOD_PLANTOID_KILLER, 5); break;
	            }
				//DA and TA
				if(PMob->GetMJob()==JOB_WAR && PMob->m_minLevel >= 25 || PMob->GetSJob()==JOB_WAR && PMob->m_minLevel >= 50){
					PMob->addModifier(MOD_DOUBLE_ATTACK,15);
				}
				if(PMob->GetMJob()==JOB_THF && PMob->m_minLevel >= 55){
					PMob->addModifier(MOD_TRIPLE_ATTACK,7);
				}
				
				zoneutils::GetZone(ZoneID)->InsertMOB(PMob);
				PMob->SetDespawnTimer(20);
				//PMob->PBattleAI->SetCurrentAction(ACTION_ATTACK,CloneID);
				PMob->PBattleAI->CheckCurrentAction(gettick());
				mob_returnID = PMob->id;
				luautils::OnMobInitialise(PMob);
                //return CloneID;
			}
				
			}
		}
				//zoneutils::GetZone(ZoneID)->ZoneServer(-1);
				//g_PZoneList[ZoneID] = zoneutils::GetZone(ZoneID);
				//if (zoneutils::GetZone(ZoneID)->GetIP() != 0)
				//{
				//	luautils::OnZoneInitialise(zoneutils::GetZone(ZoneID)->GetID());
				//}
		return CloneID;
	}
I know the code is a bit messy I will make it look pretty when I figure out how to delete the mob