Skip to content

Commit

Permalink
Add a few more schedules that the player can interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
ZehMatt committed Mar 23, 2024
1 parent 49e857c commit efce2c5
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions gamemode/sv_taunts.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
AddCSLuaFile("cl_taunts.lua")
include("sh_taunts.lua")
util.AddNetworkString("PlayerStartTaunt")

local COMMANDABLE_CLASSES = {
["npc_citizen"] = true
}

local function CanInterruptSchedule(sched)
if sched == SCHED_NONE then return true end
if sched == SCHED_IDLE_STAND then return true end
if sched == SCHED_ALERT_STAND then return true end
if sched == SCHED_ALERT_FACE then return true end
if sched == SCHED_MOVE_AWAY then return true end
if sched == SCHED_ALERT_REACT_TO_COMBAT_SOUND then return true end

return false
end

local function GetNearbyAllies(ply)
local playerPos = ply:GetPos()
local boxMins = Vector(600, 600, 100)
local boxMaxs = Vector(600, 600, 100)
local nearbyEnts = ents.FindInBox(playerPos - boxMins, playerPos + boxMaxs)
local res = {}

for _, v in pairs(nearbyEnts) do
if COMMANDABLE_CLASSES[v:GetClass()] ~= true then continue end
if v:IsNPC() == false then continue end
Expand All @@ -21,7 +30,11 @@ local function GetNearbyAllies(ply)
if v:HasSpawnFlags(SF_CITIZEN_NOT_COMMANDABLE) == true then continue end
if v:Disposition(ply) ~= D_LI then continue end
local sched = v:GetCurrentSchedule()
if sched ~= SCHED_IDLE_STAND and sched ~= SCHED_ALERT_STAND then continue end
if CanInterruptSchedule(sched) == false then
print("NPC is not idle", v, sched)
continue
end

table.insert(res, v)
end

Expand All @@ -31,7 +44,6 @@ end
local function CommandAlliesToAttack(ply, target)
if IsFriendEntityName(target:GetClass()) == false then return end
local allies = GetNearbyAllies(ply)

for _, v in pairs(allies) do
v:SetEnemy(target)
v:UpdateEnemyMemory(target, target:GetPos())
Expand All @@ -40,7 +52,6 @@ end

local function CommandAlliesToPosition(ply, pos)
local allies = GetNearbyAllies(ply)

for _, v in pairs(allies) do
v:ClearSchedule()
v:SetLastPosition(pos)
Expand All @@ -53,13 +64,11 @@ local function PlaceRunPointer(ply)
local playerPos = ply:EyePos()
local tracelen = traceang:Forward() * 10000
local filter = {ply}

if ply:InVehicle() then
table.insert(filter, ply:GetVehicle())
end

local trace = util.QuickTrace(playerPos, tracelen, filter)

if trace.HitWorld or (IsValid(trace.Entity) and not trace.Entity:IsNPC()) then
local effectdata = EffectData()
effectdata:SetOrigin(trace.HitPos)
Expand All @@ -76,7 +85,6 @@ local function PlaceRunPointer(ply)
elseif IsValid(trace.Entity) and trace.Entity:IsNPC() then
local npc = trace.Entity
local isFriendly = IsFriendEntityName(npc:GetClass())

if isFriendly == false then
CommandAlliesToAttack(ply, npc)
end
Expand All @@ -96,15 +104,13 @@ function GM:PlayPlayerTaunt(ply, category, tauntIndex)
if ply:Alive() == false then return end
local mdlCategory = ply:GetModelCategory()
local categoryId = category

if not isnumber(categoryId) then
categoryId = self:GetTauntCategoryId(category)
end

local taunts = self:GetTaunts(categoryId, mdlCategory)
local taunt = taunts[tauntIndex]
local snd = table.Random(taunt.Sounds)

if taunt.Name == "Over here" then
ply:SendLua[[RunConsoleCommand("act", "wave")]]
PlaceRunPointerLocal(ply)
Expand All @@ -122,8 +128,11 @@ function GM:PlayPlayerTaunt(ply, category, tauntIndex)
ply:EmitSound(snd)
end

net.Receive("PlayerStartTaunt", function(len, ply)
local categoryId = net.ReadInt(16)
local tauntIndex = net.ReadInt(16)
GAMEMODE:PlayPlayerTaunt(ply, categoryId, tauntIndex)
end)
net.Receive(
"PlayerStartTaunt",
function(len, ply)
local categoryId = net.ReadInt(16)
local tauntIndex = net.ReadInt(16)
GAMEMODE:PlayPlayerTaunt(ply, categoryId, tauntIndex)
end
)

0 comments on commit efce2c5

Please sign in to comment.