Anti spam CurTime

I’m trying to get a anti-spam script working for a horn. I have this code, it doesn’t give errors, but doesn’t work.

[lua]
if (player:InVehicle() and key == IN_RELOAD) then
local vehicle = player:GetVehicle()
if vehicle.VehicleTable && vehicle.VehicleTable.Horn then
local AntiCmdSpam = CurTime()
if (AntiCmdSpam + 10 < CurTime()) then
player:GetVehicle():EmitSound(vehicle.VehicleTable.Horn.Sound, 100, vehicle.VehicleTable.Horn.Pitch)
AntiCmdSpam = CurTime();
end
end
end
[/lua]

What am I doing wrong?

You’re setting AntiCmdSpam before you check it every single time, in effect, CurTime() + 10 < CurTime(), which is never going to work

And tabbing.

Alright, I moved local AntiCmdSpam = CurTime() to line 2, but it still doesn’t work. Could you post the code, please?

[lua]
local AntiCmdSpam = 0

if (player:InVehicle() and key == IN_RELOAD) then
local vehicle = player:GetVehicle()
if vehicle.VehicleTable && vehicle.VehicleTable.Horn then
if (AntiCmdSpam + 10 < CurTime()) then
player:GetVehicle():EmitSound(vehicle.VehicleTable.Horn.Sound, 100, vehicle.VehicleTable.Horn.Pitch)
AntiCmdSpam = CurTime();
end
end
end
[/lua]

Although, you might want to make the AntiCmdSpam for each player different, at the moment (if this is serverside) the variable will effect everybody.

[editline]31st December 2010[/editline]

And is everything bold only for me?

It’s not bold for me.

I tried your script, I can horn, but the spam protector itself doesn’t work. The script is running serverside.

How can I make the AntiCmdSpam for each player different?