claude-sonnet-4-20250514· Anthropic LMArena Human Preference 140K
so can you make me something for tick
- User
so can you make me something for tick
- Assistant
Here's a tick system for your StatusEffect class:
local StatusEffect = {} StatusEffect.__index = StatusEffect function StatusEffect.new(name, duration, onApply, onTick, onExpire, stackable) local self = setmetatable({}, StatusEffect) self.Name = name self.Duration = duration self.onApply = onApply or function(target) end self.onTick = onTick or function(target, dt) end self.onExpire = onExpire or function(target, expired) end self.Stackable = stackable or false self.Elapsed = 0 self.Active = false self.Target = nil return self end function StatusEffect:apply(target) self.Target = target self.Active = true self.Elapsed = 0 self.onApply(target) end function StatusEffect:tick(deltaTime) if not self.Active then return end self.Elapsed = self.Elapsed + deltaTime self.onTick(self.Target, deltaTime) if self.Elapsed >= self.Duration then self:expire() end end function StatusEffect:expire() if not self.Active then return end self.Active = false self.onExpire(self.Target, true) end function StatusEffect:remove() if not self.Active then return end self.Active = false self.onExpire(self.Target, false) -- false = manually removed, not expired end function StatusEffect:isActive() return self.Active end function StatusEffect:getRemainingTime() return math.max(0, self.Duration - self.Elapsed) end return StatusEffectAnd here's a simple tick manager to handle multiple status effects:
local StatusEffectManager = {} StatusEffectManager.__index = StatusEffectManager function StatusEffectManager.new() local self = setmetatable({}, StatusEffectManager) self.effects = {} return self end function StatusEffectManager:addEffect(statusEffect) table.insert(self.effects, statusEffect) end function StatusEffectManager:removeEffect(statusEffect) for i, effect in ipairs(self.effects) do if effect == statusEffect then effect:remove() table.remove(self.effects, i) break end end end function StatusEffectManager:tick(deltaTime) -- Iterate backwards to safely remove expired effects for i = #self.effects, 1, -1 do local effect = self.effects[i] effect:tick(deltaTime) -- Remove inactive effects if not effect:isActive() then table.remove(self.effects, i) end end end function StatusEffectManager:getActiveEffects() local active = {} for _, effect in ipairs(self.effects) do if effect:isActive() then table.insert(active, effect) end end return active end function StatusEffectManager:hasEffect(name) for _, effect in ipairs(self.effects) do if effect:isActive() and effect.Name == name then return true end end return false end return StatusEffectManagerUsage example:
local StatusEffect = require(path.to.StatusEffect) local StatusEffectManager = require(path.to.StatusEffectManager) -- Create a manager local effectManager = StatusEffectManager.new() -- Create a poison effect local poisonEffect = StatusEffect.new( "Poison", 5, -- 5 seconds function(target) print(target.Name .. " is poisoned!") end, function(target, dt) -- Deal damage every tick target.Health = target.Health - (10 * dt) -- 10 damage per second print(target.Name .. " takes poison damage! Health: " .. target.Health) end, function(target, expired) if expired then print(target.Name .. " recovers from poison.") else print(target.Name .. "'s poison was cured.") end end, false ) -- Apply the effect to a target local player = {Name = "Player", Health = 100} poisonEffect:apply(player) effectManager:addEffect(poisonEffect) -- In your game loop, call this every frame: -- effectManager:tick(deltaTime)If you're using Roblox, you could connect it to RunService like this:
local RunService = game:GetService("RunService") local connection connection = RunService.Heartbeat:Connect(function(deltaTime) effectManager:tick(deltaTime) end) -- To stop the tick system: -- connection:Disconnect()This system handles multiple status effects, automatically removes expired ones, and provides utility methods for checking active effects.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.