5.0 KiB
5.0 KiB
Moddio World Setup Guide for BetFun Arena
Overview
This document explains how to set up and configure the Moddio multiplayer game world for BetFun Arena.
World Configuration
1. Create New World
- Go to Moddio Studio
- Create a new blank world
- Name it "BetFun Arena Battle"
2. World Settings
{
"name": "BetFun Arena Battle",
"description": "Live prediction market battles",
"maxPlayers": 100,
"worldSize": "1024x1024",
"backgroundColor": "#000000"
}
3. Assets Setup
Upload the following assets from /moddio/assets/:
yes_zone.png- Green zone for "Yes" teamno_zone.png- Red zone for "No" teamplayer_spritesheet.png- Player avatarsconfetti_green.particle- Victory effect for Yes winsconfetti_red.particle- Victory effect for No winswhale_explosion.particle- Effect for bets > 10 SOL
4. Game Scripts
Player Join Script
// When player joins, assign to team based on outcome
actions.on("playerJoinsGame", function(player) {
// Get outcome from URL parameter
const outcome = player.getVariable("outcome");
const arenaId = player.getVariable("arenaId");
// Assign player to team zone
if (outcome == 0) {
// Yes team - green zone
player.setPosition(256, 512);
player.setColor("#39FF14");
} else {
// No team - red zone
player.setPosition(768, 512);
player.setColor("#DC143C");
}
// Set player username from wallet
const wallet = player.getVariable("wallet");
player.setName(wallet.substring(0, 8) + "...");
});
Big Bet Alert Script
// Listen for big bet events
actions.on("bigBetPlaced", function(data) {
const { wallet, amount, outcome } = data;
// Trigger whale explosion effect
if (amount > 10000000000) { // > 10 SOL
effects.play("whale_explosion", getPlayerPosition(wallet));
// Global chat message
chat.broadcast(`๐ WHALE ALERT! ${wallet} bet ${amount/1e9} SOL!`);
}
// Emoji rain
effects.emojiRain(outcome == 0 ? "๐ฅ" : "๐");
});
Victory Resolution Script
// When arena is resolved
actions.on("arenaResolved", function(data) {
const { winnerOutcome } = data;
// Play confetti for winning team
if (winnerOutcome == 0) {
effects.play("confetti_green", { x: 256, y: 512 });
chat.broadcast("๐ YES WON! ๐");
} else {
effects.play("confetti_red", { x: 768, y: 512 });
chat.broadcast("๐ NO WON! ๐");
}
// Highlight winners
players.forEach(function(player) {
if (player.getVariable("outcome") == winnerOutcome) {
player.addEffect("glow", { color: "#FFD700", duration: 5000 });
}
});
});
Chat System
// Enable live chat with emoji support
chat.enable({
maxLength: 100,
emojisEnabled: true,
cooldown: 2000,
profanityFilter: true
});
// Custom chat commands
chat.on("command", function(player, command, args) {
if (command == "bet") {
// Show player's bet info
const amount = player.getVariable("betAmount");
const outcome = player.getVariable("outcome");
chat.sendTo(player, `You bet ${amount} SOL on ${outcome}`);
}
});
5. World Variables
Set these variables in Moddio:
worldVars = {
arenaId: "", // Set from URL parameter
totalPot: 0, // Updated by webhook
participantsCount: 0,
outcomeDistribution: [0, 0]
};
6. Embedding in Frontend
The world is embedded using the ModdioBattle component:
<ModdioBattle
arenaId={arenaId}
wallet={publicKey?.toString()}
outcome={userOutcome}
className="w-full h-[600px]"
/>
URL format:
https://play.modd.io/{WORLD_ID}?arenaId=xxx&wallet=yyy&outcome=0
7. Webhook Integration
Set up webhook endpoint in Moddio:
POST https://betfun-indexer.railway.app/webhook/moddio
Events to send:
player.join- When player enters worldchat.message- Chat messages- Custom events from indexer
8. Publishing
- Test the world in Moddio Studio
- Click "Publish"
- Copy the World ID
- Set
NEXT_PUBLIC_MODDIO_WORLD_IDin.env - Set API secret in
NEXT_PUBLIC_MODDIO_SECRET_KEY
Testing
- Create a test arena
- Join with multiple browser windows
- Verify team assignment
- Test chat functionality
- Trigger big bet alert (use devtools)
- Test resolution effects
Screenshots
See /moddio/scripts-screenshots/ for visual examples:
player-join-team.png- Team assignmentbig-bet-whale.png- Whale alert effectvictory-resolution.png- Winner celebration
Troubleshooting
Players not joining:
- Check URL parameters are being passed correctly
- Verify World ID matches published world
Effects not showing:
- Ensure particle assets are uploaded
- Check asset names match script references
Chat not working:
- Enable chat in world settings
- Check cooldown settings
Next Steps
- Add more particle effects
- Implement powerups (boost visibility, taunt opponents)
- Add spectator mode with different camera
- Integrate voice chat (optional)
For help: support@modd.io