Advertisement
HK47

Untitled

Oct 19th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.25 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. ENT.Type = "anim"
  4. ENT.Base = "base_anim"
  5. ENT.Spawnable = true
  6. ENT.PrintName = "Teleporter"
  7. ENT.Category = "TELEPORTERS"
  8.  
  9. ENT.health = 100
  10.  
  11. if SERVER then
  12. util.AddNetworkString("create_a_teleport")
  13. util.AddNetworkString("teleport_player_kekc")
  14. util.AddNetworkString("teleport_change_health")
  15.  
  16. CreateConVar("tps_kekc_enable", 1)
  17. CreateConVar("tps_kekc_enablehp", 1)
  18. else
  19. surface.CreateFont("teleporters_font1", {
  20. font = "Segoe UI",
  21. size = 1000,
  22. weight = 0,
  23. blursize = 0,
  24. scanlines = 0,
  25. antialias = true,
  26. underline = false,
  27. italic = false,
  28. strikeout = false,
  29. symbol = false,
  30. rotary = false,
  31. shadow = false,
  32. additive = false,
  33. outline = false,
  34. })
  35. end
  36.  
  37. function ENT:Draw()
  38. if SERVER then return end
  39.  
  40. self:DrawModel()
  41.  
  42. if self.teleport then
  43. local private = "<>"
  44. if self.teleport.private then private = "Yes" else private = "No" end
  45.  
  46. cam.Start3D2D(self:GetPos() + Vector(0, 0, 70), Angle(0, CurTime() * 60, 90), 0.1)
  47. draw.DrawText("Name: " .. self.teleport.name, "teleporters_font1", 0, 0, Color(255, 255, 255), TEXT_ALIGN_CENTER)
  48. draw.DrawText("Owner: " .. self.teleport.owner, "teleporters_font1", 0, 80, Color(255, 255, 255), TEXT_ALIGN_CENTER)
  49. draw.DrawText(self.teleport.desc, "teleporters_font1", 0, 160, Color(255, 255, 255), TEXT_ALIGN_CENTER)
  50. draw.DrawText("Private: " .. private, "teleporters_font1", 0, 240, Color(255, 255, 255), TEXT_ALIGN_CENTER)
  51. if GetConVar("tps_kekc_enablehp"):GetBool() then draw.DrawText("Health: " .. self.health, "teleporters_font1", 0, 320, Color(255 - self.health * 2.55, self.health * 2.55, 0), TEXT_ALIGN_CENTER) end
  52. cam.End3D2D()
  53.  
  54. cam.Start3D2D(self:GetPos() + Vector(0, 0, 70), Angle(0, 180 + CurTime() * 60, 90), 0.1)
  55. draw.DrawText("Name: " .. self.teleport.name, "teleporters_font1", 0, 0, Color(255, 255, 255), TEXT_ALIGN_CENTER)
  56. draw.DrawText("Owner: " .. self.teleport.owner, "teleporters_font1", 0, 80, Color(255, 255, 255), TEXT_ALIGN_CENTER)
  57. draw.DrawText(self.teleport.desc, "teleporters_font1", 0, 160, Color(255, 255, 255), TEXT_ALIGN_CENTER)
  58. draw.DrawText("Private: " .. private, "teleporters_font1", 0, 240, Color(255, 255, 255), TEXT_ALIGN_CENTER)
  59. if GetConVar("tps_kekc_enablehp"):GetBool() then draw.DrawText("Health: " .. self.health, "teleporters_font1", 0, 320, Color(255 - self.health * 2.55, self.health * 2.55, 0), TEXT_ALIGN_CENTER) end
  60. cam.End3D2D()
  61. end
  62. end
  63.  
  64. function ENT:OnTakeDamage(dmg)
  65. if CLIENT then return end
  66. if not GetConVar("tps_kekc_enablehp"):GetBool() then return end
  67.  
  68. self.health = math.Round(self.health - dmg:GetDamage() / 10)
  69.  
  70. if self.health <= 0 then
  71. self:EmitSound("phx/explode00.wav", 400, 100)
  72.  
  73. local ef = EffectData()
  74. ef:SetOrigin(self:GetPos())
  75. util.Effect("Explosion", ef)
  76.  
  77. self:Remove()
  78.  
  79. return
  80. end
  81.  
  82. net.Start("teleport_change_health")
  83. net.WriteInt(self.health, 32)
  84. net.WriteEntity(self)
  85. net.Broadcast()
  86. end
  87.  
  88. function ENT:Initialize()
  89. if CLIENT then
  90. return
  91. end
  92.  
  93. umsg.Start("open_menu_kekc", ply)
  94. umsg.Entity(self)
  95. umsg.End()
  96.  
  97. self:SetModel("models/props_lab/teleplatform.mdl")
  98. self:SetMoveType(MOVETYPE_VPHYSICS)
  99. self:SetSolid(SOLID_VPHYSICS)
  100. self:PhysicsInit(SOLID_VPHYSICS)
  101. end
  102.  
  103. function ENT:PhysicsCollide(data, physobj)
  104. if CLIENT then return end
  105. end
  106.  
  107. local next_use = 0
  108. function ENT:Use(ply, caller)
  109. if not GetConVar("tps_kekc_enable"):GetBool() then if CurTime() > next_use then ply:ChatPrint("Teleporters is not enable on this server!") next_use = CurTime() + 1 end return end
  110.  
  111. umsg.Start("use_teleport_kekc", ply)
  112. umsg.Entity(ply)
  113. umsg.Entity(self)
  114. umsg.End()
  115. end
  116.  
  117. function ENT:SpawnFunction(ply, tr, name)
  118. if not tr.Hit then return end
  119.  
  120. local pos = tr.HitPos + tr.HitNormal * 32
  121.  
  122. local ent = ents.Create(name)
  123. ent:SetPos(pos)
  124. ent:Spawn()
  125. ent:Activate()
  126.  
  127. if IsValid(ent:GetPhysicsObject()) then ent:GetPhysicsObject():Wake() else return NULL end
  128.  
  129. return ent
  130. end
  131.  
  132. function ENT:OnRemove()
  133. table.RemoveByValue(TELEPORTS_TABLE_KEKC, self.teleport)
  134. end
  135.  
  136.  
  137. // CALLBACK FUNCTIONS
  138.  
  139. // Callback function creates a teleport
  140. local function CreateTeleport()
  141. local name = net.ReadString()
  142. local desc = net.ReadString()
  143. local ply = net.ReadEntity()
  144. local lab = net.ReadBit()
  145. local ent = net.ReadEntity()
  146.  
  147. ent.teleport = {}
  148. ent.teleport.name = name
  149. ent.teleport.entity = ent
  150. ent.teleport.private = util.tobool(lab)
  151. ent.teleport.desc = desc
  152. ent.teleport.owner = ply
  153.  
  154. table.insert(TELEPORTS_TABLE_KEKC, ent.teleport)
  155. end
  156. net.Receive("create_a_teleport", CreateTeleport)
  157.  
  158.  
  159. // Callback function teleports player
  160. local function TeleportPlayer()
  161. local ply = net.ReadEntity()
  162. local tp = net.ReadEntity()
  163.  
  164. if IsValid(ply) and ply:Alive() and IsValid(tp) and SERVER then
  165. if not tp.teleport.private then
  166. ply:SetPos(tp:GetPos())
  167. //ply:EmitSound("garrysmod/save_load" .. math.random(1, 4) .. ".wav")
  168. ply:EmitSound("hl1/ambience/particle_suck1.wav")
  169. ply:SetEyeAngles(Angle(0, tp:GetAngles().yaw, 0))
  170.  
  171. umsg.Start("effect_teleport_kekc")
  172. umsg.Entity(ply)
  173. umsg.End()
  174. else
  175. if ply != tp.teleport.owner then
  176. ply:ChatPrint("This teleport is private!")
  177. else
  178. ply:SetPos(tp:GetPos())
  179. //ply:EmitSound("garrysmod/save_load" .. math.random(1, 4) .. ".wav")
  180. ply:EmitSound("hl1/ambience/particle_suck1.wav")
  181. ply:SetEyeAngles(Angle(0, tp:GetAngles().yaw, 0))
  182.  
  183. umsg.Start("effect_teleport_kekc")
  184. umsg.Entity(ply)
  185. umsg.End()
  186. end
  187. end
  188. else
  189. ply:ChatPrint("This teleport is not valid or you're not alive")
  190. end
  191. end
  192. net.Receive("teleport_player_kekc", TeleportPlayer)
  193.  
  194.  
  195. // Callback function changes health on client
  196. local function ChangeHealth_cl()
  197. if SERVER then return end
  198.  
  199. local hp = net.ReadInt(32)
  200. local tp = net.ReadEntity()
  201.  
  202. tp.health = hp
  203. end
  204. net.Receive("teleport_change_health", ChangeHealth_cl)
  205.  
  206.  
  207. // Callback function opens the menu
  208. local function OpenTeleportMenu(data)
  209. if SERVER then return end
  210.  
  211. local ply = data:ReadEntity()
  212. local tp = data:ReadEntity()
  213.  
  214. if ply.Menu_teleports_kekc and IsValid(ply.Menu_teleports_kekc) then return end
  215.  
  216. ply.Menu_teleports_kekc = vgui.Create("DFrame")
  217.  
  218. local win = ply.Menu_teleports_kekc
  219. win:SetSize(600, 300)
  220. win:Center()
  221. win:SetTitle("Menu")
  222. win:MakePopup()
  223. win.Paint = function()
  224. if win and IsValid(win) then
  225. local w = win:GetWide()
  226. local h = win:GetTall()
  227.  
  228. draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 220))
  229. end
  230. end
  231.  
  232. local l = vgui.Create("DListView", win)
  233. l:SetSize(580, 260)
  234. l:SetPos(10, 30)
  235. l:AddColumn("Name")
  236. l:AddColumn("Owner")
  237. l:AddColumn("Description")
  238. l:AddColumn("Private")
  239. l:AddColumn("Distance")
  240. l.OnClickLine = function(parent, line, isselected)
  241. local entity = NULL
  242.  
  243. for k, v in pairs(TELEPORTS_TABLE_KEKC) do
  244. if v.name == line:GetValue(1) then
  245. entity = v.entity
  246. end
  247. end
  248.  
  249. if entity == tp then ply:ChatPrint("You can't teleport to youself!") return end
  250.  
  251. //now we teleports player
  252. net.Start("teleport_player_kekc")
  253. net.WriteEntity(ply)
  254. net.WriteEntity(entity)
  255. net.SendToServer()
  256.  
  257. if win and IsValid(win) then win:Close() end
  258. end
  259.  
  260. for k, v in pairs(TELEPORTS_TABLE_KEKC) do
  261. if v.entity == tp then continue end
  262.  
  263. local private = "<>"
  264. if v.private then private = "Yes" else private = "No" end
  265.  
  266. l:AddLine(v.name, v.owner:Nick(), v.desc, private, math.Round(tp:GetPos():Distance(v.entity:GetPos())))
  267. end
  268. end
  269. usermessage.Hook("use_teleport_kekc", OpenTeleportMenu)
  270.  
  271.  
  272. // Callback function opens the menu
  273. local function CreateEffect(data)
  274. if SERVER then return end
  275.  
  276. local bloom = 1
  277. local ply = data:ReadEntity()
  278.  
  279. hook.Add("RenderScreenspaceEffects", "stuff_storm_hp" .. ply:EntIndex(), function()
  280. if bloom <= 0 then hook.Remove("RenderScreenspaceEffects", "stuff_storm_hp" .. ply:EntIndex()) return end
  281.  
  282. bloom = bloom - 0.003
  283.  
  284. local tab = {}
  285. tab["$pp_colour_addr"] = 0
  286. tab["$pp_colour_addg"] = 0
  287. tab["$pp_colour_addb"] = 0
  288. tab["$pp_colour_brightness"] = bloom
  289. tab["$pp_colour_contrast"] = 1
  290. tab["$pp_colour_colour"] = 1
  291. tab["$pp_colour_mulr"] = 0
  292. tab["$pp_colour_mulg"] = 0
  293. tab["$pp_colour_mulb"] = 0
  294.  
  295. DrawColorModify(tab)
  296. end)
  297. end
  298. usermessage.Hook("effect_teleport_kekc", CreateEffect)
  299.  
  300.  
  301.  
  302. local function OpenMenu(data)
  303. if SERVER then return end
  304.  
  305. local ent = data:ReadEntity()
  306.  
  307. local win = vgui.Create("DFrame")
  308. win:SetSize(200, 130)
  309. win:Center()
  310. win:SetTitle("Options")
  311. win:ShowCloseButton(true)
  312. win:MakePopup()
  313. win.Paint = function()
  314. if win and win:IsActive() then
  315. local w = win:GetWide()
  316. local h = win:GetTall()
  317.  
  318. draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 220))
  319. end
  320. end
  321.  
  322. local name = vgui.Create("DTextEntry", win)
  323. name:SetPos(10, 30)
  324. name:SetSize(180, 20)
  325. name:SetText("Name")
  326.  
  327. local desc = vgui.Create("DTextEntry", win)
  328. desc:SetPos(10, 60)
  329. desc:SetSize(180, 20)
  330. desc:SetText("Description")
  331.  
  332. local ch = vgui.Create("DCheckBoxLabel", win)
  333. ch:SetPos(10, 80)
  334. ch:SetValue(0)
  335. ch:SetText("Private?")
  336. ch:SizeToContents()
  337.  
  338. local accept = vgui.Create("DButton", win)
  339. accept:SetPos(10, 100)
  340. accept:SetSize(180, 20)
  341. accept:SetText("Accept")
  342. accept.DoClick = function()
  343. if win and win:IsActive() then
  344. local n, d, p, c = name:GetValue(), desc:GetValue(), LocalPlayer(), ch:GetChecked()
  345. local close
  346.  
  347. if string.len(n) > 15 then p:ChatPrint("You have reached maximum symbols in Name text box!") return end
  348. if string.len(n) > 40 then p:ChatPrint("You have reached maximum symbols in Description text box!") return end
  349.  
  350. for k, v in pairs(TELEPORTS_TABLE_KEKC) do
  351. if v.name == n then close = true break end
  352. end
  353.  
  354. if close then p:ChatPrint("Teleport with " .. n .. " name is already exists!") return end
  355.  
  356. net.Start("create_a_teleport")
  357. net.WriteString(n)
  358. net.WriteString(d)
  359. net.WriteEntity(p)
  360. net.WriteBit(c)
  361. net.WriteEntity(ent)
  362. net.SendToServer()
  363.  
  364. ent.teleport.name = name
  365. ent.teleport.entity = ent
  366. ent.teleport.private = util.tobool(lab)
  367. ent.teleport.desc = desc
  368. ent.teleport.owner = ply
  369.  
  370. win:Close()
  371. end
  372. end
  373. end
  374. usermessage.Hook("open_menu_kekc", OpenMenu)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement