General > Developers Corner

Admin sounds, tools and other code chat.

<< < (16/31) > >>

jay209015:
Another thing is I got the effect I want, but the ring is verticle instead of horizontal. No matter what I set the angles to it stays the same. Heres the effects code.


--- Code: ---local function MakeEffect( ply )
local effectdata = EffectData()
effectdata:SetStart( ply:GetPos() )
effectdata:SetOrigin( ply:GetPos() )
effectdata:SetNormal( ply:GetPos() )
effectdata:SetMagnitude( 3 )
effectdata:SetScale( 2 )
effectdata:SetRadius( 5 )
effectdata:SetAngle( Angle( 90, 90, 0) )
util.Effect( "selection_indicator", effectdata, true, true )
end

--- End code ---

Also I found the error in for my timer, but no fix.


--- Code: ---
if ply:IsValid() then
timer.Create( "Admin" ..ply:Nick(), 1, 0, MakeEffect, ply )
else
        timer.Destroy( "Admin" ..ply:Nick() )
end

--- End code ---

Let's say I'm admin ok, so when I join it creates a timer called AdminJay209015, but when I leave it tries to remove AdminNull bc ply is now a null value. So I need a way to check if ply disconnects, check to see if they're admin, and if yes then get their nick and destroy their timer. To advance for my knowledge though :'(. Maybe one of you lua experts can help here.

spbogie:
A few options here, in no particular order:

* Hook into PlayerDisconnected and remove the timer when they disconnect.
* Use a non-recurring timer, and recreate it each time it calls with a valid player (if it's not valid just return and it won't get called next time)
* Create your own "timer" using a Think hook and comparing against CurTime(). Loop through all players, create effect when ply:IsAdmin() is true
Edit: I also recommend against using their name as the name for the timer. Consider what happens if they are to change their name while connected and go to connect. Best option to uniquely identify them would probably be UniqueID. Either way, this is only necessary if you go the Named timer/PlayerDisconnected route.

jay209015:
Thank you Spbodie it works, and here is my new code:


--- Code: ---local function MakeEffect( ply )
local effectdata = EffectData()
effectdata:SetStart( ply:GetPos() )
effectdata:SetOrigin( ply:GetPos() )
effectdata:SetNormal( ply:GetPos() )
effectdata:SetMagnitude( 3 )
effectdata:SetScale( 2 )
effectdata:SetRadius( 5 )
effectdata:SetAngle( Angle( 0, 0, 0) )
util.Effect( "selection_indicator", effectdata, true, true )
end
function AdminJoin( ply)
content = file.Read( "Umotd/admins.txt" )
if ( !ply:IsAdmin() ) then return end
timer.Simple( 3, game.ConsoleCommand, "ulx playsound admin.mp3 \n")
timer.Simple( 5, game.ConsoleCommand, "ulx csay admin " ..ply:Nick().. " has connected \n")
timer.Create( "Admin" ..ply:SteamID( ), 1, 0, MakeEffect, ply )
if string.find( content, ply:Nick(), 1, true ) then
content = content
else
content = content.. "\n" ..ply:Nick()
file.Write( "Umotd/admins.txt", content )
end
function PlyDisconnected( ply )
if ply:IsValid() then
timer.Destroy( "Admin" ..ply:SteamID( ) )
end
end
hook.Add( "PlayerDisconnected" , "PlyDisconnected" , PlyDisconnected )
end
hook.Add( "PlayerInitialSpawn", "AdminJoin", AdminJoin )
concommand.Add( "Ajoin", AdminJoin )
--- End code ---



Now to get the effects to dsiplay a horizontal ring instead of a vertical one.

==EDIT==
New Code: Now rights admins that have connected to the server to Admins.txt for the Umotd file so that the admin list is available to users :D

jay209015:
Revision of code above, better file.write on spawn rather than initial spawn plus cleaner code.


--- Code: ---local function MakeEffect( ply )
local effectdata = EffectData()
effectdata:SetStart( ply:GetPos() )
effectdata:SetOrigin( ply:GetPos() )
effectdata:SetNormal( ply:GetPos() )
effectdata:SetMagnitude( 3 )
effectdata:SetScale( 2 )
effectdata:SetRadius( 5 )
effectdata:SetAngle( Angle( 0, 0, 0) )
util.Effect( "selection_indicator", effectdata, true, true )
end
function AdminJoin( ply)
if ( !ply:IsAdmin() ) then return end
timer.Simple( 3, game.ConsoleCommand, "ulx playsound admin.mp3 \n")
timer.Simple( 5, game.ConsoleCommand, "ulx csay admin " ..ply:Nick().. " has connected \n")
timer.Create( "Admin" ..ply:SteamID( ), 1, 0, MakeEffect, ply )
function PlyDisconnected( ply )
if ply:IsValid() then
timer.Destroy( "Admin" ..ply:SteamID( ) )
end
end
hook.Add( "PlayerDisconnected" , "PlyDisconnected" , PlyDisconnected )
end
hook.Add( "PlayerInitialSpawn", "AdminJoin", AdminJoin )
concommand.Add( "Ajoin", AdminJoin )
function AdminWrite( ply )
content = file.Read( "Umotd/admins.txt" )
if ply:IsUserGroup("admin") || ply:IsUserGroup("superadmin") then
if string.find( content, ply:Nick(), 1, true ) then
content = content
else
content = content.. "<li>" ..ply:Nick()
file.Write( "Umotd/admins.txt", content )
end
else

end
end
hook.Add( "PlayerSpawn", "AdminWrite", AdminWrite )
--- End code ---

jay209015:
Script is not writing to players.txt, but the admins.txt is working perfectly. players.txt does exist in the proper location to, it's just not writing to it.


--- Code: ---function AdminWrite( ply )
content = file.Read( "Umotd/admins.txt" )
contentp = file.Read( "Umotd/players.txt" )
if ply:IsUserGroup("admin") || ply:IsUserGroup("superadmin") then
if string.find( content, ply:Nick(), 1, true ) then
content = content
else
content = content.. "<li>" ..ply:Nick()
file.Write( "Umotd/admins.txt", content )
end
else
if string.find( contentp, ply:Nick(), 1, true ) then
contentp = contentp
else
contentp = contentp.. "<li>" ..ply:Nick()
file.Write( "Umotd/players.txt", contentp )
end
end
end
hook.Add( "PlayerSpawn", "AdminWrite", AdminWrite )
--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version