From 534eb4cd9aafdc7dc681c3c4dcc26fd262214deb Mon Sep 17 00:00:00 2001 From: viral32111 Date: Sat, 28 Apr 2018 22:48:27 +0100 Subject: [PATCH] Update 125 (Previous Commit Included) - Changed holdtype to normal. - Fixed going outside world and getting a NULL script error bug. - Optimized a few more GetNW's --- README.md | 2 +- lua/autorun/carkeys.lua | 2 +- lua/weapons/carkeys/cl_init.lua | 4 ++-- lua/weapons/carkeys/shared.lua | 17 +++++++++++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d347b38..3158f22 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Car Keys -#### Version: 124 +#### Version: 125 In short this addon protects others from getting in or picking up your car. diff --git a/lua/autorun/carkeys.lua b/lua/autorun/carkeys.lua index f33755b..1898581 100644 --- a/lua/autorun/carkeys.lua +++ b/lua/autorun/carkeys.lua @@ -15,7 +15,7 @@ limitations under the License. ---------------------------------------------------------------------------]] CarKeys = {} -CarKeys.Version = 124 +CarKeys.Version = 125 CarKeys.Name = "Car Keys" AddCSLuaFile("carkeys_config.lua") diff --git a/lua/weapons/carkeys/cl_init.lua b/lua/weapons/carkeys/cl_init.lua index aa60877..ae69cb5 100644 --- a/lua/weapons/carkeys/cl_init.lua +++ b/lua/weapons/carkeys/cl_init.lua @@ -29,14 +29,14 @@ function SWEP:DrawHUD() local owner = trace:GetNWString( "CarKeysVehicleOwner", "N/A" ) local Price = tostring( trace:GetNWInt( "CarKeysVehiclePrice", 0 ) ) - if ( trace == nil ) then return end + if ( trace == nil or trace == NULL ) then return end if ( ply:InVehicle() ) then return end if ( ply:GetPos():Distance( trace:GetPos() ) >= 150 ) then return end if ( table.HasValue( CarKeysVehicles, trace:GetClass() ) ) and ( trace:GetClass() != "gmod_sent_vehicle_fphysics_wheel" ) then if ( owner != "N/A" ) then draw.DrawText( "Owned by " .. owner, "TargetID", ScrW()/2, ScrH()/2+15, Color( 255, 255, 255 ), TEXT_ALIGN_CENTER) - if ( ply:GetEyeTrace().Entity:GetNWBool( "CarKeysVehicleLocked", false ) ) then + if ( ply:GetEyeTrace().Entity:GetNWBool( "CarKeysVehicleLocked" ) ) then draw.DrawText( "Vehicle is locked", "TargetIDSmall", ScrW()/2, ScrH()/2+35, Color( 255, 255, 255 ), TEXT_ALIGN_CENTER) else draw.DrawText( "Vehicle is unlocked", "TargetIDSmall", ScrW()/2, ScrH()/2+35, Color( 255, 255, 255 ), TEXT_ALIGN_CENTER) diff --git a/lua/weapons/carkeys/shared.lua b/lua/weapons/carkeys/shared.lua index 5e21c39..86b2acb 100644 --- a/lua/weapons/carkeys/shared.lua +++ b/lua/weapons/carkeys/shared.lua @@ -40,6 +40,10 @@ SWEP.ViewModelFlip = false SWEP.ViewModel = "models/sentry/pgkey.mdl" SWEP.WorldModel = "" -- models/sentry/pgkey.mdl +function SWEP:Initialize() + self:SetHoldType("normal") +end + function SWEP:Reload() if ( SERVER and IsFirstTimePredicted() ) then if ( timer.Exists( "CarKeysReloadTimer" ) ) then @@ -51,8 +55,9 @@ function SWEP:Reload() local ply = self.Owner local ent = ply:GetEyeTrace().Entity - local Price = ent:GetNWInt( "CarKeysVehiclePrice", 0 ) + local Price = ent:GetNWInt( "CarKeysVehiclePrice" ) + if ( ent == nil or ent == NULL ) then return end if not ( table.HasValue( CarKeysVehicles, ent:GetClass() ) ) then return end if ( ent:GetClass() == "gmod_sent_vehicle_fphysics_wheel" ) then return end if ( ply:GetPos():Distance( ent:GetPos() ) >= 150 ) then return end @@ -61,11 +66,11 @@ function SWEP:Reload() if ( engine.ActiveGamemode() == "darkrp" ) then if ( ply:canAfford( Price ) ) then ply:addMoney( -Price ) - ply:SendLua([[ chat.AddText( Color( 26, 198, 255 ), "(Car Keys) ", Color( 255, 255, 255 ), "You have bought this vehicle for $" .. tostring( LocalPlayer():GetEyeTrace().Entity:GetNWInt( "CarKeysVehiclePrice", 0 ) ) ) ]]) + ply:SendLua([[ chat.AddText( Color( 26, 198, 255 ), "(Car Keys) ", Color( 255, 255, 255 ), "You have bought this vehicle for $" .. tostring( LocalPlayer():GetEyeTrace().Entity:GetNWInt( "CarKeysVehiclePrice" ) ) ) ]]) ent:SetNWString( "CarKeysVehicleOwner", ply:Nick() ) ent:EmitSound("ambient/machines/keyboard6_clicks.wav") else - ply:SendLua([[ chat.AddText( Color( 26, 198, 255 ), "(Car Keys) ", Color( 255, 255, 255 ), "You cannot affort this vehicle! It cost $" .. tostring( LocalPlayer():GetEyeTrace().Entity:GetNWInt( "CarKeysVehiclePrice", 0 ) ) ) ]]) + ply:SendLua([[ chat.AddText( Color( 26, 198, 255 ), "(Car Keys) ", Color( 255, 255, 255 ), "You cannot affort this vehicle! It cost $" .. tostring( LocalPlayer():GetEyeTrace().Entity:GetNWInt( "CarKeysVehiclePrice" ) ) ) ]]) end else ply:SendLua([[ chat.AddText( Color( 26, 198, 255 ), "(Car Keys) ", Color( 255, 255, 255 ), "You have acquired this vehicle!" ) ]]) @@ -76,7 +81,7 @@ function SWEP:Reload() if ( ent:GetNWString( "CarKeysVehicleOwner", "N/A" ) == ply:Nick() ) then if ( engine.ActiveGamemode() == "darkrp" ) then ply:addMoney( Price ) - ply:SendLua([[ chat.AddText( Color( 26, 198, 255 ), "(Car Keys) ", Color( 255, 255, 255 ), "You have sold your vehicle for $" .. tostring( LocalPlayer():GetEyeTrace().Entity:GetNWInt( "CarKeysVehiclePrice", 0 ) ) ) ]]) + ply:SendLua([[ chat.AddText( Color( 26, 198, 255 ), "(Car Keys) ", Color( 255, 255, 255 ), "You have sold your vehicle for $" .. tostring( LocalPlayer():GetEyeTrace().Entity:GetNWInt( "CarKeysVehiclePrice" ) ) ) ]]) else ply:SendLua([[ chat.AddText( Color( 26, 198, 255 ), "(Car Keys) ", Color( 255, 255, 255 ), "You no longer own this vehicle." ) ]]) end @@ -103,6 +108,7 @@ function SWEP:PrimaryAttack() local ply = self.Owner local ent = ply:GetEyeTrace().Entity + if ( ent == nil or ent == NULL ) then return end if not ( table.HasValue( CarKeysVehicles, ent:GetClass() ) ) then return end if ( ent:GetClass() == "gmod_sent_vehicle_fphysics_wheel" ) then return end if ( ply:GetPos():Distance( ent:GetPos() ) >= 150 ) then return end @@ -119,6 +125,7 @@ function SWEP:PrimaryAttack() ply:SendLua([[ chat.AddText( Color( 0, 180, 255 ), "(Car Keys) ", Color( 255, 255, 255 ), "You cannot lock this vehicle, You don't own it." ) ]]) ent:EmitSound("doors/handle_pushbar_locked1.wav") end + ply:AnimRestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_GMOD_GESTURE_ITEM_PLACE, true ) ply:SendLua([[ LocalPlayer():AnimRestartGesture(GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_GMOD_GESTURE_ITEM_PLACE, true) ]]) end @@ -136,6 +143,7 @@ function SWEP:SecondaryAttack() local ply = self.Owner local ent = ply:GetEyeTrace().Entity + if ( ent == nil or ent == NULL ) then return end if not ( table.HasValue( CarKeysVehicles, ent:GetClass() ) ) then return end if ( ent:GetClass() == "gmod_sent_vehicle_fphysics_wheel" ) then return end if ( ply:GetPos():Distance( ent:GetPos() ) >= 150 ) then return end @@ -147,6 +155,7 @@ function SWEP:SecondaryAttack() ply:SendLua([[ chat.AddText( Color( 0, 180, 255 ), "(Car Keys) ", Color( 255, 255, 255 ), "You cannot unlock this vehicle, You don\'t own it." ) ]]) ent:EmitSound("doors/handle_pushbar_locked1.wav") end + ply:AnimRestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_GMOD_GESTURE_ITEM_PLACE, true ) ply:SendLua([[ LocalPlayer():AnimRestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_GMOD_GESTURE_ITEM_PLACE, true ) ]]) end