February 5

Примеры кода на glua для garrys mod

Пример 1:

local TEMP_NPC_Victims = {
    ["npc_vj_zend_guard"] = "npc_vj_Security",
    ["npc_alyx"] = "npc_zombie_alyx",
    [""] = "",
    ["npc_kleiner"] = "npc_14d_hunter"
}

hook.Add("OnNPCKilled", "InfectionNPCKilled", function(NPC, ATT, INF)
    if isstring(TEMP_NPC_Victims[NPC:GetClass()]) then
        local TEMP_MDL = NPC:GetModel()
        local TEMP_POS = NPC:GetPos()
        local TEMP_ANG = NPC:GetAngles()
        local TEMP_CLS = TEMP_NPC_Victims[NPC:GetClass()]

        print("МЕСТО ДЛЯ ПАРТИКЛА")

        timer.Create("INFECTION_CREATE_ZOMBIE_NPC_" .. tostring(NPC),  10,  1, function()
            local TEMP_Victim = ents.Create(TEMP_CLS)
            TEMP_Victim:SetModel(TEMP_MDL)
            TEMP_Victim:SetPos(TEMP_POS)
            TEMP_Victim:SetAngles(TEMP_ANG)
            TEMP_Victim:Spawn()
        end)
    end
end)

Пример 2:

hook.Add("OnNPCKilled", "Dying_Light_Mutant_Level_Up_numberi", function(DEAD_NPC, Entity_Attacker, Entity_Inflictor)
    if IsValid(Entity_Attacker) and DEAD_NPC:IsNPC() and Entity_Attacker ~= NULL then
        if Entity_Attacker:GetClass() == "npc_vj_dyinglight_toxicbiter" then
            Entity_Attacker.VAR_Points = Entity_Attacker.VAR_Points + 1
            if Entity_Attacker.VAR_Points > 3 then
                Entity_Attacker.VAR_Points = -999999

                timer.Create("DL_Biter_Upgrade_1_" .. tostring(Entity_Attacker), 30, 1, function()
                    if IsValid(Entity_Attacker) and Entity_Attacker ~= NULL then
                        Entity_Attacker:SetHealth(Entity_Attacker:Health() + 60)
                        Entity_Attacker:VJ_ACT_PLAYACTIVITY("Cower", true, 2, false)

                        timer.Create("DL_Biter_Upgrade_2_" .. tostring(Entity_Attacker), 3, 1, function()
                            if IsValid(Entity_Attacker) and Entity_Attacker ~= NULL then
                                local ReincarnationMonster = ents.Create("npc_vj_14d_com_m_soldier")
                                ReincarnationMonster:SetModel(Entity_Attacker:GetModel())
                                ReincarnationMonster:SetPos(Entity_Attacker:GetPos())
                                ReincarnationMonster:SetAngles(Entity_Attacker:GetAngles())
                                -- ReincarnationMonster:SetColor(Color(242,162,162))
                                ReincarnationMonster:Spawn()
                                ReincarnationMonster:VJ_ACT_PLAYACTIVITY("attackdoor_01", true, 3, false)
                                Entity_Attacker:Remove()
                            end
                        end)
                    end
                end)
            end
        end
    end
end)