Skip to content

autumngmod/cream-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cream-api

Small module that adds functions that allow communication between cream (Garry's Mod) and JavaScript.

Installation

npm i @autumngmod/cream-api
# or using bun
bun i @autumngmod/cream-api

Usage example

Calling Lua function from JS

import { call } from "@autumngmod/cream-api";

// calls the 'getUsername' function in Garry's Mod
// which returns to JavaScript the LocalPlayer's username
let username: string = await call("getUsername");

console.log(`LocalPlayer's username is ${username}`);

Listening for a event

import { listen } from "@autumngmod/cream-api";
import { useState } from "react";

// payload of a event
interface MenuOpenedEvent {
  state: boolean
}

function ExampleComponent() {
  const [isOpen, setIsOpen] = useState(false);

  listen<MenuOpenedEvent>("changeMenuOpened", e => {
    setIsOpen(e.state)
  })

  return (
    <div hidden={!isOpen}>
      {...}
    </div>
  )
}

About

TypeScript npm module for cream

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published