LeadKiller / leadbot

🤖Player AI Bots to revive obscure gamemodes in Garry's Mod🤖
63 stars 14 forks source link

Weapon Priority System #3

Open LeadKiller opened 4 years ago

LeadKiller commented 4 years ago

Currently, the bot relies on either the gamemode or bot code to switch weapons.

Weapon Priority would allow users to add weapons to the gamemode configuration, allowing users to define if weapons are projectile, melee or hitscan (possibly categories such as sniper and smg?) and their priority for pickup.

The bot would be able to switch between weapons depending on which is stronger (set by pickup priority), and if needed, switch weapons depending on the situation.

Melee weapons may have an issue where the draw animation disallows the bot to switch back to their previous weapon and primary attack. To fix this, the bot could have a delay before switching back.

Bots would also be able to pick up weapons in gamemodes that have weapon pickups (if the weapon is stronger than their current one), such as Quake III and other deathmatch gamemodes.

unknown-gd commented 4 years ago

I make it ^-^


    local selectWeap = "hands"
    local range = 160000
    local WepList0 = {
        "weapon_bugbait",
        "weapon_crwbr",
        "weapon_fists",
        "weapon_crowbar",
        "weapon_stunstick",
        "weapon_slapstick",
        "weapon_longbar"
    }
    local WepList1 = {
        "weapon_parkinsons",
        "weapon_spraynpray",
        "weapon_pistol",
        "weapon_357",
        "weapon_smg1",
        "weapon_ar2",
        "weapon_crossbow",
        "weapon_rpg"
    }
    local WepList2 = {
        "weapon_hossrifle",
        "weapon_longbar",
        "weapon_frag",
        "weapon_shotgun"
    }

if(IsValid(controller.Target)) then
    local TargetDist = controller.Target:GetPos():DistToSqr(controller:GetPos())
    if (TargetDist < range/4 and TargetDist < range*2) then
        for _, wepClass in ipairs(WepList0) do
            if bot:HasWeapon( wepClass ) then
              selectWeap = wepClass
              weapon_type = 'mele'
            end
         end
    elseif (TargetDist > range) then
        for _, wepClass in ipairs(WepList1) do
            if bot:HasWeapon( wepClass ) then
              selectWeap = wepClass
              weapon_type = "long_guns"
            end
         end
    elseif (TargetDist < range) then
        for _, wepClass in ipairs(WepList2) do
            if bot:HasWeapon( wepClass ) then
                selectWeap = wepClass
                weapon_type = "shotgun"
            end
    end

    end

    if (TargetDist > range/4) then
        buttons = buttons + IN_DUCK
    end

    if selectWeap != nil then
        bot:SelectWeapon(selectWeap)
    end

    end

    cmd:ClearButtons()
    cmd:ClearMovement()
    cmd:SetButtons(buttons)
end