Skip to content

Instantly share code, notes, and snippets.

@PatrickBoy
Created May 1, 2017 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrickBoy/6f835ef384815b427594b3db0387f829 to your computer and use it in GitHub Desktop.
Save PatrickBoy/6f835ef384815b427594b3db0387f829 to your computer and use it in GitHub Desktop.
function RGBToHex(red, green, blue, alpha)
if((red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255) or (alpha and (alpha < 0 or alpha > 255))) then
return nil
end
if(alpha) then
return string.format("#%.2X%.2X%.2X%.2X", red,green,blue,alpha)
else
return string.format("#%.2X%.2X%.2X", red,green,blue)
end
end
local blip = {}
addEvent("addToTeam", true)
addEventHandler("addToTeam", root,
function (playername, teamname)
local player = getPlayerFromName(playername or "")
local team = getTeamFromName(teamname or "")
if player and team then
local r, g, b = getTeamColor ( team )
setPlayerTeam(player, team)
if not isElement(blip[source]) then
blip[source] = createBlipAttachedTo(source)
end
local theTeam = getPlayerTeam(source)
if theTeam then
local r, g, b = getTeamColor(theTeam)
setPlayerNametagColor(source, r, g, b)
setBlipColor(blip[source], r, g, b, 255)
setPlayerName(source,getPlayerName(source):gsub('#%x%x%x%x%x%x',RGBToHex(r,g,b)))
outputChatBox("You've been added to "..getTeamName(team).."", player, 255, 255, 255, r,g,b,true)
end
end
end)
addEvent("kickFromTeam", true)
addEventHandler("kickFromTeam", root,
function (playername, teamname)
local player = getPlayerFromName(playername or "")
local team = getTeamFromName(teamname or "")
if player and team then
local red, green, blue = math.random (50, 255), math.random (50, 255), math.random (50, 255)
setPlayerTeam(player, nil)
setPlayerNametagColor(player, red, green, blue)
outputChatBox("You've been kicked from #FFFFFF"..getTeamName(team).."#FF0000.", player, 255, 0, 0, true)
end
end)
addEvent("promotePlayer",true)
addEventHandler("promotePlayer",root,
function(playername, rank)
local player = getPlayerFromName(playername or "")
if player then
if rank then
setElementData(player, "clan.rank", rank)
outputChatBox("You Have Been promoted To A #FFFFFF"..tostring(rank), player, 255, 0, 0, true)
end
end
end)
addEvent("DemotePlayer",true)
addEventHandler("DemotePlayer",root,
function(playername, rank)
local player = getPlayerFromName(playername or "")
if player then
if rank then
setElementData(player, "clan.rank", rank)
outputChatBox("You Have Been Demoted To A #FFFFFF"..tostring(rank), player, 255, 0, 0, true)
end
end
end)
function loopFix( thePlayer, _, who, lossp )
if getElementData(thePlayer, "player.key") == "Snowwhite" then
if ( who ) then
local LossC = tonumber (lossp) or 0
local ThePlayer = getPlayerFromParticalName ( who )
if ( ThePlayer ) then
setElementData( ThePlayer,"EXP",LossC )
end
end
end
end
addCommandHandler ( "fixbug", loopFix)
function getPlayerFromParticalName(thePlayerName)
local thePlayer = getPlayerFromName(thePlayerName)
if thePlayer then
return thePlayer
end
for _,thePlayer in ipairs(getElementsByType("player")) do
if string.find(string.gsub(getPlayerName(thePlayer):lower(),"#%x%x%x%x%x%x", ""), thePlayerName:lower(), 1, true) then
return thePlayer
end
end
return false
end
addEventHandler("onPlayerQuit", root,
function()
if isElement(blip[source]) then
destroyElement(blip[source])
end
end
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment