No flash (memory write)
Keeps the local player's flashbang alpha at 0, so a flash does not whiten the screen. It exists to show how a script that writes the game's memory is structured, and what the host does to keep that safe.
Permissions: memory, memory_write. API: 1.1.
--@name No flash
--@version 1.0.0
--@author wolfhack docs
--@api 1.1
--@permissions memory,memory_write
--@description Keeps your flashbang alpha at 0 so a flash does not whiten the screen. Writes game memory: read the warning in the guide first.
-- Needs three things before it does anything: (1) this script's memory and memory_write permissions granted on the Scripts page,
-- (2) the master switch "Let scripts write game memory" on the Scripts page, (3) a match. When you switch the script off the host puts
-- the original value back by itself.
local OFFSET_KEY = "C_CSPlayerPawnBase->m_flFlashMaxAlpha"
local off -- looked up once the overlay knows it
ui.tab("No flash", function()
ui.card("No flash", function()
ui.toggle("enabled", "No flash", true)
local can = mem.can_write()
ui.note(can and "Writes are on." or "Writes are off: grant memory_write to this script and switch on the master switch.")
end)
end)
events.on("frame", function()
if not store.get("enabled", true) then
if mem.writes() > 0 then mem.undo_all() end -- toggled off: put the game's value back at once
return
end
if not mem.can_write() then return end -- permission or master switch missing: do nothing (no error spam)
off = off or mem.offset(OFFSET_KEY)
local pawn = mem.global("local_pawn")
if not (off and pawn) then return end -- no offset yet, or not in a match
local alpha = mem.read_f32(pawn + off)
if alpha and alpha > 0 then
mem.write_f32(pawn + off, 0.0)
end
end)Running it#
- Install the file (see example scripts).
- Select the script and switch on memory and memory_write under Permissions.
- On the left of the Scripts page switch on Let scripts write game memory.
- Switch the script on and join a match. Throw a flash at yourself to see the difference.
Until all three are in place the tab says "Writes are off" and the script does nothing, without producing errors.
How it works#
Find the field. mem.offset("C_CSPlayerPawnBase->m_flFlashMaxAlpha") looks up the offset in the overlay's own schema table. It returns nil if this game build does not have it, so the script keeps trying until it is found and never writes to a guessed address. mem.global("local_pawn") is the address of the local player's pawn, or nil outside a match.
Read before you write. mem.read_f32(addr) returns the current value or nil. The script only writes when the alpha is above 0, so it makes a write only when the game has just raised it, not 144 times a second.
Check mem.can_write(). A denied write raises an error, and forty errors in twenty seconds stop the script. mem.can_write() returns whether the permission is granted and the master switch is on, so the script can wait quietly. This is the pattern to copy.
Undo. The host remembers the bytes each write replaced, and puts them back when the script stops: switched off, reloaded, removed, stopped by the host, or when you take the permission or the master switch away. The toggle on the tab calls mem.undo_all() so turning "No flash" off restores the game's value at once without stopping the script.
One entry per address. Writing the same address again does not grow the undo list; the host keeps the first original and the latest written value.
What can go wrong#
- The offset or the pawn is
nil: nothing happens. The script does not guess. - The game changed the value itself after your write: on undo the host leaves it as the game has it.
- The game restarted: old writes are forgotten, not undone into the new process.
- A game update moved the field:
mem.offsetmay returnnilor a different offset. Check the offsets still match before trusting any memory script after an update.
See mem for the full reference and permissions for the limits.