• Converting NewAdmin Playernames
    7 replies, posted
Ok some of you may have seen the playernames in NewAdmin the cool ones with with little rank image and typing indicator well im trying to convert them to ASSMod i did this before but i cant remember how here is my code (Overv's code) [CODE] local PLUGIN = {} PLUGIN.Name = "Playernames" PLUGIN.Author = "Virus78" PLUGIN.Date = "6th August 2009" PLUGIN.Filename = PLUGIN_FILENAME PLUGIN.ClientSide = true PLUGIN.ServerSide = true PLUGIN.APIVersion = 2 PLUGIN.Gamemodes = {} resource.AddFile( "materials/gui/silkicons/comment.vmt" ) resource.AddFile( "materials/gui/silkicons/comment.vtf" ) resource.AddFile( "materials/gui/silkicons/user_suit.vmt" ) resource.AddFile( "materials/gui/silkicons/user_suit.vtf" ) //Drawing function function DrawHUD() if CLIENT then DrawPlayers() end end if CLIENT then hook.Add("HUDPaint", "DrawHud", DrawHUD) end //Load icons if CLIENT then Guest = surface.GetTextureID("gui/silkicons/user") Respected = surface.GetTextureID("gui/silkicons/heart") Admin = surface.GetTextureID("gui/silkicons/shield") SAdmin = surface.GetTextureID("gui/silkicons/shield") Owner = surface.GetTextureID("gui/silkicons/star") Typing = surface.GetTextureID("gui/silkicons/comment") Away = surface.GetTextureID("gui/silkicons/exclamation") end //All the functions for the things drawn in DrawHUD() function GetHeadPos( ply ) local BoneIndx = ply:LookupBone("ValveBiped.Bip01_Head1") local BonePos, BoneAng = ply:GetBonePosition( BoneIndx ) return BonePos end function DrawPlayers() local k = nil local v = nil local maxdistance = 2048 local maxfullalpha = 512 for k, v in pairs(player.GetAll()) do if v != NULL and v:IsValid() and v:Nick() ~= LocalPlayer():Nick() and v:GetNetworkedBool("Ghosted") == false and v:GetColor() ~= Color(255, 255, 255, 0) and v:Nick() != "unconnected" then Position = v:GetShootPos() if v:GetNetworkedBool("Ragdolled") and ents.GetByIndex( v:GetNetworkedInt( "Ragdoll" ) ) != NULL then r = ents.GetByIndex( v:GetNetworkedInt( "Ragdoll" ) ) if r != NULL then Position = r:GetPos() end end local pDistance = LocalPlayer():GetShootPos():Distance( Position ) //Check if the player is even visible (e.g. no wall in between) local tracedata = {} tracedata.start = LocalPlayer():GetShootPos() tracedata.endpos = Position local trace = util.TraceLine(tracedata) if pDistance < maxdistance and pDistance > 64 and v:Alive() and trace.HitWorld == false then //Calculate alpha local dAlpha = 128 if pDistance > maxfullalpha then dAlpha = 128 - math.Clamp((pDistance - maxfullalpha) / (maxdistance-maxfullalpha)*128, 0, 128) end if v:GetNetworkedBool("Ragdolled") and ents.GetByIndex( v:GetNetworkedInt( "Ragdoll" ) ) != NULL then dPos = GetHeadPos( r ):ToScreen() else dPos = GetHeadPos( v ):ToScreen() end dPos.y = dPos.y - 75 dPos.y = dPos.y + (100 * (GetHeadPos(v):Distance(LocalPlayer():GetShootPos()) / 2048)) * 0.5 //Icon if v:GetNWBool("Typing") != true then if ply:HasLevel( ASS_LVL_SERVER_OWNER ) then Icon = Owner elseif ply:IsSuperAdmin() then Icon = SAdmin elseif ply:IsAdmin() then Icon = Admin elseif ply:IsRespected() then Icon = Respected elseif v:GetNWBool("AFK") then Icon = Away else Icon = Guest end else Icon = Typing end //Draw the box with the playername if !v:GetNWBool("AFK") then Nick = v:Nick() else if v:GetNWString("AFKReason") == "" then Nick = v:Nick() .. " (AFK)" else Nick = v:Nick() .. " (AFK: " .. v:GetNWString("AFKReason") .. ")" end end surface.SetFont( "ScoreboardText" ) local w = surface.GetTextSize( Nick ) local teamColor = team.GetColor( v:Team() ) ow = w w = w + 26 draw.RoundedBox( 6, dPos.x-((w+10)/2), dPos.y-10, w+10, 25, Color(0, 0, 0, dAlpha) ) draw.DrawText( Nick, "ScoreboardText", dPos.x + 14, dPos.y-6, Color(teamColor.r, teamColor.g, teamColor.b, dAlpha), 1 ) surface.SetTexture( Icon ) surface.SetDrawColor( 255, 255, 255, dAlpha) surface.DrawTexturedRect(dPos.x - (ow / 2) - 12, dPos.y - 6, 16, 16) end end end end //Rehook when anything goes wrong function DrawReHook() //hook.Remove( "HUDPaint", "DrawHud" ) hook.Add("HUDPaint", "DrawHud", DrawHUD) end timer.Create( "DrawRehook", 1, 0, DrawReHook ) //Show a chat icon when the user is typing a message if SERVER then function NA_TypeStart( ply ) ply:SetNWBool( "Typing", true ) end concommand.Add( "NA_TypeStart", NA_TypeStart ) function NA_TypeStop( ply ) ply:SetNWBool( "Typing", false ) end concommand.Add( "NA_TypeStop", NA_TypeStop ) elseif NewAdmin then hook.Add( "StartChat", "TypeStart", function() RunConsoleCommand("NA_TypeStart") end ) hook.Add( "FinishChat", "TypeStop", function() RunConsoleCommand("NA_TypeStop") end ) end ASS_RegisterPlugin(PLUGIN) [/code] Can anyone see any immidiate errors? Ok i changed something and in console i get this error [quote]Hook 'DrawHud' Failed: plugins/ass_playernames.lua:84: attempt to index global 'ply' (a nil value)[/quote]
You're trying to use the variable 'ply' while the current player is defined as 'v'.
Are you talking about this [code] //Icon if v:GetNWBool("Typing") != true then if ply:HasLevel( ASS_LVL_SERVER_OWNER ) then Icon = Owner elseif ply:IsSuperAdmin() then Icon = SAdmin elseif ply:IsAdmin() then Icon = Admin elseif ply:IsRespected() then Icon = Respected elseif v:GetNWBool("AFK") then Icon = Away else Icon = Guest end else Icon = Typing end [/code] Becuse at the moment i cant even get a box or text to shop up above the players heads and thats jsut the icons so im not sure whats wrong but should i change the 'ply' in that to v
all ply to v
ok i will try it [editline]08:18PM[/editline] [code] local PLUGIN = {} PLUGIN.Name = "Playernames" PLUGIN.Author = "Virus78" PLUGIN.Date = "6th August 2009" PLUGIN.Filename = PLUGIN_FILENAME PLUGIN.ClientSide = true PLUGIN.ServerSide = true PLUGIN.APIVersion = 2 PLUGIN.Gamemodes = {} resource.AddFile( "materials/gui/silkicons/comment.vmt" ) resource.AddFile( "materials/gui/silkicons/comment.vtf" ) resource.AddFile( "materials/gui/silkicons/user_suit.vmt" ) resource.AddFile( "materials/gui/silkicons/user_suit.vtf" ) //Enable and disable playernames pn_enabled = true end //Drawing function function DrawHUD() if pn_enabled then DrawPlayers() end end if (CLIENT) then hook.Add("HUDPaint", "DrawHud", DrawHUD) end //Load icons if (CLIENT) then Guest = surface.GetTextureID("gui/silkicons/user") Respected = surface.GetTextureID("gui/silkicons/heart") Admin = surface.GetTextureID("gui/silkicons/shield") SAdmin = surface.GetTextureID("gui/silkicons/shield") Owner = surface.GetTextureID("gui/silkicons/star") Typing = surface.GetTextureID("gui/silkicons/comment") Away = surface.GetTextureID("gui/silkicons/exclamation") end //All the functions for the things drawn in DrawHUD() function GetHeadPos( v ) local BoneIndx = v:LookupBone("ValveBiped.Bip01_Head1") local BonePos, BoneAng = v:GetBonePosition( BoneIndx ) return BonePos end function DrawPlayers() local k = nil local v = nil local maxdistance = 2048 local maxfullalpha = 512 for k, v in pairs(player.GetAll()) do if v != NULL and v:IsValid() and v:Nick() ~= LocalPlayer():Nick() and v:GetNetworkedBool("Ghosted") == false and v:GetColor() ~= Color(255, 255, 255, 0) and v:Nick() != "unconnected" then Position = v:GetShootPos() if v:GetNetworkedBool("Ragdolled") and ents.GetByIndex( v:GetNetworkedInt( "Ragdoll" ) ) != NULL then r = ents.GetByIndex( v:GetNetworkedInt( "Ragdoll" ) ) if r != NULL then Position = r:GetPos() end end local pDistance = LocalPlayer():GetShootPos():Distance( Position ) //Check if the player is even visible (e.g. no wall in between) local tracedata = {} tracedata.start = LocalPlayer():GetShootPos() tracedata.endpos = Position local trace = util.TraceLine(tracedata) if pDistance < maxdistance and pDistance > 64 and v:Alive() and trace.HitWorld == false then //Calculate alpha local dAlpha = 128 if pDistance > maxfullalpha then dAlpha = 128 - math.Clamp((pDistance - maxfullalpha) / (maxdistance-maxfullalpha)*128, 0, 128) end if v:GetNetworkedBool("Ragdolled") and ents.GetByIndex( v:GetNetworkedInt( "Ragdoll" ) ) != NULL then dPos = GetHeadPos( r ):ToScreen() else dPos = GetHeadPos( v ):ToScreen() end dPos.y = dPos.y - 75 dPos.y = dPos.y + (100 * (GetHeadPos(v):Distance(LocalPlayer():GetShootPos()) / 2048)) * 0.5 //Icon if v:GetNWBool("Typing") != true then if v:HasLevel( ASS_LVL_SERVER_OWNER ) then Icon = Owner elseif v:IsSuperAdmin() then Icon = SAdmin elseif v:IsAdmin() then Icon = Admin elseif v:IsRespected() then Icon = Respected elseif v:GetNWBool("AFK") then Icon = Away else Icon = Guest end else Icon = Typing end //Draw the box with the playername if !v:GetNWBool("AFK") then Nick = v:Nick() else if v:GetNWString("AFKReason") == "" then Nick = v:Nick() .. " (AFK)" else Nick = v:Nick() .. " (AFK: " .. v:GetNWString("AFKReason") .. ")" end end surface.SetFont( "ScoreboardText" ) local w = surface.GetTextSize( Nick ) local teamColor = team.GetColor( v:Team() ) ow = w w = w + 26 draw.RoundedBox( 6, dPos.x-((w+10)/2), dPos.y-10, w+10, 25, Color(0, 0, 0, dAlpha) ) draw.DrawText( Nick, "ScoreboardText", dPos.x + 14, dPos.y-6, Color(teamColor.r, teamColor.g, teamColor.b, dAlpha), 1 ) surface.SetTexture( Icon ) surface.SetDrawColor( 255, 255, 255, dAlpha) surface.DrawTexturedRect(dPos.x - (ow / 2) - 12, dPos.y - 6, 16, 16) end end end end //Rehook when anything goes wrong function DrawReHook() //hook.Remove( "HUDPaint", "DrawHud" ) hook.Add("HUDPaint", "DrawHud", DrawHUD) end timer.Create( "DrawRehook", 1, 0, DrawReHook ) //Show a chat icon when the user is typing a message if (SERVER) then function NA_TypeStart( v ) v:SetNWBool( "Typing", true ) end concommand.Add( "NA_TypeStart", NA_TypeStart ) function NA_TypeStop( v ) v:SetNWBool( "Typing", false ) end concommand.Add( "NA_TypeStop", NA_TypeStop ) elseif NewAdmin then hook.Add( "StartChat", "TypeStart", function() RunConsoleCommand("NA_TypeStart") end ) hook.Add( "FinishChat", "TypeStop", function() RunConsoleCommand("NA_TypeStop") end ) end ASS_RegisterPlugin(PLUGIN) [/code] Ok this is my new code its still not working :S this is seriosuly frustrating
Why do you have an extra end under pn_enabled? Should work now :3
Change author to Overv and note that you converted it into an ASSMod plugin.
Ok will do :P and i will try the pn_enabled thing i wasnt sure if you would mind you code being edited but i guessed that the more openly available it was the better [editline]11:28PM[/editline] thanks it worked here is my final code if anyone else wants it [lua] local PLUGIN = {} PLUGIN.Name = "PlayerNames Converted By Virus78" PLUGIN.Author = "Overv" PLUGIN.Date = "6th August 2009" PLUGIN.Filename = PLUGIN_FILENAME PLUGIN.ClientSide = true PLUGIN.ServerSide = true PLUGIN.APIVersion = 2 PLUGIN.Gamemodes = {} // Special Thanks to Overv and commander204 who helped me complete this :D resource.AddFile( "materials/gui/silkicons/comment.vmt" ) resource.AddFile( "materials/gui/silkicons/comment.vtf" ) resource.AddFile( "materials/gui/silkicons/user_suit.vmt" ) resource.AddFile( "materials/gui/silkicons/user_suit.vtf" ) //Enable and disable playernames pn_enabled = true //Drawing function function DrawHUD() if pn_enabled then DrawPlayers() end end if (CLIENT) then hook.Add("HUDPaint", "DrawHud", DrawHUD) end //Load icons if (CLIENT) then Guest = surface.GetTextureID("gui/silkicons/user") Respected = surface.GetTextureID("gui/silkicons/heart") Admin = surface.GetTextureID("gui/silkicons/shield") SAdmin = surface.GetTextureID("gui/silkicons/shield") Owner = surface.GetTextureID("gui/silkicons/star") Typing = surface.GetTextureID("gui/silkicons/comment") Away = surface.GetTextureID("gui/silkicons/exclamation") end //All the functions for the things drawn in DrawHUD() function GetHeadPos( v ) local BoneIndx = v:LookupBone("ValveBiped.Bip01_Head1") local BonePos, BoneAng = v:GetBonePosition( BoneIndx ) return BonePos end function DrawPlayers() local k = nil local v = nil local maxdistance = 2048 local maxfullalpha = 512 for k, v in pairs(player.GetAll()) do if v != NULL and v:IsValid() and v:Nick() ~= LocalPlayer():Nick() and v:GetNetworkedBool("Ghosted") == false and v:GetColor() ~= Color(255, 255, 255, 0) and v:Nick() != "unconnected" then Position = v:GetShootPos() if v:GetNetworkedBool("Ragdolled") and ents.GetByIndex( v:GetNetworkedInt( "Ragdoll" ) ) != NULL then r = ents.GetByIndex( v:GetNetworkedInt( "Ragdoll" ) ) if r != NULL then Position = r:GetPos() end end local pDistance = LocalPlayer():GetShootPos():Distance( Position ) //Check if the player is even visible (e.g. no wall in between) local tracedata = {} tracedata.start = LocalPlayer():GetShootPos() tracedata.endpos = Position local trace = util.TraceLine(tracedata) if pDistance < maxdistance and pDistance > 64 and v:Alive() and trace.HitWorld == false then //Calculate alpha local dAlpha = 128 if pDistance > maxfullalpha then dAlpha = 128 - math.Clamp((pDistance - maxfullalpha) / (maxdistance-maxfullalpha)*128, 0, 128) end if v:GetNetworkedBool("Ragdolled") and ents.GetByIndex( v:GetNetworkedInt( "Ragdoll" ) ) != NULL then dPos = GetHeadPos( r ):ToScreen() else dPos = GetHeadPos( v ):ToScreen() end dPos.y = dPos.y - 75 dPos.y = dPos.y + (100 * (GetHeadPos(v):Distance(LocalPlayer():GetShootPos()) / 2048)) * 0.5 //Icon if v:GetNWBool("Typing") != true then if v:HasLevel( ASS_LVL_SERVER_OWNER ) then Icon = Owner elseif v:IsSuperAdmin() then Icon = SAdmin elseif v:IsAdmin() then Icon = Admin elseif v:IsRespected() then Icon = Respected elseif v:GetNWBool("AFK") then Icon = Away else Icon = Guest end else Icon = Typing end //Draw the box with the playername if !v:GetNWBool("AFK") then Nick = v:Nick() else if v:GetNWString("AFKReason") == "" then Nick = v:Nick() .. " (AFK)" else Nick = v:Nick() .. " (AFK: " .. v:GetNWString("AFKReason") .. ")" end end surface.SetFont( "ScoreboardText" ) local w = surface.GetTextSize( Nick ) local teamColor = team.GetColor( v:Team() ) ow = w w = w + 26 draw.RoundedBox( 6, dPos.x-((w+10)/2), dPos.y-10, w+10, 25, Color(0, 0, 0, dAlpha) ) draw.DrawText( Nick, "ScoreboardText", dPos.x + 14, dPos.y-6, Color(teamColor.r, teamColor.g, teamColor.b, dAlpha), 1 ) surface.SetTexture( Icon ) surface.SetDrawColor( 255, 255, 255, dAlpha) surface.DrawTexturedRect(dPos.x - (ow / 2) - 12, dPos.y - 6, 16, 16) end end end end //Rehook when anything goes wrong function DrawReHook() //hook.Remove( "HUDPaint", "DrawHud" ) hook.Add("HUDPaint", "DrawHud", DrawHUD) end timer.Create( "DrawRehook", 1, 0, DrawReHook ) //Show a chat icon when the user is typing a message if (SERVER) then function NA_TypeStart( v ) v:SetNWBool( "Typing", true ) end concommand.Add( "NA_TypeStart", NA_TypeStart ) function NA_TypeStop( v ) v:SetNWBool( "Typing", false ) end concommand.Add( "NA_TypeStop", NA_TypeStop ) elseif NewAdmin then hook.Add( "StartChat", "TypeStart", function() RunConsoleCommand("NA_TypeStart") end ) hook.Add( "FinishChat", "TypeStop", function() RunConsoleCommand("NA_TypeStop") end ) end ASS_RegisterPlugin(PLUGIN) [/lua] Also what are the BBCodes to post this with correct syntax highlighting? (NVM i worked it out) And is there a better way to check if the player is typig? becuse its kinda buggy at the moment sometimes it works somethimes it dosent
Sorry, you need to Log In to post a reply to this thread.