Chessnut / NutScript

A free role-play framework for Garry's Mod.
http://nutscript.rocks
MIT License
94 stars 77 forks source link

Very strange problem #745

Closed ghost closed 7 years ago

ghost commented 7 years ago

I have reprogrammaing the shootlock plugin because the original is only functionnal with doors who have a handle.

Original shootlock plugin : https://github.com/Chessnut/hl2rp/blob/1.1/plugins/shootlock.lua

My code :

PLUGIN.name = "Shoot Locks"
PLUGIN.author = "Chessnut"
PLUGIN.desc = "Shoot locks to open doors."

local SHOOT_DISTANCE = 180

function PLUGIN:EntityFireBullets( ent, data )
    if (ent:GetClass() == "player") then

        local client = ent
        local position = client:GetEyeTrace().HitPos
        local entity = client:GetEyeTrace().Entity

        if (entity:GetClass() ==  "func_door_rotating") then

            if (client:GetEyeTrace().Entity != entity or client:GetPos():Distance(position) > SHOOT_DISTANCE) then
                return
            end

            if (IsValid(client)) then
                if (hook.Run("CanPlayerBustLock", client, entity) == false) then
                    return
                end

                local weapon = client:GetActiveWeapon()

                if (IsValid(weapon) and weapon:GetClass() == "weapon_shotgun") then
                    entity:EmitSound("physics/wood/wood_crate_break"..math.random(1, 5)..".wav", 150)
                    entity:blastDoor(client:GetAimVector() * 380)

                    local effect = EffectData()
                        effect:SetStart(position)
                        effect:SetOrigin(position)
                        effect:SetScale(10)
                    util.Effect("GlassImpact", effect, true, true)

                    return
            end
            end

            if (IsValid(client) and position:Distance(entity:GetPos()) <= 200) then
                if (hook.Run("CanPlayerBustLock", client, entity) == false) then
                    return
                end

                local effect = EffectData()
                    effect:SetStart(position)
                    effect:SetOrigin(position)
                    effect:SetScale(2)
                util.Effect("GlassImpact", effect)

                local name = client:UniqueID()..CurTime()
                client:SetName(name)

                entity.nutOldSpeed = entity.nutOldSpeed or entity:GetKeyValues().speed or 100
                entity:Fire("setspeed", entity.nutOldSpeed * 3.5)
                entity:Fire("unlock")
                entity:Fire("Open")
                entity:EmitSound("physics/wood/wood_plank_break"..math.random(1, 4)..".wav", 100, 120)

                entity.nutNextBreach = CurTime() + 1

                timer.Simple(0.5, function()
                    if (IsValid(entity)) then
                        entity:Fire("setspeed", entity.nutOldSpeed)
                    end
                end)
            end
        end
    end
end

My script is functional because the doors are broken when i shoot, but my game says there is an error.

My console :

[ERROR] gamemodes/postaporp/plugins/shootlock.lua:56: attempt to call method 'SetName' (a nil value)
  1. v - gamemodes/postaporp/plugins/shootlock.lua:56
   2. unknown - gamemodes/nutscript/gamemode/core/libs/sh_plugin.lua:397

And if i remove the 56th line (client:SetName(name), my console says :

[ERROR] gamemodes/postaporp/plugins/shootlock.lua:58: attempt to call method 'GetKeyValues' (a nil value)
  1. v - gamemodes/postaporp/plugins/shootlock.lua:58
   2. unknown - gamemodes/nutscript/gamemode/core/libs/sh_plugin.lua:397

Thank you for answering me ! SuperMicronde

chadreed93 commented 7 years ago

I think its setName as seen here https://github.com/Chessnut/NutScript/search?utf8=%E2%9C%93&q=SetName

ghost commented 7 years ago

Thanks a lot but it's not setName from nutscript but SetName like in the original plugin

http://wiki.garrysmod.com/page/Entity/SetName

ghost commented 7 years ago

Please i need help for create a fallout server