pointshop pre round

I want to add some weapons to the servers pointshop and limit them based on their evolve ranks.

So something like;


ITEM.Name = 'Mac10'
ITEM.Price = 250
ITEM.Material = 'some/images/mac10.png'
ITEM.WeaponClass = 'weapon_ttt_mac10'
ITEM.SingleUse = true

function ITEM:CanPlayerBuy(ply)
	return ply:Alive() and (ply:EV_GetRank() == "owner" or the other ton of ranks who are allowed this)
end

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

However, I wish that they only be able to purchase it during Pre-round.

So they must be alive, meet the rank requirement, and not be in an active round. Is there a way to do this?

Can’t seem to find anything in wiki about getting the current status of the round (presumably there’ll be something that knows if it’s pre, active or post round?)

How I would go about doing it.



ITEM.Name = 'Mac10'
ITEM.Price = 250
ITEM.Material = 'some/images/mac10.png'
ITEM.WeaponClass = 'weapon_ttt_mac10'
ITEM.SingleUse = true

local canPlayerBuy = false
hook.Add("TTTPrepareRound", "Allowbuyingfornow", function()
	canPlayerBuy = true
end)
hook.Add("TTTBeginRound", "Disallowbuyingnow", function()
	canPlayerBuy = false
end)

function ITEM:CanPlayerBuy(ply)
	if ply:Alive() and (ply:EV_GetRank() == "owner" or the other ton of ranks who are allowed this) then
		if canPlayerBuy then
			return true
		end
		return false
	end
	return false
end

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


[LUA]
ITEM.AllowedUserGroups = { “owner”, “admin”, “vip” }
[/LUA]

??

EDIT: Ok, looking back over the thread this isn’t what you need, but use it as you will.

Thanks crazy i’ll give it a go now.

[editline]11th January 2014[/editline]

Doesn’t seem to work, never allows me to buy it (did once when I first put them in)

Seems like the canPlayerBuy doesn’t get set to true using the TTTPrepareRound hook?

Looking over it, that was a horrible way to do it, when TTT already gives you the functions you need for it. Try using this one instead, my mistake.



ITEM.Name = 'Mac10'
ITEM.Price = 250
ITEM.Material = 'some/images/mac10.png'
ITEM.WeaponClass = 'weapon_ttt_mac10'
ITEM.SingleUse = true

function ITEM:CanPlayerBuy(ply)
	local state = GetRoundState()
	if ply:Alive() and (ply:EV_GetRank() == "owner" or the other ton of ranks who are allowed this) then
		if state == ROUND_PREP then
			return true
		end
		return false
	end
	return false
end

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


This should work fine, as opposed to having a line about it in canbuy. The pointshop already supports Evolve ranks (at least mine does), so you’d basically just place in the group ID you set when you do the AllowedUserGroups part.

Regardless, that’s nothing to do with the basis of the thread.

I’ve used AllowedUsergroups in past and wasn’t fine, so modified so it’s under CanPlayerBuy function which works perfectly.

Thanks again crazy, will give it a go now.