(v0.5)
Mods to "Inject" local data for other mods
Modding support utilizing online party tools to send "data".
In online party, the event "OnOnlinePartyCommand()" receives any request other players do inside a lobby, the data holds the following info:
- Command -> The data itself
- CommandChannel -> Extra layer to check to see where the command should fall into.
- Sender -> Gives you information of who send this request.
Sender is the most important part of this, every command received will always have a "Sender" defined, you will always know "who did it", a ghost that fails to send it (via things like packet loss or bad connection) is never received which by that point: The event wasn't even triggered to begin with. You can say that the Steam API does handle it pretty well!
When you install a mod, it usually comes with a GameMod file, while this GameMod file is inaccessible directly from other mods through code, you can target the file directly through other means such as "AllActors" foreach iterations.
And since "OnOnlinePartyCommand()" is a game command, every mod has access to this, which means, we can on the parent level call "OnOnlinePartyCommand()" directly (and locally).
See the snippet below for an example, overall, this demonstration gives you local data transfer to other mods, but this assumes that the mod has implemented a feature to process the data.
So why do this?
- Override mod settings, you want to make it possible to directly interact with the "mod" since it allows it.
- Allows for both local and online party features to still work thanks "Sender == None" checks, if its none, we know its a local, otherwise, its a an online player.
- More possibilities and just overall more different ways to add modding support!
// This class sends data, class SS_GameMod_DataSender extends GameMod; const GAMEMOD_CLASS_NAME = 'SS_GameMod_Example'; function OnPostInitGame() { SendLocalData(); } function SendLocalData() { local GameMod gm; foreach AllActors(class'GameMod', mod) { if(!mod.IsA(GAMEMOD_CLASS_NAME)) continue; gm = mod; break; } // Always make the Sender "None", the reason for this so we can "psychologically" tell it that this command is a local, // a Sender that failed to "send" the data (like from bad connection) is never recieved anyways. gm.OnOnlinePartyCommand("5", 'SetTimeSpeed', None); } // This class receieves data because it implements something to process. class SS_GameMod_Example extends GameMod; event OnOnlinePartyCommand(string Command, Name CommandChannel, Hat_GhostPartyPlayerStateBase Sender) { // In other words, this mod refuses any "online" player request, and will only accept local data being transfered from other mods. // Realistically, you can implement for both, one that manages online and local by checking if its "None". if(Sender != None) return; switch(CommandChannel) { case 'SetTimeSpeed': SetTimeSpeed(float(command)); break; default: Print("Invalid command received!"); } } function SetTimeSpeed(float speed) { Print("Setting speed to" @ speed); // do stuff idk } final function Print(const string msg) { local WorldInfo wi; wi = class'WorldInfo'.static.GetWorldInfo(); if (wi != None) { if (wi.GetALocalPlayerController() != None) wi.GetALocalPlayerController().TeamMessage(None, "[DEBUG" @ Class.Name $ "]" @ msg, 'Event', 6); else wi.Game.Broadcast(wi, "[DEBUG" @ Class.Name $ "]" @ msg); } }