ULX Physgun Colors

I am trying to set physgun colors via ulx ranks but the code ain’t working. A little help would be good.


-- sv_rankphysguncolours.lua
local ranks = {}
local function AddExtraRank(id,col)
	ranks[id] = {}
	ranks[id].Color = col
end
	
AddExtraRank("superadmin",Color(255,0,0))
AddExtraRank("admin",Color(0,0,255))
AddExtraRank("user",Color(0,128,255))
AddExtraRank("Owner",Color(255,0,0))
AddExtraRank("Head Administrator",Color(255,0,0))
AddExtraRank("Senior Administrator",Color(167,47,255))
AddExtraRank("Administrator",Color(0,170,0))
AddExtraRank("Moderator",Color(0,0,255))
AddExtraRank("Trial-Moderator",Color(0,148,255)
AddExtraRank("Dedicated Member",Color(239,207,0)) -- don't remove these three. just add more as necessary.

local function GetRankPhysgunColor(ply)
	if ucl then -- I took this code from a join colour thing I made in another thread a while back.
		if ranks[ply:GetUserGroup()] then
			return ranks[ply:GetUserGroup()].Color
		else
			return Color(255,255,255)
		end
	else
		if ply:IsSuperAdmin() then
			return ranks["superadmin"].Color
		elseif ply:IsAdmin() then
			return ranks["admin"].Color
		else
			return ranks["user"].Color
                else
                        return ranks["Head Administrator"].Color
                else 
                        return ranks["Senior Administrator"].Color
                else
                        return ranks["Administrator"].Color
                else
                        return ranks["Moderator"].Color
                else
                        return ranks["Trial Moderator"].Color
                else
                        return ranks["Dedicated Member"].Color
		end
	end
end

hook.Add( "PlayerSpawn", "AdminPhysgunCol", function( ply )
	local color = GetRankPhysgunColor(ply)
	timer.Create("setphysguncolour",0.1,1,function()
	ply:SetWeaponColor(Vector(color.r / 255, color.g / 255, color.b / 255))
	end)
end)

hook.Add( "PlayerInitialSpawn", "AdminPhysgunCol2", function( ply )
	local color = GetRankPhysgunColor(ply)
	timer.Create("setinitialphysguncolour",0.1,1,function()
	ply:SetWeaponColor(Vector(color.r / 255, color.g / 255, color.b / 255))
	end)
end)

shit code dudee. :fap:


(User was banned for this post ("Why reply?" - Kiwi))

instead of talking shit why dont u try helping out? hes obviously a beginner



		if ply:IsSuperAdmin() then
			return ranks["superadmin"].Color
		elseif ply:IsAdmin() then
			return ranks["admin"].Color
		else
			return ranks["user"].Color
                else
                        return ranks["Head Administrator"].Color
                else 
                        return ranks["Senior Administrator"].Color
                else
                        return ranks["Administrator"].Color
                else
                        return ranks["Moderator"].Color
                else
                        return ranks["Trial Moderator"].Color
                else
                        return ranks["Dedicated Member"].Color
		end


This is piece of code doesn’t really make sense, mind explaining what its supposed to do? and what is “ucl” defined as?

IsSuperAdmin() and IsAdmin() will not work with ulx, you should probably use



ply:IsUserGroup("superadmin")


IsAdmin() and IsSuperAdmin() DO work on ulx, but they also include anything that inherits from them.

as for the original question, you’re just doing if else blocks super duper wrong. Instead of doing an if block, just do



return ranks[ply:GetUserGroup()].Color


because shit

[editline]11th September 2017[/editline]

Using this is shit : http://wiki.secondlife.com/wiki/Category:LSL_Color



local ranks = {
	["superadmin"] = Vector(0.30, 1.80, 2.10),
	["admin"] = Vector(0.75, 0.75, 0.75),
}

local function GetColorSpawn(ply)
	local wclr = ranks[ply:GetUserGroup()] or Vector(1, 1, 1)
	timer.Simple(1, function()
		ply:SetWeaponColor(wclr)
	end)
end

hook.Add("PlayerSpawn", "AdminPhysgunCol", GetColorSpawn)
hook.Add("PlayerInitialSpawn", "AdminPhysgunCol2", GetColorSpawn)


not tested.

[editline]11th September 2017[/editline]