Revision Difference
Global.IsFirstTimePredicted#560130
<function name="IsFirstTimePredicted" parent="Global" type="libraryfunc">
<description>
Returns if this is the first time this hook was predicted.
This is useful for one-time logic in your SWEPs PrimaryAttack, SecondaryAttack and Reload and other (to prevent those hooks from being called rapidly in succession). It's also useful in a Move hook for when the client predicts movement.
Visit <page>Prediction</page> for more information about this behavior.
<note>This is already used internally for <page>Entity:EmitSound</page>, <page>Weapon:SendWeaponAnim</page> and <page>Entity:FireBullets</page>, but NOT in <page>util.Effect</page>.</note>
</description>
<realm>Shared</realm>
<rets>
<ret name="" type="boolean">Whether or not this is the first time being predicted.</ret>
</rets>
</function>
<example>
<description>An override for <page>GM:KeyPress</page> in the gamemode Trouble in Terrorist Town, to work around the hook being called multiple times.</description>
<description>An override for <page>GM:KeyPress</page>, to work around the hook being called multiple times.</description>
<code>
-- Note that for some reason KeyPress and KeyRelease are called multiple times
-- for the same key event in multiplayer.
function GM:KeyPress(ply, key)
if not IsFirstTimePredicted() then return end
if not IsValid(ply) or ply != LocalPlayer() then return end
if key == IN_SPEED and ply:IsActiveTraitor() then
if key == IN_SPEED then
timer.Simple(0.05, function() RunConsoleCommand("+voicerecord") end)
end
end
</code>
</example>