Advertisement
Guest User

SERVER SIDE

a guest
Dec 7th, 2019
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. // server side apple
  2. if CLIENT then return end
  3. AddCSLuaFile( "cl_player.lua" )
  4.  
  5. if file.Exists( "apple_join_disconnect_warning/indicate.txt", "DATA" ) == false then
  6. file.CreateDir("apple_join_disconnect_warning")
  7. file.Write( "apple_join_disconnect_warning/indicate.txt", "1" )
  8. end
  9.  
  10.  
  11. //Connected
  12. function PlayerConnectAnnouncement( ply, ip )
  13. for k,v in pairs(player.GetAll()) do
  14. umsg.Start( "PlayerConnectAnnouncement", v)
  15. umsg.String(ply)
  16. umsg.String(file.Read( "apple_join_disconnect_warning/indicate.txt" ))
  17. umsg.End()
  18. end
  19. Msg("Player " .. ply .. " has connected to the server.\n")
  20. end
  21. hook.Add( "PlayerConnect", "PlayerConnectAnnouncement", PlayerConnectAnnouncement )
  22.  
  23. //Spawn
  24. function PlayerInitialSpawnAnnouncement( ply )
  25. timer.Simple( 3, function()
  26. if !ply:IsValid() then return end
  27. for k,v in pairs(player.GetAll()) do
  28. if v:IsAdmin() then
  29. -- if ply:IsBot() then return end
  30. umsg.Start( "PlayerInitialSpawnAnnouncement", v)
  31. umsg.String(ply:Nick())
  32. umsg.Short(ply:Team())
  33. umsg.String(ply:SteamID())
  34. umsg.String(file.Read( "apple_join_disconnect_warning/indicate.txt" ))
  35. umsg.End()
  36. else
  37. umsg.Start( "PlayerInitialSpawnAnnouncement2", v)
  38. umsg.String(ply:Nick())
  39. umsg.Short(ply:Team())
  40. umsg.String(file.Read( "apple_join_disconnect_warning/indicate.txt" ))
  41. umsg.End()
  42. end
  43. end
  44. Msg("Player " .. ply:Nick() .. " has spawned in the server.\n")
  45. end)
  46. end
  47. hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawnAnnouncement", PlayerInitialSpawnAnnouncement )
  48.  
  49.  
  50. //Disconnect
  51. function PlayerDisconnectAnnouncement( ply )
  52. for k,v in pairs(player.GetAll()) do
  53. if v:IsAdmin() then
  54. if ply:IsBot() then return end
  55. umsg.Start( "PlayerDisconnectAnnouncement", v)
  56. umsg.String(ply:Nick())
  57. umsg.Short(ply:Team())
  58. umsg.String(ply:SteamID())
  59. umsg.String(file.Read( "apple_join_disconnect_warning/indicate.txt" ))
  60. umsg.End()
  61. else
  62. umsg.Start( "PlayerDisconnectAnnouncement2", v)
  63. umsg.String(ply:Nick())
  64. umsg.Short(ply:Team())
  65. umsg.String(file.Read( "apple_join_disconnect_warning/indicate.txt" ))
  66. umsg.End()
  67. end
  68. end
  69. Msg("Player " .. ply:Nick() .. " has left the server.\n")
  70. end
  71. hook.Add( "PlayerDisconnected", "PlayerDisconnectAnnouncement", PlayerDisconnectAnnouncement )
  72.  
  73.  
  74.  
  75. concommand.Add( "jd_sounds", function(ply, cmd, args)
  76. if ply:IsPlayer() == false || ply:IsSuperAdmin() == false then
  77. MsgC(Color(255,0,0,255),"Either console has attempted to turn sounds off, or a player is attempting to turn sounds off for apple_join_disonnect_warning addon!")
  78. return end
  79. if tostring(args[1]) == "on" then
  80. file.Write( "apple_join_disconnect_warning/indicate.txt", "1" )
  81. umsg.Start( "PlayerJDAnnouncement", ply)
  82. umsg.String("You have turned on sounds for: Apples_Join_Disconnect_Warning")
  83. umsg.End()
  84. elseif tostring(args[1]) == "off" then
  85. file.Write( "apple_join_disconnect_warning/indicate.txt", "0" )
  86. umsg.Start( "PlayerJDAnnouncement", ply)
  87. umsg.String("You have turned off sounds for: Apples_Join_Disconnect_Warning")
  88. umsg.End()
  89. else
  90. umsg.Start( "PlayerJDAnnouncement", ply)
  91. umsg.String("There are only two options, on or off. You selected '"..tostring(args[1]).."' which is not a valid option!")
  92. umsg.End()
  93. end
  94. end)
  95.  
  96.  
  97.  
  98.  
  99.  
  100. if SERVER then
  101. local YOUR_VERSION = "1.11"
  102. local PLY2 = "105"
  103. local ADDON_NAME = "join_disconnect"
  104. local ADDON_ACTUAL_NAME = "apple_join_disconnect_warning"
  105. local DOWNLOAD_LINK = "http://goo.gl/VitT7Z"
  106. local MESSAGE_TO_SERVER = "APPLE'S JOIN/DISCONNECT MESSAGE"
  107.  
  108. hook.Add('PlayerInitialSpawn','PlayerInitialSpawn'..ADDON_NAME, function(ply)
  109. http.Fetch( "https://raw.githubusercontent.com/chaos12135/gmod-development/master/branches/"..ADDON_NAME..".txt", function( body, len, headers, code )
  110. if body == nil then return end
  111. local body = string.Explode(" ",body)
  112. if tostring(body[1]) != tostring("Version") then return end
  113. if tonumber(body[2]) != tonumber(YOUR_VERSION) then
  114. if ply:GetPData(ADDON_NAME..""..PLY2) != nil || ply:GetPData(ADDON_NAME..""..PLY2) != "1" && ply:IsSuperAdmin() == true then
  115. umsg.Start(ADDON_NAME, ply)
  116. umsg.String(YOUR_VERSION)
  117. umsg.String(body[2])
  118. umsg.String(ADDON_ACTUAL_NAME)
  119. umsg.String(DOWNLOAD_LINK)
  120. umsg.End()
  121. end
  122.  
  123. MsgC("\n",Color(255,0,0,255),"- - OUT OF DATE - -","\n")
  124. MsgN("~"..MESSAGE_TO_SERVER.."~")
  125. MsgC(Color(255,255,255,255),"Your Version: ",Color(255,0,0,255),YOUR_VERSION,"\n")
  126. MsgC(Color(255,255,255,255),"Online Version: ",Color(255,0,0,255),body[2])
  127. MsgN("We here at Apple Inc. strongly suggest that you keep this addon updated")
  128. MsgC(Color(255,255,255,255),"Please go here and update: ",Color(0,255,255,255),""..DOWNLOAD_LINK.."\n")
  129. end
  130. end,
  131. function( error )
  132. MsgN("DOESNOT WORK")
  133. end)
  134. end)
  135. net.Receive( ADDON_NAME, function( length, client )
  136. net.ReadEntity():SetPData(ADDON_NAME..""..PLY2,"1")
  137. end )
  138. util.AddNetworkString( ADDON_NAME )
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement