Skip to content

republic-community/background-citizens

 
 

Repository files navigation

Background NPCs

gLua Workshop Subscribers Favorite Open source Documentation

WARNING

BE SURE TO SUBSCRIBE TO THE LIBRARY SLibrary:

General


Short information

This is an addon that will automatically spawn NPCs on the map at predetermined movement points. NPCs can walk around the map, perform random actions, attack or defend.

Performance

The system is quite optimized and almost does not load the system. NPCs are removed when they disappear from the player's field of view, and appear with a certain delay. The spawn process is performed between server frames, which does not create unnecessary lags.

Assignment

This addon can rather be considered a base for development. There is basic functionality here, but if you are a developer, you can fairly easily extend the system to suit your conditions and for any gamemode.

F.A.Q.


Documentation


Warning

The wiki is currently under development and some methods may not be described. When the wiki is complete, this warning will be removed.

Simple code example:

-- The hook is called when the NPC is looking at an object.
-- In this example, the police give the player 2 warnings with animation, and then push him away.
hook.Add("BGN_NPCLookAtObject", "BGN_PoliceWarnAndPushPlayerIfHeIsClose", function(actor, ent)
    if ent:IsPlayer() and actor:GetType() == 'police'
        and actor:GetState() == 'walk'
        and actor:IsSequenceFinished()
    then
        if ent:GetPos():DistToSqr(actor:GetNPC():GetPos()) > 50 ^ 2 then return end

        -- Get temporary table of state data
        local data = actor:GetStateData()
        -- Add a variable to the temporary state table, if it does not exist
        data.LuggageWarn = data.LuggageWarn or 0

        if data.LuggageWarn < 2 then
            -- Play warn animation
            actor:PlayStaticSequence('LuggageWarn')
            data.LuggageWarn = data.LuggageWarn + 1
        else
            -- Play push animation
            actor:PlayStaticSequence('LuggagePush')

            -- A local function that pushes the player away from the entity
            TargetPlayerPush(actor:GetNPC(), ent, 250)

            data.LuggageWarn = 0
        end
    end
end)

NPCs do not have extra code and overloaded tables. For each background NPC an "Actor" class is created, through which most actions are carried out. This makes the code cleaner.

Performance testing

During testing, we used the factory settings of cvars.

Local Server

Disable Background NPCs

Disable Background NPCs

Enable Background NPCs

Enable Background NPCs

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Lua 100.0%