[TTT] Is it possible/how can I replace a traitor shop item if user has item equipped.

Hello, not sure how to word this correctly within the title so excuse that. I’ve recently found an interest within TTT, but wanted to try doing a pointshop item, which is essentially an upgrade of a T weapon. Issue I found is, having the pointshop item use the weapon class to strip then give the new weapon class is not clean. I want to make it so if user has item equipped it will won’t return canbuy from the default weapon class and the new weapon class if has item equipped it will return the canbuy. Not sure if this is possible. Sorry if it sounds unclear.

Edit: To be more clearer, I want to hide one weapon from the t shop if item is equipped and show the other weapon.

Thanks for reading.

What is the name of the weapon?
And you haven’t defined what SWEP is.

Use the TTTCanOrderEquipment hook https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/terrortown/gamemode/weaponry.lua#L337

The weapon is prop disguiser and thanks stardust but how would I exactly use the function?

It’s a hook so you’d use

hook.Add.

After doing this I got it to work! But just noticed the issue, I said replace the Traitor weapon so. The default doesn’t appear if has the item equipped and then the other one shows if the item is equipped?

It would be easiest to just make both appear in the menu but only allow those who own the PointShop weapon to be able to buy it. If you did some modifications to the cl_equip.lua file you might be able to achieve what you want…

From this thread

Replace table.HasValue with PS_HasItemEquipped and you’re good to go

Thanks for trying to help but no luck with that :(. Preventing it being purchased is the only thing that did :(. Seems to be no way to hide to weapon from the store at all

What exactly did you do? The first code is supposed to go on the client

I did exactly what you said to do.

Well I did exactly what I said to do too and it worked…
Show us everything you have and what is happening (So each file and what actually occurs in-game)

The within lua/autorun/client


local oWeaponsGetList = weapons.GetList

function weapons.GetList()
	local tbl = oWeaponsGetList()

	if not IsValid( LocalPlayer() ) then return tbl end

	local grp = LocalPlayer():GetUserGroup()

	if string.find( debug.traceback(), "GetEquipmentForRole" ) then
		for k, wep in pairs( tbl ) do
			if wep and wep.CanBuy and wep.GroupOnly and wep.Groups and not PS_HasItemEquipped( wep.Groups, grp ) then
				table.remove( tbl, k )
			end
		end
	end
	return tbl
end


Wasn’t sure where this was meant to go, so I placed it at the bottom of one of my t weapons.


hook.Add( "TTTCanOrderEquipment", "GroupOnlyWeapons", function( ply, wep )
	wep = weapons.GetStored(wep)
	if wep.GroupOnly then
		return PS_HasItemEquipped( wep.Groups, ply:GetUserGroup() )
	end
end )

Like I said, blocking the weapon from being purchased works but actually removing it doesn’t. From looking at the code, it never said anything about stating what pointshop item should be equipped in the first place. I guess that would have some form of issue? Sorry for this, thanks for helping

Well, that code is not even close to being functional at all.
PS_HasItemEquipped is not a global function, it’s a metafunction. You have to call it with ply:PS_HasItemEquipped where ply is a player variable.
Next, you only want to do run this code on weapons that are pointshop-only, so you should have a variable in your weapon’s code, something like SWEP.Pointshop = true.
Then, in the code, instead of:
[lua]if wep and wep.CanBuy and wep.GroupOnly and wep.Groups and not PS_HasItemEquipped( wep.Groups, grp ) then[/lua] you need to put: [lua]if wep and wep.Pointshop and and not LocalPlayer():PS_HasItemEquipped( wep:GetClass() ) then[/lua]

I put in wep:GetClass() for the item name but it needs to be the PS item name.

As for the 2nd code (TTTCanOrderEquipment), put it anywhere serverside (lua/autorun/server will do), and again - change the code to make it work (Pretty much do what I did up there ^ but use ply instead of LocalPlayer())

client:


local oWeaponsGetList = weapons.GetList

function weapons.GetList()
	local tbl = oWeaponsGetList()

	if not IsValid( LocalPlayer() ) then return tbl end

	local grp = LocalPlayer():GetUserGroup()

	if string.find( debug.traceback(), "GetEquipmentForRole" ) then
		for k, wep in pairs( tbl ) do
			if wep and wep.Pointshop and not LocalPlayer():PS_HasItemEquipped( "newton" ) then
				table.remove( tbl, k )
			end
		end
	end
	return tbl
end

Server:


hook.Add( "TTTCanOrderEquipment", "GroupOnlyWeapons", function( ply, wep )
	wep = weapons.GetStored(wep)
	if wep.GroupOnly then
		return PS_HasItemEquipped( wep.Pointshop, ply:PS_HasItemEquipped() )
	end
end )

SWEP.Pointshop = true on weapon

Sorry if I’m misunderstood, but tried this and still no luck.

Thanks for marking as “Dumb” in an arrogant approach. You can clearly tell i’m stuck and have been listening to you.

haha no :suicide:

You literally didn’t even touch the serverside code

Whatever then, if you can clearly tell I attempted to. Sorry that I’m not the best and you’re not the best at describing :confused:

You didn’t attempt anything. You literally just copy+pasted some code.