Entity Simple.Timer Problem

Hello people, I wanted to make a Simpel timer that set’s a delay on the self:Use but i dont seem to get it work, so i need help from you guys. Here is the codes from the entity im making, if you need more information about the entity just ask.

Here is the code:


function ENT:Use(activator,caller)
	if (activator:Team() == TEAM_POLICE or TEAM_ACOP or TEAM_ASCOP or TEAM_SPOLICE or TEAM_GPOLICE or TEAM_CHIEF) then
	GAMEMODE:Notify(activator, 1, 4, "You recharged you're combine suit to maxium power.")
	activator:SetArmor(100)
	activator:SetHealth(200)
	self:EmitSound("npc/roller/mine/rmine_chirp_quest1.wav");
	return
end

end

So can someone please tell me how to do it, i dont think Self:Use = false in on Gmod13 anymore or something because i tried that.

edit: My if(activator:Team() == dosent work either, all teams can use the entity, i hope someone can help.


local AllowedTeams = {TEAM_POLICE, TEAM_ACOP, TEAM_ASCOP, TEAM_SPOLICE, TEAM_GPOLICE, TEAM_CHIEF}

local ENT.NextUse = {}

function ENT:Use(activator,caller)
	if self.NextUse[activator] and self.NextUse[activator] > CurTime() then return end -- Too early to use again!
	if table.HasValue(AllowedTeams,activator:Team()) then
		self.NextUse[activator] = CurTime() + 60 -- 1 minute delay.
		GAMEMODE:Notify(activator, 1, 4, "You recharged you're combine suit to maxium power.")
		activator:SetArmor(100)
		activator:SetHealth(200)
		self:EmitSound("npc/roller/mine/rmine_chirp_quest1.wav");
		return
	end
end

Here’s an untested way to do it. Not perfect by any means as it’ll keep track of disconnected players.



[ERROR] gamemodes/darkrp/entities/entities/suit_dispenser/init.lua:30: unexpected symbol near '.'
  1. unknown - gamemodes/darkrp/entities/entities/suit_dispenser/init.lua:0



It say’s this in console :slight_smile: Maybe you need to put “CurTime” in local ENT.NextUse = {CurTime}

Now that I think of it ENT.NextUse doesn’t need to be local. And no I’m positive I don’t need to store a function in that table. The keys are meant to be players.

ENT.NextUse can’t be local.
You cannot make local table elements.

So what you are saying is, that i should put “ENT.NextUse” In the ENT.Use Function?

What is the point of the ENT.NextUse table?

[SUB]The OP didn’t say he wanted it… and if its purpose is to prevent spam, just set the entity to usetype to SIMPLE_USE.[/SUB]

The OP didn’t indicate what type of delay he wanted. I think he meant make it so if you hold E while looking at it, it dosent keep spamming you with notifications.

If thats the case, then you should set the entity usetype to SIMPLE_USE

He did say he wanted a delay between uses of the entity.

Nope. I’m just saying that I left local next to ENT.NextUse by mistake.

When used in another function it becomes self.NextUse.

Im sorry but you are getting me all confused, could you please make a quote with the code that i need to replace my orginal code with?

Im thankfull for everyone’s help :slight_smile:

No one that can help me?