Gamemode Creation Help

I don’t like starting a new thread for everything I need to ask so I’m going to make this thread and just post a question from time to time and hope that someone will be able to answer unlike my last thread about helping fix my rank system, which is now fixed due to days of working and reworking X_X.

I’m wondering if it is at all possible to give each player their own table to put things in.

For example, I’m trying to make it so I can give ownership over a player to another player so that that the owned player cannot damage the owner and vice versa, but they can still damage other players. I thought I could somehow accomplish this by making each player that has becomes a Master have their own table and when you kill another player they are entered in that Masters table and made a Zombie Slave to that Master.

Is there any way to accomplish what I want to do?

I don’t think you would be giving ‘ownership’ but you can prevent damage from certain players using the PlayerShouldTakeDamage hook. Assign the ‘Master’ of every player when they turn zombies (e.g. ply.Master = [whoever]) then check if the attacker is the master of the victim. If this needs to be the other way around as well (Masters can’t take damage from zombies) you will also need to check if the attacker’s master is equal to the victim. If you can have more masters, use tables.

And yeah, you can assign tables and any data to a player just by doing ply.something = whatever data. You can then get that with attacker.something, victim.something, anything really as long as it is the same player entity. This goes for all entities btw. (Remember this is not networked though)

Oohh, that might work. And yes there can be more then one Master, the amount of Masters depends on the amount of players in the server, kind of like TTT.

Now I just have to learn how it works :suicide:

I meant more Masters per zombie. Can any zombie only have 1 master at a time? Store that master as a variable on the zombie player. Just like you can do “variable = anything”, you can also do “player.variable = anything” storing it on the player so you can get it back by referring to “player.variable” later. “player” can be anything as long as it refers to the same player (like the arguments in many hooks).

This works because the player entity is essentially like a table, and you can store values in a table by doing “table.key = value” just like “table[key] = value”.

Late reply due to being gone for 2 weeks but is this how you would set something like this up?

BecomeServant is called when a player is turned into a zombie by a Masters right click.
[lua]yourmaster = {}
local zombies = {}
function MastersWishes( ply )
if ply:IsMaster() then
for k, v in pairs( player.GetAll() ) do

		if v:IsMaster() then
			table.insert( yourmaster, v )
		end
		
	end
	
	ply:SetModel( "models/player/zombie_fast.mdl" )
	
	ply:Give( "weapon_zm_master" )
	
	ply:GodEnable()
end

end

function BecomeServant( ply, ruler )
for k, v in pairs( player.GetAll() ) do

	if v:IsZombie() then
		table.insert( zombies, v )
	end
	
end

ply:SetRank( RANK_ZOMBIE )

ply:SetModel( "models/player/zombie_classic.mdl" )


ply:Give( "weapon_zm_zompistol" )

--Setting a zombie's Master
ply.Master = yourmaster[ruler]

end[/lua]

Sadly I don’t know how to test this