Pointshop 1: (TTT) Replacing current weapon with chosen weapon
6 replies, posted
Not sure if this is the right section so apologies if so. I want to replace a current weapon someone has for a different one. The point of this is to have upgraded weapons from the t/d shop. I've been searching the forums for things similar and came across this code, this does the job but doesn't strip/give the original weapon. I want it so that if people try and sell it/take the item off it will instantly strip.
[CODE]function ITEM:OnEquip(ply, modifications)
timer.Create("weaponcheck_"..ply:SteamID(), 1, 0, function()
if ply:HasWeapon( "weapon_ttt_push" ) then
ply:StripWeapon('weapon_ttt_push')
ply:Give(self.WeaponClass)
ply:SelectWeapon(self.WeaponClass)
end
end)
end
function ITEM:OnHolster(ply)
timer.Destroy("weaponcheck_"..ply:SteamID())
ply:StripWeapon(self.WeaponClass)
ply:Give('weapon_ttt_push')
end
[/CODE]
Just a guess but could it be that it isn't running the rest of the code during holster because the weapon check timer doesn't exist?
In Pointshop, OnEquip is only called when the player equips it via the shop menu.
Try using ITEM:PlayerSpawn( ply ), and call it when the player spawns, because initially when a player dies, they basically Holster the weapon, so yeah.
Thank you Jacob! I'm quite stupid for got to look into the other functions. I presumed On Equip also meant when spawned that it would also work. Sorry for this post and thanks for helping :P
Recently noticed that despite everything working the timers are failing and giving me this error.
[QUOTE]
[ERROR] addons/pointshop/lua/items/reskins/newton.lua:19: Tried to use a NULL entity!
1. HasWeapon - [C]:-1
2. unknown - addons/pointshop/lua/items/reskins/newton.lua:19
Timer Failed! [weaponcheck_STEAM_0:1:80657775][@addons/pointshop/lua/items/reskins/newton.lua (line 18)][/QUOTE]
Pointshop code:
[CODE]function ITEM:PlayerSpawn(ply)
timer.Create("weaponcheck_"..ply:SteamID(), 1, 0, function() --- Line 18
if ply:HasWeapon( "weapon_ttt_push" ) then --Line 19
ply:StripWeapon('weapon_ttt_push')
ply:Give(self.WeaponClass)
ply:SelectWeapon(self.WeaponClass)
end
end)
end
function ITEM:OnEquip(ply, modifications)
timer.Create("weaponcheck_"..ply:SteamID(), 1, 0, function()
if ply:HasWeapon( "weapon_ttt_push" ) then
ply:StripWeapon('weapon_ttt_push')
ply:Give(self.WeaponClass)
ply:SelectWeapon(self.WeaponClass)
end
end)
end
function ITEM:OnHolster(ply)
timer.Remove("weaponcheck_"..ply:SteamID())
ply:StripWeapon(self.WeaponClass)
end
function ITEM:OnSell(ply)
timer.Remove("weaponcheck_"..ply:SteamID())
ply:StripWeapon(self.WeaponClass)
end
[/CODE]
Originally I thought this was happening when the user leaves but, I proven it hasn't. Not sure why.
[QUOTE=Impitt;52467669]Recently noticed that despite everything working the timers are failing and giving me this error.
Pointshop code:
[CODE]function ITEM:PlayerSpawn(ply)
timer.Create("weaponcheck_"..ply:SteamID(), 1, 0, function() --- Line 18
if ply:HasWeapon( "weapon_ttt_push" ) then --Line 19
ply:StripWeapon('weapon_ttt_push')
ply:Give(self.WeaponClass)
ply:SelectWeapon(self.WeaponClass)
end
end)
end
function ITEM:OnEquip(ply, modifications)
timer.Create("weaponcheck_"..ply:SteamID(), 1, 0, function()
if ply:HasWeapon( "weapon_ttt_push" ) then
ply:StripWeapon('weapon_ttt_push')
ply:Give(self.WeaponClass)
ply:SelectWeapon(self.WeaponClass)
end
end)
end
function ITEM:OnHolster(ply)
timer.Remove("weaponcheck_"..ply:SteamID())
ply:StripWeapon(self.WeaponClass)
end
function ITEM:OnSell(ply)
timer.Remove("weaponcheck_"..ply:SteamID())
ply:StripWeapon(self.WeaponClass)
end
[/CODE]
Originally I thought this was happening when the user leaves but, I proven it hasn't. Not sure why.[/QUOTE]
Line 19 is just [B]end[/B].
Post the full code
Presumably this is line 19 [lua]if ply:HasWeapon( "weapon_ttt_push" ) then[/lua]
Remember the player can leave the server with the item equipped, meaning the timer will keep running. Change the line to make sure the player still exists
[lua]if IsValid( ply ) and ply:HasWeapon( "weapon_ttt_push" ) then[/lua]
Thank you!
Sorry, you need to Log In to post a reply to this thread.