Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ZKEntSpawnF4 = ZKEntSpawnF4 or {}
- ZKEntSpawnF4.config = ZKEntSpawnF4.config or {}
- ZKEntSpawnF4.config.EntityOwners = {}
- ZKEntSpawnF4.config.Entities = {}
- ZKEntSpawnF4.config.OwnerIndex = 1
- function GetPlyEyeTracer(ply)
- local pos = ply:GetEyeTrace().HitPos -- Vector of Where the Player is Looking.
- if (pos == nil) then return nil end
- local Distance = (ply:GetPos()):Distance(pos) -- Get the Distance from player's position to tracer position.
- -- If looking too far, return function --> unable to spawn
- if (Distance > 500) then
- ServerLog("[ZES]: Error, " .. ply:Nick() .. " Has tried to Spawn too far.".."\n")
- return nil
- end
- -- If looking too close, return function --> unable to spawn (Due to Spawn Kill)
- if (Distance < 120) then
- ServerLog("[ZES]: Error, " .. ply:Nick() .. " Has tried to Spawn too close.".."\n")
- return nil
- end
- return pos
- end
- --[[--------------------
- Test
- ----------------------]]
- DarkRP.createEntity("Test", {
- ent = "Entity",
- model = "model.mdl",
- price = 0,
- max = 1,
- cmd = "cmds",
- category = "Entities",
- allowed = {TEAM_TEST},
- customCheck = function(ply) return
- table.HasValue({TEAM_TEST}, ply:Team())
- end,
- CustomCheckFailMsg = "You must be a TEST.",
- spawn = function(ply, tr, tblEnt)
- local curEnt = ents.Create("Entity")
- curEnt:SetModel("model.mdl")
- local posPly = GetPlyEyeTracer(ply)
- local safeRange = Vector(200,200,70)
- if (posPly == nil) then
- posPly = ply:GetPos() + safeRange
- end
- curEnt:SetPos(posPly + Vector(0,0,50))
- curEnt:Spawn()
- curEnt:SetOwner(ply)
- ZKEntSpawnF4.config.EntityOwners[ZKEntSpawnF4.config.OwnerIndex] = curEnt:GetOwner() -- Log the Owner
- ZKEntSpawnF4.config.Entities[ZKEntSpawnF4.config.OwnerIndex] = curEnt -- Log the Entity with same Index
- ZKEntSpawnF4.config.OwnerIndex = ZKEntSpawnF4.config.OwnerIndex + 1
- return curEnt
- end,
- })
- hook.Add("PlayerDeath", "ZK_OnPlayerDeath", function(vic, inf, at) -- Remove Entity on Death
- if (table.HasValue(ZKEntSpawnF4.config.EntityOwners, vic)) then -- If the player that died is an Owner of an Entity
- for k, v in pairs(ZKEntSpawnF4.config.EntityOwners) do
- if (v == vic) then -- Check for more entities this player has
- local zEnt = ZKEntSpawnF4.config.Entities[k] -- Get the entity with the same index.
- if (IsValid(zEnt)) then -- If the entity is Valid
- zEnt:Remove() -- Remove the entity
- end
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement