Jump to content
Sign in to follow this  
ADELIJAH

Kick Party

Recommended Posts

I don't think there is a way to kick players from a party using only Lua code (someone correct me if I'm wrong). I've searched and found no useful functions in the source that could do this.
You can't even send a packet to GameServer or GroupServer to kick players, because the two lua functions that can send packets (SendPacket() and SynPacket()) only send them to clients.
If you want to do it in source, though, it's quite easy. Inside Expand.h, add this anywhere:

 

inline int lua_LeaveTeam(lua_State* pLS)
{
T_B 
int nParaNum = lua_gettop(pLS);
bool bSuccess = true;
CCharacter* cha		 = (CCharacter*)lua_touserdata(pLS, 1);
CPlayer*	ply		 = nullptr;
do
{
if(nParaNum != 1 || !cha)
{
		bSuccess = false;
		break;
}
ply = cha->GetPlayer();
if(!ply)
{
		bSuccess = false;
		break;
}
ply->LeaveTeam();


} 
while(0);
if(bSuccess)
{
	lua_pushnumber(pLS, 1);
} else
{
	lua_pushnumber(pLS, 0);
}
return 1;
T_E}


Inside RegisterLuaGameLogic, add this:

REGFN(LeaveTeam);


Now you can use your new C++ function in .lua files.
To kick everyone once a player leaves a specific map, open the ctrl.lua file inside the map folder, search for "function before_leave_[MAP_NAME]" and call your new function there:

function before_leave_garner( role )
	-- First, check if character leaving is in a party.
	local team_size = IsChaInTeam(role)	
	if team_size > 0 then
		-- A party exists, so we must disband it.
		for i=0,3,1 do 
  			local member = GetTeamCha(role, i)
			if member ~= nil then
  				LeaveTeam(member)
  			end
		end
  		LeaveTeam(role)
	end
end







 


"Beware of bugs in the above code; I have only proved it correct, not tried it."

- Donald E. Knuth

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...