[TTT] Pointshop D/T Role fix

Not entirely sure who created this but I made a minor change to fix them so if purchased a role and end up being that role by TTT’s selection then you dont lose your credits. ie: Buying Traitor only to actually be a Traitor that round. The new server I play on doesn’t have a Pointshop (thank god) so I figured I would throw them on here for anyone who wants them.



ITEM.Name = 'Detective'
ITEM.Price = 1000
ITEM.Material = 'vgui/ttt/icon_det.png'
ITEM.OneUse = true

function ITEM:OnEquip(ply, modifications)
	ply:ChatPrint("[PS]: Bought Detective round! It will take effect at the start of the next round")
	hook.Add("TTTBeginRound", ply:UniqueID() .. "_detective", function()
	if SERVER then
		if ply:GetRole() ~= ROLE_DETECTIVE then
			ply:SetRole(ROLE_DETECTIVE)
			ply:Give("weapon_ttt_wtester")
			ply:AddCredits( GetConVarNumber( "ttt_credits_starting" ) )
			ply:PS_TakeItem(self.ID)
			ply:ChatPrint("[PS]: Forced Detective. Have fun!")
		elseif ply:GetRole() == ROLE_DETECTIVE then
			ply:ChatPrint("[PS]: You are already a Detective! You will recieve Detective on the next round")
		end
	end
		
	hook.Remove("TTTBeginRound", ply:UniqueID() .. "_detective") end)
end

function ITEM:OnHolster(ply)
	hook.Remove("TTTBeginRound", ply:UniqueID() .. "_detective")
end

function ITEM:OnSell(ply)
	hook.Remove("TTTBeginRound", ply:UniqueID() .. "_detective")
end




ITEM.Name = 'Traitor'
ITEM.Price = 1000
ITEM.Material = 'vgui/ttt/icon_traitor.png'
ITEM.OneUse = true

function ITEM:OnEquip(ply, modifications)
	ply:ChatPrint("[PS]: Bought Traitor round! It will take effect at the start of the next round")
	hook.Add("TTTBeginRound", ply:UniqueID() .. "_traitor", function()
	if SERVER then
		if ply:GetRole() ~= ROLE_TRAITOR then
			ply:SetRole(ROLE_TRAITOR)
			ply:AddCredits( GetConVarNumber( "ttt_credits_starting" ) )
			ply:PS_TakeItem(self.ID)
			ply:ChatPrint("[PS]: Forced Traitor. Have fun!")
		elseif ply:GetRole() == ROLE_TRAITOR then
			ply:ChatPrint("[PS]: You are already a Traitor! You will recieve Traitor on the next round")
		end
	end
		
	hook.Remove("TTTBeginRound", ply:UniqueID() .. "_traitor") end)
end

function ITEM:OnHolster(ply)
	hook.Remove("TTTBeginRound", ply:UniqueID() .. "_traitor")
end

function ITEM:OnSell(ply)
	hook.Remove("TTTBeginRound", ply:UniqueID() .. "_traitor")
end


Why should someone be able to BUY a Traitor / Detective Round, it would ADD one more traitor! (8 Players - not 2 traitors, 3!)

Most server add this since sometimes it’s hard for players just to get 1 Traitor round, One time I was in a server and I wasn’t able to get traitor in over 12 rounds.

But then you have abusive admins buying T every round.

Get better admins

I don’t have a TTT server.

Its not aimed at you, Im saying if anyone has abusive admins on their staff team, they should get better admins

Its pointshop code… Unless you give your admins the ability to add/remove points, “aboosive admans” wont be able to cheat the system. It simply serves as a nice perk for people who play frequently and when I managed a server, very few people bought them unless they were leaving for a long time or something.

Even in my owe server, it happened. I wasn’t traitor for about 2 maps, and i can 100% guarantee that none of my admins abuse the admin commands to become traitor.

on topic it looks nice to add, but is their a way to script a timer on it ?

Like player buy’s it at round 3, and has to wait 3 rounds before he’s able to buy it again?

Just some thought’s i had… my lua knowledge ain’t that good but i might try to add in a timer myself!

Serene Gaming had this once, I’d be really interested to add a timer for 1 buy every map!

Ye i’m still trying to find a way to create an round timer instead of seconds/minutes.

Tips/Help’s are welcome

Once a player buys it, set a variable like ply.Countdown to 3 or whatever you wanted. Hook to TTTEndRound then grab all players and subtract 1 from their countdown. Finally throw something into the ITEM’s buy function that checks the Countdown and returns accordingly

Untested but its how I would do it

I understand the logic way of you explaining this, But i’m pretty new to lua, so could u might give me another ‘‘hint’’ (not willing you to make this for me, somehow I have to achieve this myself #discipline).

so far i got



function timer
	hook.Add(ply.countdown 3)
	end 
	
function ITEM:OnBuy
Hook.add("TTTEndRound", ply(), ply.countdown -1)
print "Roundtimer reduced by 1"
end


I have a feeling I’m messing up with the hook’s.

You can rate this dumb :slight_smile:

That wont work lol. I’m not terribly good with Pointshop but try this



function ITEM:OnBuy()
ply.Countdown = 3
Hook.add("TTTEndRound", ply:SteamId().."_countdown", function()
-- Reduce countdown
end
end



ply isnt declared there, oops

Oh ffs.


function ITEM:OnBuy( ply )
   ply.Countdown = 3
   hook.add( "TTTEndRound", ply:SteamID() .. "_countdown", function()
      -- Reduce countdown
   end )
end

Does that work?

Try it and see?

Didn’t had the opportunity to try it out yet, like chimp said try it out and find it out :smiley:

I’ll probably try to add this to my server tomorrow, if you read back i have said that i didn’t asked them to complete it so it might be that they didn’t and still gave me a part to do, if that happened you still gotta do some work!

Buying Traitor doesn’t even work for me…

Then you’re obviously doing it wrong, cause I mean I already used these and they work so yeaaaaaaah