Jump to content

Help Create Panel Clan


Amenic

Recommended Posts

This code should give you a idea how this can be done, but the last time i tried this code was in July, there could be unknown bugs xD

Gang = {}
Gang.__index = Gang
Gang.instances = {}


function Gang:create(name, r, g, b)
    local self = setmetatable({}, Gang)
	
    self.id = Gang.getFreeId()
	self.name = name
	
    self.team = Team(name, r, g, b)
    self.team:setData("id", self.id)

    table.insert(Gang.instances, self)
    return self
end

function Gang:getName()
	return self.name
end

function Gang:dispose()
	for index,instance in pairs(Gang.instances) do
		if (instance == self) then
			table.remove(Gang.instances, index)
			self.team:destroy()	
		end
	end
end


function Gang.getFromMember(member) 
    for index, gang in pairs(Gang.instances) do
        if(gang.team == member.team) then
            return gang
        end
    end 
    return false
end

function Gang.getFromName(name) 
    for index, gang in pairs(Gang.instances) do
        if(gang.team.name == name) then
            return gang
        end
    end  
    return false
end
	
function Gang.getFromID(id)
	for index,gang in pairs(Gang.instances) do
		if (gang.id == id) then
			return gang
		end
	end
	return false
end

function Gang.getFreeId()
	for i=1, 100 do
		if not (Gang.getFromID(i)) then
			return i
		end
	end
end



addCommandHandler("gang",
function (player, command, ...) 
    local parameters = {...}
    local act = parameters[1]
	
	if(act == "create") then
	    local name = table.concat ({parameters[2], parameters[3], parameters[4], parameters[5]}, " ")
	    local gang = Gang:create(name, math.random(0,255),math.random(0,255),math.random(0,255))
	    player:setTeam(gang.team)
	    player:outputChat("Gang successfully created!", 0, 255, 0)
	
	elseif(act == "delete") then
	    local gang = Gang.getFromMember(player)
		if(gang) then
		    gang:dispose()
		    player:outputChat("Gang successfully deleted!", 0, 255, 0)
		end
	elseif (act == "invite") then
		local target = parameters[2]
		if (target) and (target ~= "") then
			if (player.team) then
				local gang = Gang.getFromName(player.team.name)
				if (getPlayerFromName(target)) then
					getPlayerFromName(target):setData("Invite", gang.name, false)

					player:outputChat("Invite sent to "..getPlayerFromName(target), 255, 255, 0)
				end
			else
				player:outputChat("A player with this name is not online", 255, 0, 0)
			end
		else
			player:outputChat("You have no gang bro", 255, 0, 0)
		end

    elseif(act == "accept") then
    	if not (player:getData("Invite") == false) then
    		local gangName = player:getData("Invite")
    		local gang = Gang.getFromName(gangName)
    		if (gang) then
    			player:outputChat("Welcome in "..gangName, 0, 255, 0)
    			player:setTeam(gang.team)

    			player:removeData("Invite")
    		end
    	else
    		player:outputChat("You were not invited to join any gang", 255, 0, 0)
    	end
    end
end)

addEventHandler("onResourceStart", resourceRoot,
function ()
	addCommandHandler("gangs", 
	function (player, command)
		player:outputChat("Gangs:", 255, 255, 0)
		for index,instance in pairs (Gang.instances) do
			player:outputChat("ID: "..instance.id.." Name: "..instance.name.."", 255, 255, 0)
		end
	end)
end)

 

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...