Skip to content

Commit

Permalink
Merge pull request #158 from Shark-vil/dev
Browse files Browse the repository at this point in the history
1.12.0
  • Loading branch information
Shark-vil authored Dec 10, 2023
2 parents 07dcfa9 + 67a63b8 commit a5ce71d
Show file tree
Hide file tree
Showing 33 changed files with 564 additions and 188 deletions.
6 changes: 3 additions & 3 deletions lua/background_npcs_core/actions/sv_damage_reaction.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local bgNPC = bgNPC
local hook_Run = hook.Run
-- local hook_Run = hook.Run
--

hook.Add('BGN_PostReactionTakeDamage', 'BGN_ActorsReactionToDamageAnotherActor', function(attacker, target)
Expand All @@ -15,7 +15,7 @@ hook.Add('BGN_PostReactionTakeDamage', 'BGN_ActorsReactionToDamageAnotherActor',
if npc == target then continue end
if not bgNPC:IsTargetRay(npc, attacker) and not bgNPC:IsTargetRay(npc, target) then continue end

local hook_result = hook_Run('BGN_PreDamageToAnotherActor', actor, attacker, target, reaction)
local hook_result = hook.Run('BGN_PreDamageToAnotherActor', actor, attacker, target, reaction)
if hook_result then continue end

reaction = actor:GetLastReaction()
Expand All @@ -31,6 +31,6 @@ hook.Add('BGN_PostReactionTakeDamage', 'BGN_ActorsReactionToDamageAnotherActor',
actor:AddEnemy(enemy, reaction)
end

hook_Run('BGN_PostDamageToAnotherActor', actor, attacker, target, reaction)
hook.Run('BGN_PostDamageToAnotherActor', actor, attacker, target, reaction)
end
end)
14 changes: 7 additions & 7 deletions lua/background_npcs_core/actions/sv_self_damage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local bgNPC = bgNPC
local IsValid = IsValid
local isbool = isbool
local CurTime = CurTime
local hook_Run = hook.Run
-- local hook_Run = hook.Run
local table_WhereFindBySeq = table.WhereFindBySeq
local table_insert = table.insert
--
Expand All @@ -18,9 +18,9 @@ hook.Add('EntityTakeDamage', 'BGN_ActorTakeDamageEvent', function(target, dmginf
local result

if target:IsNPC() or target:IsNextBot() then
result = hook_Run('BGN_TakeDamageFromNPC', attacker, target, dmginfo)
result = hook.Run('BGN_TakeDamageFromNPC', attacker, target, dmginfo)
elseif target:IsPlayer() then
result = hook_Run('BGN_TakeDamageFromPlayer', attacker, target, dmginfo)
result = hook.Run('BGN_TakeDamageFromPlayer', attacker, target, dmginfo)
end

if isbool(result) then return result end
Expand Down Expand Up @@ -75,7 +75,7 @@ hook.Add('BGN_TakeDamageFromNPC', 'BGN_NPCDamageReaction', function(attacker, ta
local reaction = ActorTarget:GetReactionForDamage()
ActorTarget:SetReaction(reaction)

local hook_result = hook_Run('BGN_PreReactionTakeDamage', attacker, target, reaction, dmginfo)
local hook_result = hook.Run('BGN_PreReactionTakeDamage', attacker, target, reaction, dmginfo)
if isbool(hook_result) then return hook_result end

reaction = ActorTarget:GetLastReaction()
Expand All @@ -93,7 +93,7 @@ hook.Add('BGN_TakeDamageFromNPC', 'BGN_NPCDamageReaction', function(attacker, ta
end
end

return hook_Run('BGN_PostReactionTakeDamage', attacker, target, reaction, dmginfo)
return hook.Run('BGN_PostReactionTakeDamage', attacker, target, reaction, dmginfo)
end)

hook.Add('BGN_TakeDamageFromPlayer', 'BGN_PlayerDamageReaction', function(attacker, target, dmginfo)
Expand All @@ -106,8 +106,8 @@ hook.Add('BGN_TakeDamageFromPlayer', 'BGN_PlayerDamageReaction', function(attack
if not ActorAttacker:HasEnemy(target) then return end
end

local hook_result = hook_Run('BGN_PreReactionTakeDamage', attacker, target, dmginfo)
local hook_result = hook.Run('BGN_PreReactionTakeDamage', attacker, target, nil, dmginfo)
if isbool(hook_result) then return hook_result end

return hook_Run('BGN_PostReactionTakeDamage', attacker, target, dmginfo)
return hook.Run('BGN_PostReactionTakeDamage', attacker, target, nil, dmginfo)
end)
4 changes: 2 additions & 2 deletions lua/background_npcs_core/classes/actor/sh_actor_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1596,9 +1596,9 @@ end

function BaseClass:InVehicle()
if SERVER then
return ( self.vehicle and IsValid(self.vehicle) ) == true
return IsValid(self.vehicle)
else
return self.npc:slibGetVar('bgn_vehicle_entered', false)
return IsValid(self.npc) and self.npc:slibGetVar('bgn_vehicle_entered', false)
end
end

Expand Down
49 changes: 28 additions & 21 deletions lua/background_npcs_core/classes/actor/sh_actor_class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ function BGN_ACTOR:Instance(npc, npc_type, custom_uid, not_sync_actor_on_client,
end

npc.isBgnActor = true
-- npc:SetNWBool('IS_BGN_ACTOR', true)
-- npc:SetNWString('BGB_ACTOR_TYPE', npc_type)
-- npc:SetNWString('BGB_ACTOR_UID', obj.uid)
-- npc:SetNWString('BGN_ACTOR_INFO', util.Compress(snet.Serialize(obj.info)))

if obj.mechanics.inpc_ignore then
-- ------------------------------------------------------------------
Expand All @@ -173,31 +177,34 @@ function BGN_ACTOR:Instance(npc, npc_type, custom_uid, not_sync_actor_on_client,
npc:CapabilitiesAdd(CAP_DUCK + CAP_MOVE_SHOOT + CAP_USE + CAP_AUTO_DOORS + CAP_OPEN_DOORS + CAP_TURN_HEAD + CAP_SQUAD + CAP_AIM_GUN)
end

if SERVER and not not_sync_actor_on_client then
snet_Request('bgn_add_actor_from_client', npc, npc_type, obj.uid, obj.info).InvokeAll()
end
timer_Simple(0, function()
if not IsValid(npc) then return end

if not not_auto_added_to_list then
bgNPC:AddNPC(obj)
end
if SERVER then
obj:DropToFloor()
obj:CreateFakePlayerMethodsForNPC()

if npc_data.start_random_state or npc_data.start_state then
timer_Simple(1, function()
if not obj:IsAlive() then return end
if npc_data.start_random_state then
obj:RandomState()
elseif npc_data.start_state then
obj:SetState(npc_data.start_state)
end
end)
end
end

hook_Run('BGN_InitActor', obj)
if SERVER and not not_sync_actor_on_client then
snet_Request('bgn_add_actor_from_client', npc, npc_type, obj.uid, obj.info).InvokeAll()
end

timer_Simple(0, function()
if not IsValid(npc) then return end
obj:DropToFloor()
obj:CreateFakePlayerMethodsForNPC()

if npc_data.start_random_state or npc_data.start_state then
timer_Simple(1, function()
if not obj:IsAlive() then return end
if npc_data.start_random_state then
obj:RandomState()
elseif npc_data.start_state then
obj:SetState(npc_data.start_state)
end
end)
if not not_auto_added_to_list then
bgNPC:AddNPC(obj)
end

hook_Run('BGN_InitActor', obj)
end)

return obj
Expand Down
2 changes: 1 addition & 1 deletion lua/background_npcs_core/commands/sh_cmd_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end).AutoComplete(function(cmd)
return actors_type_list
end).Access( { isAdmin = true } ).Register()

scommand.Create('bgn_print_spawned_actors_count').OnClient(function(_, _, args)
scommand.Create('bgn_print_spawned_actors_count').OnShared(function(_, _, args)
print(bgNPC:Count(args[1]))
end).AutoComplete(function(cmd)
local actors_type_list = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local name = slib.language({
['default'] = 'Сivil Defense (NOT WANTED MODE)',
['russian'] = 'Гражданская оборона (БЕЗ РЕЖИМА РОЗЫСКА)'
})

bgNPC.cfg:SetActor('civil_defense_nwm', {
enabled = false,
inherit = 'police',
class = 'npc_metropolice',
name = name,
respawn_delay = 5,
fullness = 5,
weapons = { 'weapon_smg1' },
health = { 60, 70 },
weapon_skill = WEAPON_PROFICIENCY_GOOD,
money = { 0, 200 },
at_random = { ['walk'] = 100 },
at_damage_range = 100,
at_damage = { ['defense'] = 100 },
at_protect_range = 100,
at_protect = { ['defense'] = 100 },
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
local name = slib.language({
['default'] = 'Assault Helicopter (NOT WANTED MODE)',
['russian'] = 'Штурмовой вертолет (БЕЗ РЕЖИМА РОЗЫСКА)'
})

bgNPC.cfg:SetActor('police_helicopter_nwm', {
enabled = false,
class = 'npc_apache_scp_sb',
name = name,
disable_states = true,
respawn_delay = 15,
limit = 1,
team = { 'residents', 'police' },
money = { 0, 500 },
at_damage_range = 100,
at_damage = { ['defense'] = 100 },
at_protect_range = 100,
at_protect = { ['defense'] = 100 },
validator = function(self, npc_type)
if not list.Get('NPC')[self.class] then
return false
end
end,
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local name = slib.language({
['default'] = 'Special Forces (NOT WANTED MODE)',
['russian'] = 'Спецназ (БЕЗ РЕЖИМА РОЗЫСКА)'
})

bgNPC.cfg:SetActor('special_forces_nwm', {
enabled = false,
inherit = 'civil_defense',
class = 'npc_combine_s',
name = name,
respawn_delay = 15,
fullness = 5,
weapons = { 'weapon_ar2' },
health = { 80, 90 },
weapon_skill = WEAPON_PROFICIENCY_VERY_GOOD,
max_vehicle = 1,
vehicles = { 'sim_fphys_conscriptapc' },
random_skin = true,
random_bodygroups = true,
default_models = false,
models = { 'models/armored_elite/armored_elite_npc.mdl' },
money = { 0, 250 },
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local name = slib.language({
['default'] = 'Reinforced Special Forces (NOT WANTED MODE)',
['russian'] = 'Усиленный спецназ (БЕЗ РЕЖИМА РОЗЫСКА)'
})

bgNPC.cfg:SetActor('special_forces_2_nwm', {
enabled = false,
inherit = 'special_forces',
class = 'npc_combine_s',
name = name,
respawn_delay = 15,
fullness = 2,
weapons = { 'weapon_shotgun' },
health = { 100, 110 },
weapon_skill = WEAPON_PROFICIENCY_PERFECT,
money = { 0, 300 },
})
10 changes: 10 additions & 0 deletions lua/background_npcs_core/cvars/sh_cvars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ bgNPC.cvar.bgn_drop_money = 1
bgNPC.cvar.bgn_module_n2money = 1
bgNPC.cvar.bgn_chunk_system = 1
bgNPC.cvar.bgn_chunk_size = 5000
bgNPC.cvar.bgn_agressive_mode = 0
bgNPC.cvar.bgn_friend_mode = 0

function bgNPC:IsActiveNPCType(npc_type)
local cvar = GetConVar('bgn_npc_type_' .. npc_type)
Expand Down Expand Up @@ -110,6 +112,14 @@ scvar.Register('bgn_enable', bgNPC.cvar.bgn_enable,
FCVAR_ARCHIVE, 'Toggles the modification activity. 1 - enabled, 0 - disabled.')
.Access(DefaultAccess)

scvar.Register('bgn_agressive_mode', bgNPC.cvar.bgn_agressive_mode,
FCVAR_ARCHIVE, 'All actors will be hostile towards you.')
.Access(DefaultAccess)

scvar.Register('bgn_friend_mode', bgNPC.cvar.bgn_friend_mode,
FCVAR_ARCHIVE, 'All actors will be friendly towards you.')
.Access(DefaultAccess)

scvar.Register('bgn_chunk_system', bgNPC.cvar.bgn_chunk_system,
FCVAR_ARCHIVE, '1 - enabled, 0 - disabled.')
.Access(DefaultAccess)
Expand Down
19 changes: 19 additions & 0 deletions lua/background_npcs_core/global/sh_actors_register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local CLIENT = CLIENT
local table = table
local pairs = pairs
local IsValid = IsValid
-- local ents_GetAll = ents.GetAll
--

if CLIENT then
Expand All @@ -11,6 +12,24 @@ if CLIENT then
bgNPC:ClearRemovedNPCs()
end).Register()

-- timer.Create('bgn_client_async_actors', 1, 9, function()
-- local entities = ents_GetAll()

-- for i = 1, #entities do
-- local ent = entities[i]
-- if IsValid(ent) and ent:GetNWBool('IS_BGN_ACTOR', false) and not bgNPC:IsActor(ent) then
-- local npc_type = ent:GetNWString('BGB_ACTOR_TYPE', nil)
-- local uid = ent:GetNWString('BGB_ACTOR_UID', nil)
-- local info = ent:GetNWString('BGN_ACTOR_INFO', nil)
-- if not npc_type or not uid or not info then continue end
-- local actor = BGN_ACTOR:Instance(ent, npc_type, uid)
-- if info then
-- actor.info = snet.Deserialize(util.Decompress(info))
-- end
-- end
-- end
-- end)

snet.Callback('bgn_add_actor_from_client', function(ply, npc, npc_type, uid, info)
if bgNPC:GetActor(npc) ~= nil then return end
local actor = BGN_ACTOR:Instance(npc, npc_type, uid)
Expand Down
Loading

0 comments on commit a5ce71d

Please sign in to comment.