Fun Command GotoMob

Post Reply
WiiStream

Fun Command GotoMob

Post by WiiStream » Sun Apr 14, 2013 2:01 am

Here's a fun command to have. What is dose is spawns the mob in the zone location it should be in, and teleports you to the mob.

Code: Select all

inline int32 CLuaBaseEntity::GotoMob(lua_State* L)
{
	CCharEntity* PChar = (CCharEntity*)m_PBaseEntity;
	
	if(m_PBaseEntity == NULL)
	{
		
		ShowNotice(CL_RED"TRACER:COMMAND: spawnmob Error\n" CL_RESET);
		return false;
	}
	if(m_PBaseEntity->objtype != TYPE_PC)
	{
		
		ShowNotice(CL_RED"TRACER:COMMAND: spawnmob Error1\n" CL_RESET);
		return false;
	}
	if(lua_isnil(L,-1) || !lua_isnumber(L,-1))
	{
		PChar->pushPacket(new CChatMessagePacket(PChar, MESSAGE_TELL, "Command Error1"));
		PChar->pushPacket(new CChatMessagePacket(PChar, MESSAGE_TELL, "Command Example: .spawnmob 1"));
		ShowNotice(CL_RED"TRACER:COMMAND: spawnmob Error2\n" CL_RESET);
		return false;
	 }
	
						
	
		uint32 mobid = (uint32)lua_tointeger(L,1);
		uint32 groupid =0;
		float pos_x =0;
		float pos_y =0;
		float pos_z =0;
		uint32 pos_rot =0;
		uint32 zoneid = 0;
        CMobEntity* PMob = (CMobEntity*)zoneutils::GetEntity(mobid, TYPE_MOB);
        if (PMob != NULL)
        {
            
			//BE FUN TO ADD A APPEAR TO MOB AT LOCATION ALSO
                  const int8* Query = "SELECT groupid,pos_x,pos_y,pos_z,pos_rot FROM mob_spawn_points WHERE mobid = '%u';";
	             int32 ret = Sql_Query(SqlHandle,Query,mobid);

	             if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS)
	               {

		              PMob->PBattleAI->SetCurrentAction(ACTION_SPAWN);
					 
					   ShowNotice(CL_RED"TRACER:COMMAND: Player %s Is Appearing To Mob ID %u\n" CL_RESET ,PChar->GetName(),mobid);
					 groupid = Sql_GetUIntData(SqlHandle,0); 
					 ShowNotice(CL_RED"TRACER:COMMAND: GET GROUP ID %u\n" CL_RESET ,groupid);
					 pos_x = Sql_GetFloatData(SqlHandle,1); 
					 ShowNotice(CL_RED"TRACER:COMMAND: GET POS_X ID %f\n" CL_RESET ,pos_x);
					 pos_y = Sql_GetFloatData(SqlHandle,2); 
					 ShowNotice(CL_RED"TRACER:COMMAND: GET POS_Y ID %f\n" CL_RESET ,pos_y);
					 pos_z = Sql_GetFloatData(SqlHandle,3); 
					 ShowNotice(CL_RED"TRACER:COMMAND: GET POS_Z ID %f\n" CL_RESET ,pos_z);
					 pos_rot = Sql_GetUIntData(SqlHandle,4); 
					 ShowNotice(CL_RED"TRACER:COMMAND: GET POS_ROT ID %u\n" CL_RESET ,pos_rot);
					 PChar->status = STATUS_DISAPPEAR;
					PChar->loc.p.x=pos_x;
						PChar->loc.p.y=pos_y;
						PChar->loc.p.z=pos_z;
						PChar->loc.p.rotation=pos_rot;
						

			PChar->loc.boundary = 0;
					 const int8* Query = "SELECT zoneid FROM mob_groups WHERE groupid = '%u';";
	             int32 ret = Sql_Query(SqlHandle,Query,groupid);
				 if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS)
	               {

					   zoneid = Sql_GetUIntData(SqlHandle,0); 
					 ShowNotice(CL_RED"TRACER:COMMAND: GET ZONE ID %u\n" CL_RESET ,zoneid);
					   
			 PChar->loc.destination=zoneid ;
		    PChar->clearPacketList();
			            PChar->pushPacket(new CServerIPPacket(PChar,2));
			PChar->pushPacket(new CCharUpdatePacket(PChar));
			PChar->loc.zone->PushPacket(PChar, CHAR_INRANGE, new CEntityUpdatePacket(PChar, ENTITY_SPAWN));
			
					   return false;
				 }
				 
    lua_pushnil(L);
				 return false;
				 }
              

               
                
             
			
    lua_pushnil(L);
    return false;
		}
		
        
  
    lua_pushnil(L);
    return false;
}

WiiStream

Re: Fun Command Kill_Target

Post by WiiStream » Wed Apr 17, 2013 12:19 pm

Code: Select all

inline int32 CLuaBaseEntity::Kill_Target(lua_State *L)
{
	CCharEntity* PChar = (CCharEntity*)m_PBaseEntity;
	if(m_PBaseEntity == NULL)
	{
		//PChar->pushPacket(new CChatMessagePacket(PChar, MESSAGE_TELL, "setPos Error"));
		ShowNotice(CL_RED"TRACER:COMMAND: killtarget Error\n" CL_RESET);
		return false;
	}

	if(m_PBaseEntity->objtype != TYPE_PC)
	{
		//PChar->pushPacket(new CChatMessagePacket(PChar, MESSAGE_TELL, "getRace Error1"));
		ShowNotice(CL_RED"TRACER:COMMAND: killtarget Error1\n" CL_RESET);
		return false;
	}

	if(PChar->loc.zone->GetEntity(PChar->m_TargID, TYPE_PC))
		{

		CCharEntity* PCharTarget = (CCharEntity*)PChar->loc.zone->GetEntity(PChar->m_TargID, TYPE_PC);
		PCharTarget->PBattleAI->SetCurrentAction(ACTION_FALL);
		PCharTarget->godmode=0;
		PCharTarget->nameflags.flags = 0;
		PCharTarget->health.hp=0;
		charutils::UpdateHealth(PCharTarget);
		PCharTarget->animation = ANIMATION_DEATH;
		
		
		PCharTarget->isDead();
		PCharTarget->pushPacket(new CCharUpdatePacket(PCharTarget));
		
		return false;
	}
	if(PChar->loc.zone->GetEntity(PChar->m_TargID, TYPE_MOB))
		{
			CMobEntity * PMob = (CMobEntity*)PChar->loc.zone->GetEntity(PChar->m_TargID, TYPE_MOB);
			
			PMob->health.hp=0;
			PMob->PBattleAI->SetCurrentAction(ACTION_FALL);
		
		PMob->animation = ANIMATION_DEATH;
		
		PMob->isDead();
		
		
		PMob->loc.zone->PushPacket(PMob, CHAR_INRANGE, new CEntityUpdatePacket(PMob,ENTITY_UPDATE));
		PChar->pushPacket(new CCharUpdatePacket(PChar));
		
		
	
	
		return false;
	}
	
	PChar->pushPacket(new CChatMessagePacket(PChar, MESSAGE_TELL, "kill Error1"));
	PChar->pushPacket(new CChatMessagePacket(PChar, MESSAGE_TELL, "Command Example .kill"));
	PChar->pushPacket(new CChatMessagePacket(PChar, MESSAGE_TELL, "Note: Mob Or Player Target Must Be Selected"));
	ShowNotice(CL_RED"TRACER:COMMAND: killtarget\n" CL_RESET);
	return false;
}

Post Reply