Difference between revisions of "Lua:speedhack setSpeed"

From Cheat Engine
Jump to navigation Jump to search
(Major overhaul of the post.)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:speedhack_setSpeed}}
+
[[Category:Lua]]
 +
{{CodeBox|'''function''' speedhack_setSpeed(''speed'') ''':''' void}}
  
[http://www.example.com link title]'''function''' speedhack_setSpeed(''speed'')
+
Enables the speedhack if needed and sets the specified speed.
 
 
Enabled the speedhack if it wasn't active yet and sets the required speed.
 
 
 
Example:
 
  speedhack_setSpeed(5)  --5 times the normal speed
 
  speedhack_setSpeed(0.5) --Half the normal speed
 
  speedhack_setSpeed(1)  --Normal speed
 
  
 +
A speed value of <code>1.0</code> represents normal speed. Values above <code>1.0</code> speed the target up, while values below <code>1.0</code> slow it down.
  
 
===Function Parameters===
 
===Function Parameters===
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
Line 18: Line 13:
 
|-
 
|-
 
|speed
 
|speed
|float
+
|Float
|The speed to set
+
|The speedhack multiplier to apply. 1.0 is normal speed.
 
|}
 
|}
  
 +
===Returns===
 +
This function does not return a value.
 +
 +
===Examples===
 +
 +
====Set normal speed====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
speedhack_setSpeed(1.0)
 +
</syntaxhighlight>
 +
 +
====Speed up the target====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
speedhack_setSpeed(2.0)
 +
</syntaxhighlight>
 +
 +
====Slow down the target====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
speedhack_setSpeed(0.5)
 +
</syntaxhighlight>
 +
 +
====Set speed from a variable====
 +
<syntaxhighlight lang="lua" line highlight="3">
 +
local speed = 3.0
 +
 +
speedhack_setSpeed(speed)
 +
</syntaxhighlight>
 +
 +
====Toggle between normal and fast speed====
 +
<syntaxhighlight lang="lua" line highlight="4,6">
 +
local fast = true
 +
 +
if fast then
 +
  speedhack_setSpeed(5.0)
 +
else
 +
  speedhack_setSpeed(1.0)
 +
end
 +
</syntaxhighlight>
 +
 +
====Use with speedhack_getSpeed====
 +
<syntaxhighlight lang="lua" line highlight="3">
 +
local currentSpeed = speedhack_getSpeed()
 +
 +
speedhack_setSpeed(currentSpeed + 0.5)
 +
</syntaxhighlight>
 +
 +
====Ask for a speed value====
 +
<syntaxhighlight lang="lua" line highlight="7">
 +
local result, value = inputQuery("Speedhack", "Enter speed multiplier:", "1.0")
 +
 +
if result then
 +
  local speed = tonumber(value)
 +
 +
  if speed ~= nil then
 +
    speedhack_setSpeed(speed)
 +
  end
 +
end
 +
</syntaxhighlight>
 +
 +
====Reset speed when disabling a script====
 +
<syntaxhighlight lang="lua" line highlight="3">
 +
[DISABLE]
 +
{$lua}
 +
speedhack_setSpeed(1.0)
 +
{$asm}
 +
</syntaxhighlight>
  
== See also ==
+
{{LuaSeeAlso}}
* [[Lua]]
 

Latest revision as of 00:45, 27 June 2026

<> Lua API Reference

function speedhack_setSpeed(speed) : void

Enables the speedhack if needed and sets the specified speed.

A speed value of 1.0 represents normal speed. Values above 1.0 speed the target up, while values below 1.0 slow it down.

Function Parameters[edit]

Parameter Type Description
speed Float The speedhack multiplier to apply. 1.0 is normal speed.

Returns[edit]

This function does not return a value.

Examples[edit]

Set normal speed[edit]

1 speedhack_setSpeed(1.0)

Speed up the target[edit]

1 speedhack_setSpeed(2.0)

Slow down the target[edit]

1 speedhack_setSpeed(0.5)

Set speed from a variable[edit]

1 local speed = 3.0
2 
3 speedhack_setSpeed(speed)

Toggle between normal and fast speed[edit]

1 local fast = true
2 
3 if fast then
4   speedhack_setSpeed(5.0)
5 else
6   speedhack_setSpeed(1.0)
7 end

Use with speedhack_getSpeed[edit]

1 local currentSpeed = speedhack_getSpeed()
2 
3 speedhack_setSpeed(currentSpeed + 0.5)

Ask for a speed value[edit]

1 local result, value = inputQuery("Speedhack", "Enter speed multiplier:", "1.0")
2 
3 if result then
4   local speed = tonumber(value)
5 
6   if speed ~= nil then
7     speedhack_setSpeed(speed)
8   end
9 end

Reset speed when disabling a script[edit]

1 [DISABLE]
2 {$lua}
3 speedhack_setSpeed(1.0)
4 {$asm}

Main Pages

Core Lua documentation entry points

Lua
Script Engine