Pointshop help?

Been trying to work on this code to get it a certain way for Pointshop. It’s a traitor/detective buy, I’ve been trying to add a cooldown for 10 rounds, also something that will autoholster it, and not allow the player to reholster until the 10 rounds are up, however it does not sell the item when it’s used. I’m not familiar with PointShop. Halp. Please.

Traitor


ITEM.Name = 'Make Traitor'
ITEM.Price = 20000
ITEM.Model = 'models/props_c17/SuitCase_Passenger_Physics.mdl'
ITEM.OneUse = false

function ITEM:OnEquip(ply, modifications)
hook.Add("TTTBeginRound", ply:UniqueID() .. "_traitor", function()
if ply:GetRoleString() != "traitor" then
ply:SetRole(ROLE_TRAITOR)
ply:AddCredits(GetConVarNumber("ttt_credits_starting"))
end

hook.Add("TTTEndRound")

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

Detective


ITEM.Name = 'Make Detective'
ITEM.Price = 15000
ITEM.Model = 'models/props_c17/SuitCase_Passenger_Physics.mdl'
ITEM.OneUse = false

function ITEM:OnEquip(ply, modifications)
hook.Add("TTTBeginRound", ply:UniqueID() .. "_detective", function()
if ply:GetRoleString() != "detective" then
ply:SetRole(ROLE_DETECTIVE)
ply:AddCredits(GetConVarNumber("ttt_credits_starting"))
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.OneUse should be ITEM.SingleUse (Dunno if that’s the problem, I’m just sayin’)

*saying

ITEM.OneUse has been working so far, however I’m looking for how to auto holster, as of now, it just stays in use, keeping the player a T forever.

If anyone knows what can delay access of the item for a specified amount of rounds, that’s what I’m trying to find.
Also something that holsters the item after being used, which is what the cooldown is for, to keep the player from putting it back on.

I’ve looked everywhere for a way to apply the two items/codes to do this, as said before, I’m not the best at this :stuck_out_tongue:

Use OnBuy instead of OnEquip I would assume, and it is ITEM.SingleUse, not OneUse.

This is planned to be one time buy, then it unequips itself after being used on one round, with a cooldown after. I’m assuming that replacing OnEquip with OnBuy would be making it a kind of one time use item. I believe this, because you would have to rebuy to turn it back on?

I am a bit busy atm but its possible with OnBuy, or you can use PS_HolsterItem in the hook to auto-holster it.

Usage is PS_HolsterItem(“pointshop file name”)

Not quite sure how to do the cooldown on it though, still something I am working on figuring out =p

If you want it to remove itself after being used, put this in the OnEquip function
[lua]ply:PS_TakeItem(self.ID)[/lua]

after giving the credits. Something else you can do is to put an if function at the end of your if statement
[lua]if ply:GetRoleString() != “traitor” then[/lua]
before you close it off to print that they were already a traitor, or what not

Just for the sake of selection,
you could also use
[lua]ply:GetRole() ~= ROLE_TRAITOR[/lua]

I wrote something like this a long time ago ( cooldown over map changes with proper refunds if the map changes before they get to use it ).

I’m trying to locate the code, but I’m also working on a new version ( will be free and I’ll post here when it is done; almost, juggling a few things at the moment )

I don’t have pointshop installed, so I can’t test it. I have made other pointshop addons without testing it that have worked, so hopefully this will too…

So, the way this is set up, the 2 “items” feed info back to the sv_pointshop_special_rounds_system and a lot of logic is processed to determine whether or not the item can be equipped, etc. I don’t know how “single-use” items work, so you’ll need to add that logic in under:


function pointshop_rounds:RoundUsed( _p, _role )

which is called when the user is set as traitor or detective. To prevent unhappy people, it only saves the round-used state if the round ends properly. If the round doesn’t end ( ie server crash, or late map change ), the user will still have their special round.

I also wrote it so that it removes data that we don’t need to prevent the file from becoming overly huge. There is a lot of repeating code because of the tutorial nature, however this one seemed to look more confusing than helpful, so I’ll be reducing the code at some point ( when I test inside TTT and test with pointshop ).

I only tested the minor logic such as hard-coding a role, or whatever and checking the output. I didn’t test the equip functions…

Let me know if there are any issues / errors, whatever and I’ll fix them.

https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_pointshop_make_traitordetective_system/sv_pointshop_special_rounds_system.lua.html

https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_pointshop_make_traitordetective_system/item_buy_detective.lua.html

https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/simple_pointshop_make_traitordetective_system/item_buy_traitor.lua.html

Hopefully these tutorials and information helps. As always, to view the Lua from any of my tutorials to enable copy/pasting ( HTML doesn’t copy/paste well in terms of HTML / CSS Highlighted Lua ), remove .html from the url.

Configuration is straight forward:


//
// Configuration...
//
pointshop_rounds.config = {
	// Folder to store the data in
	folder = string.lower( ( GM or GAMEMODE ).Name ) .. "/acecool/ps_special_rounds/";

	// Filename
	filename = "data.txt";

	// Are the special rounds unique? Can T be purchased after purchasing D round?
	unique_rounds = true;

	// How many rounds does a user need to wait before purchasing a special round again?
	cooldown_rounds = 10;

	// If the user disconnects mid-round, do they lose their round? NOT IMPLEMENTED
	-- punish_disconnect = false;

	// Should credits be halved for the special round player ( after all, it is an additional player )
	punish_credits = true;

	// Should the player be notified each round as to how many rounds they must wait before becoming T or D again.
	notify_cooldown = true;
};

Instead of using hook.Add, use ITEM:HookName( args ), and instead of calling hook.Remove, call Player:SetRole( role ).

Ace, this all looks amazing, I’ve been away for some time now. It will be getting tested shortly. Thank you for the effort!