• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Mass kick (Kick all players on screen)

slaw

Software Developer
Joined
Aug 27, 2007
Messages
3,784
Solutions
133
Reaction score
1,275
Location
Germany
GitHub
slawkens
This command will kick all players which you see on your screen. Personally it help me to kick boters from trainers.

You can also use parameters, to specify max range.
Example:
/masskick 3,3,0 - kick all players which are max 3 squares from you
/masskick 1,1,7 - kick all players which are max 3 squares from you, buy on all floors are included

This command work only in TFS 0.3

talkactions.xml
Code:
<talkaction access="5" log="yes" words="/masskick" script="masskick.lua"/>

masskick.lua
Code:
local config = {
	maxRangeX = 5,
	maxRangeY = 7,
}

function onSay(cid, words, param)
	local playerPos = getCreaturePosition(cid)

	local minPos = {x = playerPos.x - config.maxRangeX, y = playerPos.y - config.maxRangeY, z = playerPos.z}
	local maxPos = {x = playerPos.x + config.maxRangeX, y = playerPos.y + config.maxRangeY, z = playerPos.z}

	if(string.find(param, ",")) then
		local params = string.explode(param, ",")
		if(isNumber(params[1]) == TRUE and isNumber(params[2]) == TRUE and isNumber(params[3]) == TRUE) then
			minPos.x = playerPos.x - params[1]
			minPos.y = playerPos.y - params[2]
			minPos.z = playerPos.z - params[3]

			maxPos.x = playerPos.x + params[1]
			maxPos.y = playerPos.y + params[2]
			maxPos.z = playerPos.z + params[3]
		else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid param specified.")
			return TRUE
		end
	end

	local kicked = 0
	local players = getPlayersOnline()
	for i, pid in ipairs(players) do
		local tmpPos = getCreaturePosition(pid)
		if(isInArea(tmpPos, minPos, maxPos) == TRUE) then
			if(cid ~= pid) then
				doRemoveCreature(pid)
				kicked = kicked + 1
			end
		end
	end

	if(kicked > 0) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Succesfully kicked " .. kicked .. " players.")
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "There are no players to kick.")
	end
	return TRUE
end
 
Last edited:
Haven't tested it, but seems like a great code, keep it up mate !
 
Nice, but... Not efficient O.o

You kick players on screen. 7 * 5 = 35 (35 squares in your screen).
You loop through all players on server, most oftenly there are more players than 35. So having 200 players online will make unnecessary lags.

Just loop through the screen tiles, not players :)
 
And you think that getThingfromPos, or any other function which there could be used, we'll be more efficient? It also make much loops.. 35 squares, but what if command will be used with param - /masskick 30,30,7 (+- 7 floors, 30 tiles)? ;> It isn't really much.. MC Check command make more loops than this, and believe my, this simple command won't make much lag event if there is 500 players online ;)
 
Last edited:
Okay xd didn't see you used floors, because I only read title (on screen, not anything else O.o) and quick look at script
 
Code:
function onSay(cid, words, param)
	if(param == "") then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
		return TRUE
	end

	local t = string.explode(param, ",")
	if(not t[2]) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enough params.")
		return TRUE
	end

	local multifloor = FALSE
	if(t[3]) then
		multifloor = getBooleanFromString(t[3])
	end

	local tmp = 0
	local players = getSpectators(getCreaturePosition(cid), t[1], t[2], multifloor)
	for i, pid in ipairs(players) do
		if(pid ~= cid and getPlayerAccess(pid) < getPlayerAccess(cid)) then
			doRemoveCreature(pid)
			tmp = tmp + 1
		end
	end

	if(tmp > 0) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Kicked " .. kicked .. " players.")
	else
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Could not kick any player.")
	end

	return TRUE
end
200% optimized, usage: /masskick 3,3,(yes/true/1) - kick all players within 3 squares including up and down floor.
 
Last edited:
Back
Top