Deathrun / Pointshop | Setting crowbar skins / models?

I know how to add weapons to the pointshop, however I’ve had a couple of problems.
I’ve wanted to add the crowbar weapon but with different models on it, like
ie. a katana instead of the regular crowbar, but having it function like the regular one.

I have, however, not found a way to get the crowbar lua code, disallowing me to simply

  1. change the model, the weapon is using,
  2. change the weapon name according to what model is used.

Before anyone starts referring to TTT - that won’t work. I tried that and it ended up with
runners being able to team kill each others, plus it seems that there are slight differences
with the regular HL2 crowbar and the TTT (but should be easily changeable).

Please note that I need to have multiple models for the crowbar, and purchasing them in
the shop will set your crowbar’s skin.

Questions / TL;DR:

Any ways to get the HL2 crowbar lua code?
Can I remove the ability to kill everyone from the TTT crowbar code?
Can I affect the weapon_crowbar without actually having all of the code, ie. simply changing the model and leaving everything else blank?
Is there a simpler way to change the crowbar’s model?

You can either recreate the crowbar in Lua, or set the view model in the OnEquip hook.

How would I go about changing the model with the hook?



ITEM.Name = 'Crowbar'
ITEM.Price = 0
ITEM.Model = 'models/weapons/w_crowbar.mdl'
ITEM.WeaponClass = 'weapon_crowbar'
ITEM.SingleUse = false

function ITEM:OnBuy(ply)
	ply:Give(self.WeaponClass)
	ply:SelectWeapon(self.WeaponClass)
end

function ITEM:OnEquip(ply)

end

function ITEM:OnSell(ply)
	ply:StripWeapon(self.WeaponClass)
end


ITEM.Model =

That changes the pointshop model when previewing it.

Bump?

Edit:

So far, this is what I’m trying to do (or something like it):



function ITEM:OnEquip(ply)
	self.WeaponClass:SetMaterial("models/weapons/v_crowbar/crowbar_cyl.vtf")
end


I get this error though:


[ERROR] addons/pointshop-master/lua/pointshop/items/weapons/crowbar.lua:13: attempt to index a string value with bad key ('SetMaterial' is not part of the string library)


-snip-

instead, use ply:GetWeapon( self.WeaponClass ):SetMaterial(“your/material/path”)

make sure to check if ply:GetWeapon( self.WeaponClass ) is valid

Still doesn’t seem to work.



ITEM.Name = 'Crowbar'
ITEM.Price = 0
ITEM.Model = 'models/weapons/w_crowbar.mdl'
ITEM.WeaponClass = 'weapon_crowbar'
ITEM.SingleUse = false

function ITEM:OnBuy(ply)
	ply:Give(self.WeaponClass)
	ply:SelectWeapon(self.WeaponClass)
end

function ITEM:OnEquip(ply)
	if ply:GetWeapon( self.WeaponClass ):IsValid then function(ply)
			ply:GetWeapon( self.WeaponClass ):SetMaterial("weapons/v_crowbar/crowbar_cyl.vtf")
		end
	end
end

function ITEM:OnSell(ply)
	ply:StripWeapon(self.WeaponClass)
end





[ERROR] addons/pointshop-master/lua/pointshop/items/weapons/crowbar.lua:13: function arguments expected near 'then'
  1. unknown - addons/pointshop-master/lua/pointshop/items/weapons/crowbar.lua:0


I believe the main cause is this:


Requesting texture value from var "$basetexture" which is not a texture value (material: trails/tube)

This is what you have:


function ITEM:OnEquip(ply)
	if ply:GetWeapon( self.WeaponClass ):IsValid then function(ply)
			ply:GetWeapon( self.WeaponClass ):SetMaterial("weapons/v_crowbar/crowbar_cyl.vtf")
		end
	end
end

and this is what you should try:


function ITEM:OnEquip(ply)
	if IsValid( ply:GetWeapon( self.WeaponClass ) ) then
			ply:GetWeapon( self.WeaponClass ):SetMaterial("weapons/v_crowbar/crowbar_cyl.vtf")
	end
end

First, you needed the correct format for the IsValid check. Some people do it this way and some people use the Class:IsValid() method, I don’t really know if there’s a difference so it might just be personal preference.

Second, you didn’t need to add the “function (ply)” inside your if statement. What this does is define a function, but it doesn’t run anything. You just need to have the SetMaterial line inside the conditional, without the surrounding function. See what I’m saying?

Yeah, I was playing a bit around with it since it said something about the functions, so I believe I pasted the wrong code.
Tried it out again with the right code, returned the same error:


Requesting texture value from var "$basetexture" which is not a texture value (material: trails/tube)


That error is looking for the trails/tube material, nothing to do with the crowbar afaik

Appears every time I equip the crowbar.

Another possibility is the pathing? Does it matter where I put it apart from having it in the /garrysmod folder?
Currently have it in the addons folder, but tried moving around with it a couple of other places too.

Unrelated, but IsValid checks for nil.
IsValid’s “source”:
[lua]
local function IsValid(o)
return o ~= nil and o.IsValid and o:IsValid()
end
[/lua]

Do you have a tube trail or some such in your pointshop? If not, go check the lua files for all your trails and look for anything that mentions “tube”. Let me know

Yeah, I have all the default trails.
If you want the code:


ITEM.Name = 'Tube Trail'
ITEM.Price = 150
ITEM.Material = 'trails/tube.vmt'

function ITEM:OnEquip(ply, modifications)
	ply.TubeTrail = util.SpriteTrail(ply, 0, modifications.color, false, 15, 1, 4, 0.125, self.Material)
end

function ITEM:OnHolster(ply)
	SafeRemoveEntity(ply.TubeTrail)
end

function ITEM:Modify(modifications)
	PS:ShowColorChooser(self, modifications)
end

function ITEM:OnModify(ply, modifications)
	SafeRemoveEntity(ply.TubeTrail)
	self:OnEquip(ply, modifications)
end


I’m pretty sure the reason that error pops up is because pointshop refreshes your items or some shit like that whenever you equip something so it’s checking for the tube trail material and it’s not proper or something like that. Try removing the tubetrail file and see what happens

Right, deleted all trails and I don’t get an error anymore.
The only possibility left is that I might’ve put the .vtf in the wrong folder or something?

Doubtful. I don’t think the tubetrail uses a custom vtf or anything. You should just remove solely the tube trail if you want the rest

For future reference:
When you get ‘function arguments expected near’ error, that means you used a function without setting it’s arguments (ik this is obvious but still). This usually happens when people do something like


LocalPlayer:ConCommand

when it should be


LocalPlayer():ConCommand

Or


if ply:IsValid then

when it should be


if ply:IsValid() then

Sorry if this was unnecessary but a lot of new coders fall in these places, thought it might be useful

Well, this thread isn’t even about the tube trail.

I still haven’t been able to find a solution as to why my code doesn’t work, and why it doesn’t change the material of the crowbar. The path and all is correct, yet it still doesn’t work.