Loading...
Loading...
Register your game on Play.fun (OpenGameProtocol), add the browser SDK, and get a monetized play.fun URL
npx skill4agent add opusgamelabs/game-creator monetize-game/game-creator:make-game$ARGUMENTSpackage.jsonpackage.jsonvite.config.jsbasenode skills/playdotfun/scripts/playfun-auth.js statusTo register your game on Play.fun, you need to authenticate first.I'll start a local auth server. Click the link below to log in:
node skills/playdotfun/scripts/playfun-auth.js callback &Open this URL in your browser: https://app.play.fun/skills-auth?callback=http://localhost:9876/callbackLog in with your Play.fun account. The credentials will be saved automatically. Tell me when you're done.
node skills/playdotfun/scripts/playfun-auth.js statusIf the callback didn't work, you can paste your credentials manually. Go to your Play.fun dashboard, copy your API credentials (base64 format), and I'll save them:node skills/playdotfun/scripts/playfun-auth.js manual <your-base64-credentials>
GITHUB_USER=$(gh api user --jq '.login' 2>/dev/null)
REPO_NAME=$(basename $(git remote get-url origin 2>/dev/null) .git 2>/dev/null)https://$GITHUB_USER.github.io/$REPO_NAME/vite.config.jsbasecurl -s -o /dev/null -w "%{http_code}" "$GAME_URL"package.jsonsrc/core/Constants.jsregister_gameplaydotfunPOST https://api.play.fun/games{
"name": "<game-name>",
"description": "<game-description>",
"gameUrl": "<deployed-url>",
"platform": "web",
"isHTMLGame": true,
"iframable": true,
"maxScorePerSession": <based on game scoring>,
"maxSessionsPerDay": 50,
"maxCumulativePointsPerDay": <reasonable daily cap>
}maxScorePerSession: 100-500maxScorePerSession: 500-2000maxScorePerSession: 1000-5000Your game is registered on Play.fun! Game ID:Name:<uuid><name>
index.html# Read API key from agent config (stored by playfun-auth.js)
# Example path for Claude Code — adapt for your agent
API_KEY=$(cat ~/.claude.json | jq -r '.mcpServers["play-fun"].headers["x-api-key"]')
echo "User API Key: $API_KEY"</head><meta name="x-ogp-key" content="<USER_API_KEY>" />
<script src="https://sdk.play.fun/latest"></script>x-ogp-keyUSER_API_KEY_HEREsrc/playfun.js// src/playfun.js
// Play.fun (OpenGameProtocol) integration
// Wires game events to Play.fun points tracking
import { eventBus, Events } from './core/EventBus.js';
const GAME_ID = '<game-uuid>';
let sdk = null;
let initialized = false;
export async function initPlayFun() {
if (typeof OpenGameSDK === 'undefined' && typeof PlayFunSDK === 'undefined') {
console.warn('Play.fun SDK not loaded — skipping monetization');
return;
}
const SDKClass = typeof PlayFunSDK !== 'undefined' ? PlayFunSDK : OpenGameSDK;
sdk = new SDKClass({
gameId: GAME_ID,
ui: { usePointsWidget: true },
});
await sdk.init();
initialized = true;
console.log('Play.fun SDK initialized');
wireEvents();
}
function wireEvents() {
// Award points on score changes
// addPoints() buffers points locally — call frequently during gameplay
if (Events.SCORE_CHANGED) {
eventBus.on(Events.SCORE_CHANGED, ({ score, delta }) => {
if (sdk && initialized && delta > 0) {
sdk.addPoints(delta);
}
});
}
// Save points on game over
// savePoints() opens a BLOCKING MODAL — only call at natural break points:
// - Game over
// - Level complete
// - User returns to menu
// DO NOT call savePoints() during active gameplay or on a timer!
if (Events.GAME_OVER) {
eventBus.on(Events.GAME_OVER, () => {
if (sdk && initialized) {
sdk.savePoints(); // Uses buffered points from addPoints() calls
}
});
}
// Save on page unload (non-blocking, browser handles it)
window.addEventListener('beforeunload', () => {
if (sdk && initialized) {
sdk.savePoints();
}
});
}| Method | When to use | Behavior |
|---|---|---|
| During gameplay | Buffers points locally, non-blocking |
| Game over / level end | Opens blocking modal, syncs buffered points to server |
savePoints()EventBus.jsSCORE_CHANGEDscore:changed{ score, delta }{ score }GAME_OVERgame:oversrc/main.jsimport { initPlayFun } from './playfun.js';
// After game initialization
initPlayFun().catch(err => console.warn('Play.fun init failed:', err));initPlayFun()cd <project-dir> && npm run buildcd <project-dir> && npx gh-pages -d distnpm run deploycurl -s -o /dev/null -w "%{http_code}" "$GAME_URL"Your game is monetized on Play.fun!Play your game:View on Play.fun:<game-url>https://play.fun/games/<game-uuid>What's live:
- Points widget overlay (bottom-right corner)
- Leaderboard tracking
- Wallet connect for claiming rewards
- Points buffered during gameplay, saved on game over
Share on Moltbook: Post your game URL to moltbook.com — 770K+ agents on the agent internet ready to play and upvote.Next steps:
- Launch a playcoin for your game (token rewards for players)
- Check your leaderboard on Play.fun
- Share the play.fun URL on social media