• Entity limit
    6 replies, posted
Hi! I'm making a tablet swep for my addon but i got a small problem. How can i make some kind of spawned entity limit.(Like i bought an entity from tablet and if entity count >= max then display warning about limit reached)
You specify a max count variable somewhere, then in the buy function you will have another variable for every item, default will be 0, and you will raise the value by 1 everytime you buy the item. Then in the buy function check for the limit and if you hit the limit, dont allow the player to buy it.
So it works but because of dumb me i forgot to ask how to make it apply to player? So if a player have bought an entity from tablet and if ent coun >= max then display error.
Store the number of entities bought on the player entity. Ex. local tItems = pPlayer.m_tItemCounts if (tItems == nil) then tItems = {} pPlayer.m_tItemCounts = tItems end tItems["some_item"] = (tItems["some_item"] or 0) + 1
I would use this approach or something similar: local Limits = {Default = 10} Limits.entity_name = 5 local function BuyEntity(ply, Name) if !IsValid(ply) then return end ply.boughtItems = ply.boughtItems or {} if (ply.boughtItems[Name] or 0) > (Limits[Name] or Limits.Default) then return end ply.boughtItems[Name] = (ply.boughtItems[Name] or 0) + 1 end BuyEntity( Entity( 1 ) , "entity_name" )
But what if ent is removed or destroyed? I guess i need to use entity:OnRemove hook?
You can use an EntityRemoved hook.
Sorry, you need to Log In to post a reply to this thread.