Advertisement
HK47

Untitled

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