Jump to content

Recommended Posts

Hi, 

 

i tried to overwrite the functions TheNet:Kick(userid) and TheNet:Ban(userid) with the purpose to drop the stuff of the player who was kicked or banned:

 



local function returnPlayer(userid)
for k, v in pairs(GLOBAL.TheNet:GetClientTable()) do
if v.userid == userid then
return v
end
end
end

local kickTheNetOld = GLOBAL.TheNet.Kick or function(...) return true end
function GLOBAL.TheNet:Kick(userid,...)
local player = returnPlayer(userid)
if player and player.components.inventory then
player.components.inventory:DropEverything(false,false)
end
return kickTheNetOld(self,userid,...)
end

local banTheNetOld = GLOBAL.TheNet.Ban or function(...) return true end
function GLOBAL.TheNet:Ban(userid,...)
local player = returnPlayer(userid)
if player and player.components.inventory then
player.components.inventory:DropEverything(false,false)
end
return banTheNetOld(self,userid,...)
end


 

But it doesn't work because TheNet is "a UserData Value", what does that mean exactly?

 

Edited by ForenSmurf

I assume you read: http://forums.kleientertainment.com/topic/53756-only-drop-inventory-if-playerdays-is-below-a-certain-thresholdbanned/

 

Userdata means it's on the C side of the C/Lua relationship.

There are two things you can do.

 

1) If you are going to use the console to enter TheNet:Ban(userid), then you may as well make a custom command.

function GLOBAL.myban(userid)   local player = returnPlayer(userid)   player.components.inventory:DropEverything(false,false)   GLOBAL.TheNet:Ban(userid)end

Then you ban people via console with your custom command.

 

2) You want the little buttons in the table that appears pressing TAB to do the same as the command

 

Then copy the rest of the code that was with the returnPlayer function.

 

 

Regardless, I'm going to look if it's possible to do something to modify userdata.

UPDATE:

Use the following

local function returnPlayer(userid)	for k, v in pairs(GLOBAL.TheNet:GetClientTable()) do		if v.userid == userid then			return v		end	endendlocal TableNet = GLOBAL.getmetatable(GLOBAL.TheNet).__indexlocal old = TableNet.KickTableNet.Kick = function(self, userid)	local player = returnPlayer(userid) 	if player and player.components.inventory then 		player.components.inventory:DropEverything(false, false) 	end	return old(self, userid)end

Hi, i tried that but it didn't work, it seems that the returned user object from client table isn't the same user object as in AllPlayers[index] and it doesn't have any components.

 

I'm just using GLOBAL.AllPlayers instead of GLOBAL.TheNet:GetClientTable() now and it works fine :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...