Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile()
- ENT.Type = "anim"
- ENT.Base = "base_anim"
- ENT.Spawnable = true
- ENT.PrintName = "Teleporter"
- ENT.Category = "TELEPORTERS"
- local teleport = {}
- ENT.health = 100
- if SERVER then
- util.AddNetworkString("create_a_teleport")
- util.AddNetworkString("teleport_player_kekc")
- util.AddNetworkString("teleport_change_health")
- CreateConVar("tps_kekc_enable", 1)
- CreateConVar("tps_kekc_enablehp", 1)
- else
- surface.CreateFont("teleporters_font1", {
- font = "Segoe UI",
- size = 1000,
- weight = 0,
- blursize = 0,
- scanlines = 0,
- antialias = true,
- underline = false,
- italic = false,
- strikeout = false,
- symbol = false,
- rotary = false,
- shadow = false,
- additive = false,
- outline = false,
- })
- end
- function ENT:Draw()
- if SERVER then return end
- self:DrawModel()
- if not self.infotbl_tp then
- self.infotbl_tp = {}
- self.infotbl_tp.name = "<>"
- self.infotbl_tp.desc = "<>"
- self.infotbl_tp.priviate = false
- self.infotbl_tp.owner = "<>"
- end
- //if teleport_name then
- local private = "<>"
- if teleport_private then private = "Yes" else private = "No" end
- cam.Start3D2D(self:GetPos() + Vector(0, 0, 70), Angle(0, CurTime() * 60, 90), 0.1)
- draw.DrawText("Name: " .. self.infotbl_tp.name, "teleporters_font1", 0, 0, Color(255, 255, 255), TEXT_ALIGN_CENTER)
- draw.DrawText("Owner: " .. self.infotbl_tp.owner, "teleporters_font1", 0, 80, Color(255, 255, 255), TEXT_ALIGN_CENTER)
- draw.DrawText(self.infotbl_tp.desc, "teleporters_font1", 0, 160, Color(255, 255, 255), TEXT_ALIGN_CENTER)
- draw.DrawText("Private: " .. private, "teleporters_font1", 0, 240, Color(255, 255, 255), TEXT_ALIGN_CENTER)
- 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
- cam.End3D2D()
- cam.Start3D2D(self:GetPos() + Vector(0, 0, 70), Angle(0, 180 + CurTime() * 60, 90), 0.1)
- draw.DrawText("Name: " .. self.infotbl_tp.name, "teleporters_font1", 0, 0, Color(255, 255, 255), TEXT_ALIGN_CENTER)
- draw.DrawText("Owner: " .. self.infotbl_tp.owner, "teleporters_font1", 0, 80, Color(255, 255, 255), TEXT_ALIGN_CENTER)
- draw.DrawText(self.infotbl_tp.desc, "teleporters_font1", 0, 160, Color(255, 255, 255), TEXT_ALIGN_CENTER)
- draw.DrawText("Private: " .. private, "teleporters_font1", 0, 240, Color(255, 255, 255), TEXT_ALIGN_CENTER)
- 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
- cam.End3D2D()
- //end
- end
- function ENT:OnTakeDamage(dmg)
- if CLIENT then return end
- if not GetConVar("tps_kekc_enablehp"):GetBool() then return end
- self.health = math.Round(self.health - dmg:GetDamage() / 10)
- if self.health <= 0 then
- self:EmitSound("phx/explode00.wav", 400, 100)
- local ef = EffectData()
- ef:SetOrigin(self:GetPos())
- util.Effect("Explosion", ef)
- self:Remove()
- return
- end
- net.Start("teleport_change_health")
- net.WriteInt(self.health, 32)
- net.WriteEntity(self)
- net.Broadcast()
- end
- function ENT:Initialize()
- if CLIENT then
- return
- end
- self:SetModel("models/props_lab/teleplatform.mdl")
- self:SetMoveType(MOVETYPE_VPHYSICS)
- self:SetSolid(SOLID_VPHYSICS)
- self:PhysicsInit(SOLID_VPHYSICS)
- end
- function ENT:PhysicsCollide(data, physobj)
- if CLIENT then return end
- end
- local next_use = 0
- function ENT:Use(ply, caller)
- 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
- umsg.Start("use_teleport_kekc", ply)
- umsg.Entity(ply)
- umsg.Entity(self)
- umsg.End()
- end
- function ENT:SpawnFunction(ply, tr, name)
- if not tr.Hit then return end
- local pos = tr.HitPos + tr.HitNormal * 32
- local ent = ents.Create(name)
- ent:SetPos(pos)
- ent:Spawn()
- ent:Activate()
- if IsValid(ent:GetPhysicsObject()) then ent:GetPhysicsObject():Wake() else return NULL end
- timer.Simple(0.3, function()
- if not IsValid(ply) or not IsValid(ent) then return end
- umsg.Start("open_menu_kekc", ply)
- umsg.Entity(ent)
- umsg.End()
- end)
- return ent
- end
- function ENT:OnRemove()
- table.RemoveByValue(TELEPORTS_TABLE_KEKC, self.teleport)
- end
- // CALLBACK FUNCTIONS
- // Callback function creates a teleport
- local function CreateTeleport()
- local name = net.ReadString()
- local desc = net.ReadString()
- local ply = net.ReadEntity()
- local lab = net.ReadBit()
- local ent = net.ReadEntity()
- ent.teleport = {}
- ent.teleport.name = name
- ent.teleport.entity = ent
- ent.teleport.private = util.tobool(lab)
- ent.teleport.desc = desc
- ent.teleport.owner = ply
- ent:SetNWString("teleport_name", name)
- ent:SetNWBool("teleport_private", util.tobool(lab))
- ent:SetNWString("teleport_desc", desc)
- ent:SetNWEntity("teleport_owner", ply)
- umsg.Start("change_settings_cl")
- umsg.Entity(ent)
- umsg.End()
- table.insert(TELEPORTS_TABLE_KEKC, ent.teleport)
- end
- net.Receive("create_a_teleport", CreateTeleport)
- // Callback function teleports player
- local function TeleportPlayer()
- local ply = net.ReadEntity()
- local tp = net.ReadEntity()
- if IsValid(ply) and ply:Alive() and IsValid(tp) and SERVER then
- if not tp.teleport.private then
- ply:SetPos(tp:GetPos())
- //ply:EmitSound("garrysmod/save_load" .. math.random(1, 4) .. ".wav")
- ply:EmitSound("hl1/ambience/particle_suck1.wav")
- ply:SetEyeAngles(Angle(0, tp:GetAngles().yaw, 0))
- umsg.Start("effect_teleport_kekc")
- umsg.Entity(ply)
- umsg.End()
- else
- if ply != tp.teleport.owner then
- ply:ChatPrint("This teleport is private!")
- else
- ply:SetPos(tp:GetPos())
- //ply:EmitSound("garrysmod/save_load" .. math.random(1, 4) .. ".wav")
- ply:EmitSound("hl1/ambience/particle_suck1.wav")
- ply:SetEyeAngles(Angle(0, tp:GetAngles().yaw, 0))
- umsg.Start("effect_teleport_kekc")
- umsg.Entity(ply)
- umsg.End()
- end
- end
- else
- ply:ChatPrint("This teleport is not valid or you're not alive")
- end
- end
- net.Receive("teleport_player_kekc", TeleportPlayer)
- // Callback function changes health on client
- local function ChangeHealth_cl()
- if SERVER then return end
- local hp = net.ReadInt(32)
- local tp = net.ReadEntity()
- tp.health = hp
- end
- net.Receive("teleport_change_health", ChangeHealth_cl)
- // Callback function opens the menu
- local function OpenTeleportMenu(data)
- if SERVER then return end
- local ply = data:ReadEntity()
- local tp = data:ReadEntity()
- if ply.Menu_teleports_kekc and IsValid(ply.Menu_teleports_kekc) then return end
- ply.Menu_teleports_kekc = vgui.Create("DFrame")
- local win = ply.Menu_teleports_kekc
- win:SetSize(600, 300)
- win:Center()
- win:SetTitle("Menu")
- win:MakePopup()
- win.Paint = function()
- if win and IsValid(win) then
- local w = win:GetWide()
- local h = win:GetTall()
- draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 220))
- end
- end
- local l = vgui.Create("DListView", win)
- l:SetSize(580, 260)
- l:SetPos(10, 30)
- l:AddColumn("Name")
- l:AddColumn("Owner")
- l:AddColumn("Description")
- l:AddColumn("Private")
- l:AddColumn("Distance")
- l.OnClickLine = function(parent, line, isselected)
- local entity = NULL
- for k, v in pairs(TELEPORTS_TABLE_KEKC) do
- if v.name == line:GetValue(1) then
- entity = v.entity
- end
- end
- if entity == tp then ply:ChatPrint("You can't teleport to youself!") return end
- //now we teleports player
- net.Start("teleport_player_kekc")
- net.WriteEntity(ply)
- net.WriteEntity(entity)
- net.SendToServer()
- if win and IsValid(win) then win:Close() end
- end
- for k, v in pairs(TELEPORTS_TABLE_KEKC) do
- if v.entity == tp then continue end
- local private = "<>"
- if v.private then private = "Yes" else private = "No" end
- l:AddLine(v.name, v.owner:Nick(), v.desc, private, math.Round(tp:GetPos():Distance(v.entity:GetPos())))
- end
- end
- usermessage.Hook("use_teleport_kekc", OpenTeleportMenu)
- // Callback function opens the menu
- local function CreateEffect(data)
- if SERVER then return end
- local bloom = 1
- local ply = data:ReadEntity()
- hook.Add("RenderScreenspaceEffects", "stuff_storm_hp" .. ply:EntIndex(), function()
- if bloom <= 0 then hook.Remove("RenderScreenspaceEffects", "stuff_storm_hp" .. ply:EntIndex()) return end
- bloom = bloom - 0.003
- local tab = {}
- tab["$pp_colour_addr"] = 0
- tab["$pp_colour_addg"] = 0
- tab["$pp_colour_addb"] = 0
- tab["$pp_colour_brightness"] = bloom
- tab["$pp_colour_contrast"] = 1
- tab["$pp_colour_colour"] = 1
- tab["$pp_colour_mulr"] = 0
- tab["$pp_colour_mulg"] = 0
- tab["$pp_colour_mulb"] = 0
- DrawColorModify(tab)
- end)
- end
- usermessage.Hook("effect_teleport_kekc", CreateEffect)
- local function OpenMenu(data)
- if SERVER then return end
- local self = data:ReadEntity()
- local win = vgui.Create("DFrame")
- win:SetSize(200, 130)
- win:Center()
- win:SetTitle("Options")
- win:ShowCloseButton(true)
- win:MakePopup()
- win.Paint = function()
- if win and win:IsActive() then
- local w = win:GetWide()
- local h = win:GetTall()
- draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 220))
- end
- end
- local name = vgui.Create("DTextEntry", win)
- name:SetPos(10, 30)
- name:SetSize(180, 20)
- name:SetText("Name")
- local desc = vgui.Create("DTextEntry", win)
- desc:SetPos(10, 60)
- desc:SetSize(180, 20)
- desc:SetText("Description")
- local ch = vgui.Create("DCheckBoxLabel", win)
- ch:SetPos(10, 80)
- ch:SetValue(0)
- ch:SetText("Private?")
- ch:SizeToContents()
- local accept = vgui.Create("DButton", win)
- accept:SetPos(10, 100)
- accept:SetSize(180, 20)
- accept:SetText("Accept")
- accept.DoClick = function()
- if win and win:IsActive() then
- local n, d, p, c = name:GetValue(), desc:GetValue(), LocalPlayer(), ch:GetChecked()
- local close
- if string.len(n) > 15 then p:ChatPrint("You have reached maximum symbols in Name text box!") return end
- if string.len(n) > 40 then p:ChatPrint("You have reached maximum symbols in Description text box!") return end
- for k, v in pairs(TELEPORTS_TABLE_KEKC) do
- if v.name == n then close = true break end
- end
- if close then p:ChatPrint("Teleport with " .. n .. " name is already exists!") return end
- net.Start("create_a_teleport")
- net.WriteString(n)
- net.WriteString(d)
- net.WriteEntity(p)
- net.WriteBit(c)
- net.WriteEntity(self)
- net.SendToServer()
- win:Close()
- end
- end
- end
- usermessage.Hook("open_menu_kekc", OpenMenu)
- local function CreateClientSetts(data)
- if SERVER then return end
- local ent = data:ReadEntity()
- self.infotbl_tp.name = ent:GetNWString("teleport_name")
- self.infotbl_tp.private = ent:GetNWBool("teleport_private")
- self.infotbl_tp.owner = ent:GetNWEntity("teleport_owner"):Nick()
- self.infotbl_tp.desc = ent:GetNWString("teleport_desc")
- end
- usermessage.Hook("change_settings_cl", CreateClientSetts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement