Skip to main content

Platform Post Load

Version History

Build VersionChange DateChange TypeDescription
6760422025-06-21stableCurrent version

Overview

The platformpostload.lua module provides platform-specific tweaks and configurations that are applied after the main game initialization. It avoids polluting the core game code with inline platform branching by centralizing platform-specific modifications in a dedicated module.

Purpose

This module serves as a post-initialization hook for applying platform-specific modifications including:

  • Custom voting mechanics for specific platforms
  • Localized command injection for regional markets
  • Platform-specific command modifications
  • Regional compliance adjustments

Platform Support

WIN32_RAIL Platform

Status: stable

Description: Special configuration for the Chinese WeGame/Rail platform that includes enhanced voting mechanics and Chinese language command support.

Voting System Modifications

YesNoTwoThirdsVote(params, voteresults)

Status: stable

Platform: WIN32_RAIL

Description: Custom vote result function that requires a two-thirds majority for kick votes to pass, providing enhanced player protection against vote abuse.

Parameters:

  • params (table): Vote parameters
  • voteresults (table): Vote results containing option counts

Returns:

  • (number): Vote result option (1 for yes, nil for no/insufficient)
  • (number): Vote count for the winning option

Logic:

if voteresults.options[1] >= 2 * voteresults.options[2] then
return 1, voteresults.options[1]
end

Example:

-- Applied automatically to kick command on WIN32_RAIL platform
local kick_command = UserCommands.GetCommandFromName("kick")
kick_command.voteresultfn = YesNoTwoThirdsVote

-- Example vote scenario:
-- Yes votes: 6, No votes: 2
-- 6 >= 2 * 2 (4) = true, kick passes
-- Yes votes: 5, No votes: 3
-- 5 >= 2 * 3 (6) = false, kick fails

Command Localization

RailUserCommandInject Function Calls

Status: stable

Platform: WIN32_RAIL

Description: Injects Chinese language equivalents for standard user commands to improve accessibility for Chinese players.

User Commands

The following user commands are injected with Chinese translations:

English CommandChinese CommandChinese AliasesParameters
help帮助指令-
emote表情-表情姓名
rescue救命--
kick踢出-用户
ban封禁-用户,
stopvote停止投票--
roll摇骰子-骰子
rollback回滚-保存次数
regenerate重新生成--

Example:

-- These commands become available on WIN32_RAIL platform:
RailUserCommandInject("help", "帮助", {"指令"})
RailUserCommandInject("kick", "踢出", {"用户"})
RailUserCommandInject("ban", "封禁", {"用户", "秒"})

-- Players can now use:
-- /help or /帮助 or /指令
-- /kick player or /踢出 player
-- /ban player 60 or /封禁 player 60

Emote Commands

The following emote commands are injected with Chinese translations:

English EmoteChinese EmoteAlternative
wave挥手再见
rude挑事-
happy快乐-
angry愤怒-
cry-
no-
joy喜悦-
dance舞蹈-
sit坐下-
squat蹲坐-
bonesaw-
facepalm-
kiss-
pose姿势-
toast干杯-

Example:

-- These emote commands become available:
RailUserCommandInject("wave", "挥手", nil, "再见")
RailUserCommandInject("happy", "快乐")
RailUserCommandInject("dance", "舞蹈")

-- Players can now use:
-- /wave or /挥手 or /再见
-- /happy or /快乐
-- /dance or /舞蹈

Command Removal

RailUserCommandRemove Function Calls

Status: stable

Platform: WIN32_RAIL

Description: Removes specific commands that may not be appropriate or necessary for the target platform.

Removed Commands:

  • bug: Bug reporting command removed (likely replaced with platform-specific reporting)

Example:

RailUserCommandRemove("bug")
-- The /bug command is no longer available on WIN32_RAIL platform

Platform Detection

Platform Identification

Constant: PLATFORM

Description: The module uses the global PLATFORM constant to determine the current gaming platform and apply appropriate modifications.

Supported Platforms:

  • WIN32_RAIL: Chinese WeGame/Rail platform with enhanced localization

Example:

if PLATFORM == "WIN32_RAIL" then
-- Apply Chinese platform-specific modifications
-- Enhanced voting mechanics
-- Chinese command localization
-- Regional compliance features
end

Integration Examples

Custom Platform Addition

-- Example of adding support for a new platform
if PLATFORM == "NEW_PLATFORM" then
-- Apply platform-specific modifications
local custom_vote_fn = function(params, voteresults)
-- Custom voting logic for new platform
return 1, voteresults.options[1]
end

local kick_command = UserCommands.GetCommandFromName("kick")
kick_command.voteresultfn = custom_vote_fn

-- Inject localized commands
CustomPlatformCommandInject("help", "aide")
CustomPlatformCommandInject("kick", "expulser", {"utilisateur"})
end

Voting System Integration

-- The modified voting system integrates with the existing vote infrastructure
local function HandleKickVote(voter, target)
-- Vote is initiated normally
local vote_data = {
command = "kick",
target = target,
initiator = voter
}

-- On WIN32_RAIL, YesNoTwoThirdsVote will be called automatically
-- Requires 2/3 majority instead of simple majority
TheWorld.components.voter:StartVote(vote_data)
end

Command Usage Example

-- Example of how localized commands work in practice
local function ProcessUserInput(player, command_text)
-- Both English and Chinese commands are recognized
if command_text == "/help" or command_text == "/帮助" or command_text == "/指令" then
ShowHelpDialog(player)
elseif command_text:match("^/kick") or command_text:match("^/踢出") then
ProcessKickCommand(player, command_text)
elseif command_text:match("^/wave") or command_text:match("^/挥手") or command_text:match("^/再见") then
player.components.playeractionpicker:DoAction(ACTIONS.WAVE)
end
end

Debug Information

Loading Notification

Debug Output:

Print(VERBOSITY.DEBUG, "[Loading platformpostload]")

Description: Debug message printed during module loading to confirm platform-specific modifications are being applied.

Usage:

-- Enable debug verbosity to see platform loading
c_setverbosity(VERBOSITY.DEBUG)
-- Output: [Loading platformpostload]

Dependencies

Required Modules

  • usercommands: Provides access to user command system for modifications
  • Global PLATFORM: Platform identification constant
  • RailUserCommandInject: Platform-specific command injection function
  • RailUserCommandRemove: Platform-specific command removal function

Integration Points

  • User Command System: Modifies existing commands and adds localized variants
  • Voting System: Enhances voting mechanics for specific platforms
  • Emote System: Adds localized emote commands
  • Debug System: Integrates with game's debug output system

Regional Compliance

Chinese Market Adaptations

Platform: WIN32_RAIL

Features:

  • Enhanced Vote Protection: Two-thirds majority requirement prevents vote abuse
  • Native Language Support: Full Chinese command localization
  • Cultural Adaptation: Emote commands with culturally appropriate translations
  • Regional Command Set: Platform-appropriate command availability

Best Practices

Platform-Specific Development

  1. Centralized Configuration: Keep platform modifications in dedicated modules
  2. Conditional Loading: Use platform detection to avoid unnecessary code execution
  3. Localization Support: Provide native language alternatives for user-facing commands
  4. Regional Compliance: Adapt game mechanics to meet regional requirements
  5. Debug Visibility: Include loading notifications for troubleshooting

Command Localization Guidelines

-- Good: Provide meaningful translations
RailUserCommandInject("rescue", "救命") -- "rescue" -> "help/save me"

-- Good: Include cultural alternatives
RailUserCommandInject("wave", "挥手", nil, "再见") -- "wave" -> "wave hand" or "goodbye"

// Good: Maintain consistent parameter naming
RailUserCommandInject("kick", "踢出", {"用户"}) // "user" parameter in Chinese

Security Considerations

Vote Protection

Enhanced Security: The two-thirds voting requirement on WIN32_RAIL platform provides additional protection against coordinated vote abuse, requiring broader consensus for player kicks.

Impact: Reduces false positive kicks while maintaining legitimate moderation capabilities.