Giter Club home page Giter Club logo

statehandler's Introduction

Statehandler

Documentation

bit outdated, new api.

Fetching module

-- SERVER
local StateHandler = require(path.to.StateHandler).GetServer()

-- CLIENT
local StateHandler = require(path.to.StateHandler).GetClient()

Shared Syntax:

Statehandler.HasState(Instance: Instance, State: string) -> boolean

-- Called whenever state is added (Duration is present) and whenever it is removed (Duration is nil)
StateHandler.AddListener(State:string, Callback: (Instance: Instance, Duration:number?) -> nil)

-- Fires each heartbeat while state is active
StateHandler.AddListenerStepped(State:string, Callback: (DeltaTime:number, Instance: Instance, Duration:number) -> nil)

Server

-- add state for a duration
-- duration can also be math.huge to replicate a boolean state
--[[
    if first argument is a player or an array with players it'll only fire State info" for those player(s)
        State will be hidden to other players
    
    These cannot stack states, only overwrite
]]
StateHandler.AddState(Instance: Instance | {Instance} | Player | {Player}, State: string, Duration: number)

-- remove state 
StateHandler.RemoveState(Instance: Instance, State: string, Duration: number)

Client

StateHandler.RequestData() -> nil
-- Request server with data, should be called only once

Examples

Poison Example

-- SERVER
local Players = game:GetService("Players")

local Statehandler = require(path.to.StateHandler).GetServer()

Statehandler.AddListenerStepped("Poison", function(dt, Player:Player, duration)
    if Player and Player.Character and Player.Character:FindFirstChild("Humanoid") then
        -- use delta time to consitently apply poison
        Player.Character.Humanoid.Health -= (5 * dt)
    end
end)

Players.PlayerAdded:Connect(function(Player)
 Player.CharacterAdded:Connect(function(char)
        -- Poison is active for 5 seconds
        Statehandler.AddState(Player, "Poison", 5)
    end)
end)

CLIENT

local Statehandler = require(game.ReplicatedStorage.Statehandler).GetClient()

Statehandler.AddListener('Poison', function(Instance:Player, number)
    if number then
        print("Is Active")
    else
        print("Is not active")
    end
end)

Statehandler.RequestData()

statehandler's People

Contributors

stenimated avatar

Stargazers

Pada avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.