Not able to have certain ULX groups buy pointshop models.

So I am using pointshop-master and in my code I’m trying to let my donator ranks, donator, vip, and prestigious, all be able to buy the same item.

My code:


ITEM.Name = 'Kleiner'
ITEM.Price = 250
ITEM.Model = 'models/player/kleiner.mdl'

function ITEM:CanPlayerBuy(ply)
	return ply:IsUserGroup("prestigious")
	return ply:IsUserGroup("donator")
	return ply:IsUserGroup("vip")
end

function ITEM:CanPlayerEquip(ply)
	return ply:IsUserGroup("donator")
	return ply:IsUserGroup("prestigious")
	return ply:IsUserGroup("vip")
end

function ITEM:OnEquip(ply, modifications)
	if not ply._OldModel then
		ply._OldModel = ply:GetModel()
	end
	
	timer.Simple(1, function() ply:SetModel(self.Model) end)
end

function ITEM:OnHolster(ply)
	if ply._OldModel then
		ply:SetModel(ply._OldModel)
	end
end

function ITEM:PlayerSetModel(ply)
	ply:SetModel(self.Model)
end


Whenever I try this I get an error message:

[ERROR] addons/pointshop-master/lua/pointshop/items/donator/donatorplayermodel.lua:7: ‘end’ expected (to close ‘function’ at line 5) near ‘return’

  1. unknown - addons/pointshop-master/lua/pointshop/items/donator/donatorplayermodel.lua:0

It says ‘end’ is expected, but I’d think that the one end at the bottom of each function is enough.

Any help is appreciated, thank you. :slight_smile:

Try this? :smile:

It isn’t really necessary to check the player’s group on equip, keep it to can player buy. Also, here is a useful pointshop coding site you might find useful.



ITEM.Name = 'Kleiner'
ITEM.Price = 250
ITEM.Model = 'models/player/kleiner.mdl'

function ITEM:CanPlayerBuy(ply)
	return ply:IsUserGroup("prestigious") end
	return ply:IsUserGroup("donator") end
	return ply:IsUserGroup("vip") end
end

function ITEM:OnEquip(ply, modifications)
	if not ply._OldModel then
		ply._OldModel = ply:GetModel()
	end
	
	timer.Simple(1, function() ply:SetModel(self.Model) end)
end

function ITEM:OnHolster(ply)
	if ply._OldModel then
		ply:SetModel(ply._OldModel)
	end
end

function ITEM:PlayerSetModel(ply)
	ply:SetModel(self.Model)
end


I want to be able to let the person be able to keep the model for the next time they donate. I also don’t want to allow them to be able to equip it if they don’t have the required rank.

[editline]22nd December 2016[/editline]

I also use that link.

[editline]22nd December 2016[/editline]

Seems that the ends of the lines don’t work.

Oh, ok then. Try this? :smile:



ITEM.Name = 'Kleiner'
ITEM.Price = 250
ITEM.Model = 'models/player/kleiner.mdl'

function ITEM:CanPlayerBuy(ply)
	return ply:IsUserGroup("prestigious") end
	return ply:IsUserGroup("donator") end
	return ply:IsUserGroup("vip") end
end

function ITEM:CanPlayerEquip(ply)
	return ply:IsUserGroup("donator") end
	return ply:IsUserGroup("prestigious") end
	return ply:IsUserGroup("vip") end
end

function ITEM:OnEquip(ply, modifications)
	if not ply._OldModel then
		ply._OldModel = ply:GetModel()
	end
	
	timer.Simple(1, function() ply:SetModel(self.Model) end)
end

function ITEM:OnHolster(ply)
	if ply._OldModel then
		ply:SetModel(ply._OldModel)
	end
end

function ITEM:PlayerSetModel(ply)
	ply:SetModel(self.Model)
end


Doing this just made the model disappear from the pointshop.



[ERROR] addons/pointshop-master/lua/pointshop/items/donator/donatorplayermodel.lua:7: '<eof>' expected near 'end'
  1. unknown - addons/pointshop-master/lua/pointshop/items/donator/donatorplayermodel.lua:0


[editline]22nd December 2016[/editline]

So I tried doing this:


ITEM.Name = 'Kleiner'
ITEM.Price = 250
ITEM.Model = 'models/player/kleiner.mdl'

function ITEM:CanPlayerBuy(ply)
	return ply:IsUserGroup("donator", "vip", "prestigious")
end

function ITEM:CanPlayerEquip(ply)
	return ply:IsUserGroup("donator", "vip", "prestigious")
end

function ITEM:OnEquip(ply, modifications)
	if not ply._OldModel then
		ply._OldModel = ply:GetModel()
	end
	
	timer.Simple(1, function() ply:SetModel(self.Model) end)
end

function ITEM:OnHolster(ply)
	if ply._OldModel then
		ply:SetModel(ply._OldModel)
	end
end

function ITEM:PlayerSetModel(ply)
	ply:SetModel(self.Model)
end


And the model was able to show up, but VIP and Prestigious aren’t allowed to buy it.

Hmm, when you’re testing, is your rank set to one of the required ranks?
There is a property that defines who can buy the item called ITEM.AllowedUserGroups = {“groupname”}

Source

Also, this might work better:



ITEM.Name = 'Kleiner'
ITEM.Price = 250
ITEM.Model = 'models/player/kleiner.mdl'
ITEM.AllowedUserGroups = { "prestigious", "donator", "vip" }

function ITEM:CanPlayerEquip(ply)
	return ply:IsUserGroup("donator") or ply:IsUserGroup("prestigious") or ply:IsUserGroup("vip")
end

function ITEM:OnEquip(ply, modifications)
	if not ply._OldModel then
		ply._OldModel = ply:GetModel()
	end
	
	timer.Simple(1, function() ply:SetModel(self.Model) end)
end

function ITEM:OnHolster(ply)
	if ply._OldModel then
		ply:SetModel(ply._OldModel)
	end
end

function ITEM:PlayerSetModel(ply)
	ply:SetModel(self.Model)
end


[editline]22nd December 2016[/editline]

Try changing this



function ITEM:CanPlayerBuy(ply)
	return ply:IsUserGroup("donator", "vip", "prestigious")
end


function ITEM:CanPlayerEquip(ply)
	return ply:IsUserGroup("donator", "vip", "prestigious")
end


to this



function ITEM:CanPlayerBuy(ply)
	return ply:IsUserGroup("donator" or "vip" or "prestigious")
end


function ITEM:CanPlayerEquip(ply)
	return ply:IsUserGroup("donator" or "vip" or "prestigious")
end


This code makes no sense.


ITEM.AllowedUserGroups = { "prestigious", "donator", "vip" }

This is what made it work.

I’m glad it’s solved now :smile:

I know that you’re trying to help and that’s really nice of you but its like you’ve never even programmed in lua before.

I have, I’m pretty new to lua but I wrote this thread pretty early in the morning, making mistakes in the process. Sorry for any confusion.

You don’t help at all. Learn lua a bit more and then try to help. It’s not morning or mistakes in the process, you just have to learn. (not raging etc, just stop this worthless help)

Well, the issue was solved in the end?


ITEM.AllowedUserGroups = { "prestigious", "donator", "vip" }

That the actual way to do it however this would’ve worked as well :



function ITEM:CanPlayerBuy(ply)
	if ply:IsUserGroup("donator") or ply:IsUserGroup("vip") or ply:IsUserGroup("prestigious") then
               return true
        else
               ply:ChatPrint("You cannot buy this, sorry.")
               return false
        end
end


(I have done something similar to permit a model to be bought only for people with specific steamIDs and it works)