Advertisement
HK47

Untitled

Oct 19th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.38 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:Nick(), "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:Nick(), "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. timer.Simple(0.1, function()
  94. if IsValid(self.owner) then
  95. umsg.Start("open_menu_kekc", self.owner)
  96. umsg.Entity(self)
  97. umsg.End()
  98. end
  99. end)
  100.  
  101. self:SetModel("models/props_lab/teleplatform.mdl")
  102. self:SetMoveType(MOVETYPE_VPHYSICS)
  103. self:SetSolid(SOLID_VPHYSICS)
  104. self:PhysicsInit(SOLID_VPHYSICS)
  105. end
  106.  
  107. function ENT:PhysicsCollide(data, physobj)
  108. if CLIENT then return end
  109. end
  110.  
  111. local next_use = 0
  112. function ENT:Use(ply, caller)
  113. 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
  114.  
  115. umsg.Start("use_teleport_kekc", ply)
  116. umsg.Entity(ply)
  117. umsg.Entity(self)
  118. umsg.End()
  119. end
  120.  
  121. function ENT:SpawnFunction(ply, tr, name)
  122. if not tr.Hit then return end
  123.  
  124. local pos = tr.HitPos + tr.HitNormal * 32
  125.  
  126. local ent = ents.Create(name)
  127. ent:SetPos(pos)
  128. ent:Spawn()
  129. ent:Activate()
  130.  
  131. if IsValid(ent:GetPhysicsObject()) then ent:GetPhysicsObject():Wake() else return NULL end
  132.  
  133. self.owner = ply
  134.  
  135. return ent
  136. end
  137.  
  138. function ENT:OnRemove()
  139. table.RemoveByValue(TELEPORTS_TABLE_KEKC, self.teleport)
  140. end
  141.  
  142.  
  143. // CALLBACK FUNCTIONS
  144.  
  145. // Callback function creates a teleport
  146. local function CreateTeleport()
  147. local name = net.ReadString()
  148. local desc = net.ReadString()
  149. local ply = net.ReadEntity()
  150. local lab = net.ReadBit()
  151. local ent = net.ReadEntity()
  152.  
  153. ent.teleport = {}
  154. ent.teleport.name = name
  155. ent.teleport.entity = ent
  156. ent.teleport.private = util.tobool(lab)
  157. ent.teleport.desc = desc
  158. ent.teleport.owner = ply
  159.  
  160. table.insert(TELEPORTS_TABLE_KEKC, ent.teleport)
  161. end
  162. net.Receive("create_a_teleport", CreateTeleport)
  163.  
  164.  
  165. // Callback function teleports player
  166. local function TeleportPlayer()
  167. local ply = net.ReadEntity()
  168. local tp = net.ReadEntity()
  169.  
  170. if IsValid(ply) and ply:Alive() and IsValid(tp) and SERVER then
  171. if not tp.teleport.private then
  172. ply:SetPos(tp:GetPos())
  173. //ply:EmitSound("garrysmod/save_load" .. math.random(1, 4) .. ".wav")
  174. ply:EmitSound("hl1/ambience/particle_suck1.wav")
  175. ply:SetEyeAngles(Angle(0, tp:GetAngles().yaw, 0))
  176.  
  177. umsg.Start("effect_teleport_kekc")
  178. umsg.Entity(ply)
  179. umsg.End()
  180. else
  181. if ply != tp.teleport.owner then
  182. ply:ChatPrint("This teleport is private!")
  183. else
  184. ply:SetPos(tp:GetPos())
  185. //ply:EmitSound("garrysmod/save_load" .. math.random(1, 4) .. ".wav")
  186. ply:EmitSound("hl1/ambience/particle_suck1.wav")
  187. ply:SetEyeAngles(Angle(0, tp:GetAngles().yaw, 0))
  188.  
  189. umsg.Start("effect_teleport_kekc")
  190. umsg.Entity(ply)
  191. umsg.End()
  192. end
  193. end
  194. else
  195. ply:ChatPrint("This teleport is not valid or you're not alive")
  196. end
  197. end
  198. net.Receive("teleport_player_kekc", TeleportPlayer)
  199.  
  200.  
  201. // Callback function changes health on client
  202. local function ChangeHealth_cl()
  203. if SERVER then return end
  204.  
  205. local hp = net.ReadInt(32)
  206. local tp = net.ReadEntity()
  207.  
  208. tp.health = hp
  209. end
  210. net.Receive("teleport_change_health", ChangeHealth_cl)
  211.  
  212.  
  213. // Callback function opens the menu
  214. local function OpenTeleportMenu(data)
  215. if SERVER then return end
  216.  
  217. local ply = data:ReadEntity()
  218. local tp = data:ReadEntity()
  219.  
  220. if ply.Menu_teleports_kekc and IsValid(ply.Menu_teleports_kekc) then return end
  221.  
  222. ply.Menu_teleports_kekc = vgui.Create("DFrame")
  223.  
  224. local win = ply.Menu_teleports_kekc
  225. win:SetSize(600, 300)
  226. win:Center()
  227. win:SetTitle("Menu")
  228. win:MakePopup()
  229. win.Paint = function()
  230. if win and IsValid(win) then
  231. local w = win:GetWide()
  232. local h = win:GetTall()
  233.  
  234. draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 220))
  235. end
  236. end
  237.  
  238. local l = vgui.Create("DListView", win)
  239. l:SetSize(580, 260)
  240. l:SetPos(10, 30)
  241. l:AddColumn("Name")
  242. l:AddColumn("Owner")
  243. l:AddColumn("Description")
  244. l:AddColumn("Private")
  245. l:AddColumn("Distance")
  246. l.OnClickLine = function(parent, line, isselected)
  247. local entity = NULL
  248.  
  249. for k, v in pairs(TELEPORTS_TABLE_KEKC) do
  250. if v.name == line:GetValue(1) then
  251. entity = v.entity
  252. end
  253. end
  254.  
  255. if entity == tp then ply:ChatPrint("You can't teleport to youself!") return end
  256.  
  257. //now we teleports player
  258. net.Start("teleport_player_kekc")
  259. net.WriteEntity(ply)
  260. net.WriteEntity(entity)
  261. net.SendToServer()
  262.  
  263. if win and IsValid(win) then win:Close() end
  264. end
  265.  
  266. for k, v in pairs(TELEPORTS_TABLE_KEKC) do
  267. if v.entity == tp then continue end
  268.  
  269. local private = "<>"
  270. if v.private then private = "Yes" else private = "No" end
  271.  
  272. l:AddLine(v.name, v.owner:Nick(), v.desc, private, math.Round(tp:GetPos():Distance(v.entity:GetPos())))
  273. end
  274. end
  275. usermessage.Hook("use_teleport_kekc", OpenTeleportMenu)
  276.  
  277.  
  278. // Callback function opens the menu
  279. local function CreateEffect(data)
  280. if SERVER then return end
  281.  
  282. local bloom = 1
  283. local ply = data:ReadEntity()
  284.  
  285. hook.Add("RenderScreenspaceEffects", "stuff_storm_hp" .. ply:EntIndex(), function()
  286. if bloom <= 0 then hook.Remove("RenderScreenspaceEffects", "stuff_storm_hp" .. ply:EntIndex()) return end
  287.  
  288. bloom = bloom - 0.003
  289.  
  290. local tab = {}
  291. tab["$pp_colour_addr"] = 0
  292. tab["$pp_colour_addg"] = 0
  293. tab["$pp_colour_addb"] = 0
  294. tab["$pp_colour_brightness"] = bloom
  295. tab["$pp_colour_contrast"] = 1
  296. tab["$pp_colour_colour"] = 1
  297. tab["$pp_colour_mulr"] = 0
  298. tab["$pp_colour_mulg"] = 0
  299. tab["$pp_colour_mulb"] = 0
  300.  
  301. DrawColorModify(tab)
  302. end)
  303. end
  304. usermessage.Hook("effect_teleport_kekc", CreateEffect)
  305.  
  306.  
  307.  
  308. local function OpenMenu(data)
  309. if SERVER then return end
  310.  
  311. local ent = data:ReadEntity()
  312.  
  313. local win = vgui.Create("DFrame")
  314. win:SetSize(200, 130)
  315. win:Center()
  316. win:SetTitle("Options")
  317. win:ShowCloseButton(true)
  318. win:MakePopup()
  319. win.Paint = function()
  320. if win and win:IsActive() then
  321. local w = win:GetWide()
  322. local h = win:GetTall()
  323.  
  324. draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 220))
  325. end
  326. end
  327.  
  328. local name = vgui.Create("DTextEntry", win)
  329. name:SetPos(10, 30)
  330. name:SetSize(180, 20)
  331. name:SetText("Name")
  332.  
  333. local desc = vgui.Create("DTextEntry", win)
  334. desc:SetPos(10, 60)
  335. desc:SetSize(180, 20)
  336. desc:SetText("Description")
  337.  
  338. local ch = vgui.Create("DCheckBoxLabel", win)
  339. ch:SetPos(10, 80)
  340. ch:SetValue(0)
  341. ch:SetText("Private?")
  342. ch:SizeToContents()
  343.  
  344. local accept = vgui.Create("DButton", win)
  345. accept:SetPos(10, 100)
  346. accept:SetSize(180, 20)
  347. accept:SetText("Accept")
  348. accept.DoClick = function()
  349. if win and win:IsActive() then
  350. local n, d, p, c = name:GetValue(), desc:GetValue(), LocalPlayer(), ch:GetChecked()
  351. local close
  352.  
  353. if string.len(n) > 15 then p:ChatPrint("You have reached maximum symbols in Name text box!") return end
  354. if string.len(n) > 40 then p:ChatPrint("You have reached maximum symbols in Description text box!") return end
  355.  
  356. for k, v in pairs(TELEPORTS_TABLE_KEKC) do
  357. if v.name == n then close = true break end
  358. end
  359.  
  360. if close then p:ChatPrint("Teleport with " .. n .. " name is already exists!") return end
  361.  
  362. net.Start("create_a_teleport")
  363. net.WriteString(n)
  364. net.WriteString(d)
  365. net.WriteEntity(p)
  366. net.WriteBit(c)
  367. net.WriteEntity(ent)
  368. net.SendToServer()
  369.  
  370. ent.teleport = {}
  371. ent.teleport.name = n
  372. ent.teleport.entity = ent
  373. ent.teleport.private = c
  374. ent.teleport.desc = d
  375. ent.teleport.owner = p
  376.  
  377. win:Close()
  378. end
  379. end
  380. end
  381. usermessage.Hook("open_menu_kekc", OpenMenu)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement