Facepunch / garrysmod-issues

Garry's Mod issue tracker
147 stars 56 forks source link

Creating NPC and using npc:Give() will create weapon, what npc can't use #2070

Closed DBotThePony closed 9 years ago

DBotThePony commented 9 years ago

The code looks like

function DCops.SpawnCop(ply)
    if not DCops.isCopsWanted(ply) then return end

    for k,v in pairs(DCops.cops[ply:UniqueID()]) do
        if not IsValid(v) then DCops.cops[ply:UniqueID()][k] = nil end
    end

    if #DCops.cops[ply:UniqueID()] > 50 then return end

    local pos = ply:GetPos()
    local randpos = 1000
    local newent = ents.Create("npc_metropolice")

    if not IsValid(newent) then return end

    local npc_pos = Vector(pos.x + math.random(-randpos,randpos),pos.y + math.random(-randpos,randpos),pos.z+10)

    newent:SetPos(npc_pos)

    local angles = (pos-npc_pos):Angle()

    newent:SetAngles(Angle(0,angles.y,0))
    local weapon = newent:Give("weapon_stunstick")
    weapon:Activate()

    for _,v in pairs(player.GetAll()) do
        newent:AddEntityRelationship(v,D_NU,99)
    end

    for k,v in pairs(DCops.getWanted()) do
        newent:AddEntityRelationship(v,D_HT,100)
    end

    newent:AddEntityRelationship(ply,D_HT,100)
    newent:SetCondition( NPC_STATE_ALERT )
    --newent:SetTarget(ply)
    --newent:SetEnemy(ply)

    newent.isRealCop = true

    newent:Spawn()
    newent:Activate()

    table.insert(DCops.cops[ply:UniqueID()],newent)
end

I tried everything! 2015-06-04_00013 2015-06-04_00010 2015-06-04_00011 edit: Custom sweps working partially, HL2 weapons don't work at all

robotboy655 commented 9 years ago

NPCs can only use ai_* counter parts of Half Life 2 weapons ( ai_weapon_stunstick, etc ).

See how sandbox does it: https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/sandbox/gamemode/commands.lua#L392-L395

DBotThePony commented 9 years ago

Huge Thanks