Skip to content

Commit

Permalink
Update 125
Browse files Browse the repository at this point in the history
(Previous Commit Included)
- Changed holdtype to normal.
- Fixed going outside world and getting a NULL script error bug.
- Optimized a few more GetNW's
  • Loading branch information
viral32111 committed Apr 28, 2018
1 parent b5076d0 commit 534eb4c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Car Keys
#### Version: 124
#### Version: 125

In short this addon protects others from getting in or picking up your car.

Expand Down
2 changes: 1 addition & 1 deletion lua/autorun/carkeys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
---------------------------------------------------------------------------]]

CarKeys = {}
CarKeys.Version = 124
CarKeys.Version = 125
CarKeys.Name = "Car Keys"

AddCSLuaFile("carkeys_config.lua")
Expand Down
4 changes: 2 additions & 2 deletions lua/weapons/carkeys/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions lua/weapons/carkeys/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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!" ) ]])
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 534eb4c

Please sign in to comment.