| Blockland Forums > Modification Help |
| Future add-ons should use ForceRequiredAddon differently |
| (1/1) |
| Kyuande:
For a while I have discovered that ForceRequiredAddon loves to kick the non-dedicated users telling them they should install 1 missing add-on, but doesn't tell them how many add-ons they are missing. So my solution is to make a function simply to check every add-on, unfortunately it doesn't do any chat messages (maybe I should of thought of this earlier) to tell them what they are missing. Include it as a support file or include it in your server.cs, then make a main.cs or some file to exec where the real stuff should go. Though this is a small problem for non-dedicated users it is still annoying to not be allowed to host due to missing 1 or more add-ons. --- Code: ---//Accepts both full file and add-on name (add-on name is RECOMMENDED) function isRequirementsMatched(%files, %doWarn) { echo("----------------------------------------------------------------------"); echo(" Loading required add-ons."); %fields = getFieldCount(%files); for(%i = 0; %i < %fields; %i++) { %match = isRequirementMatched(getField(%files, %i), %doWarn); %invalidMatches += (%match == 0); } if(%invalidMatches >= 1) { %curPath = strReplace(filePath($Con::File), "Add-Ons/", ""); warn(" Found " @ %invalidMatches @ " missing add-on" @ (%invalidMatches != 1 ? "s" : "") @ ", will not run " @ %curPath @ "."); echo("----------------------------------------------------------------------"); return false; } echo("----------------------------------------------------------------------"); return true; } function isRequirementMatched(%file, %doWarn) { if(isFile(%file)) { %addon = strReplace(%file, ".zip", "/server.cs"); %addonName = strReplace(filePath(%addon), "Add-Ons/", ""); } else { %addon = "Add-Ons/" @ %file @ "/server.cs"; %addonName = %file; } if(!isFile(%addon)) { warn(" Invalid add-on \"" @ %addon @ "\""); return false; } %curPath = strReplace(filePath($Con::File), "Add-Ons/", ""); if($GameModeArg $= "Add-Ons/GameMode_Custom/gamemode.txt" || $GameModeArg $= "") { %error = ForceRequiredAddOn(%addonName); if(%error == $Error::AddOn_NotFound) { if(%doWarn) { warn(" ERROR: " @ %curPath @ " - required add-on '" @ %addonName @ "' not found"); } return false; } } else { if($GameMode::LastAddOnCount $= "" || $GameMode::AddOnCount != $GameMode::LastAddOnCount) { $GameMode::LastAddOnCount = $GameMode::AddOnCount; deleteVariables("$GameMode::NameAddOn*"); for(%FC = 0; %FC < $GameMode::AddOnCount; %FC++) { $addonName = $GameMode::AddOn[%FC]; $GameMode::NameAddOn[$addonName] = 1; } } if(!isFile(%addon)) { if(%doWarn) { warn(" ERROR: " @ %curPath @ " - required add-on '" @ %addonName @ "' not found"); } return false; } if(!$GameMode::NameAddOn[%addonName]) { if(%doWarn) { warn(" WARNING: " @ %curPath @ " - required add-on '" @ %addonName @ "' not enabled in gamemode, forcing"); } exec(%addon); } } return true; } --- End code --- isRequirementsMatched(%files, %doWarn) - You can either use files or add-on names (add-on names is better); warn basically echos to the console that things are missing Example of server code: --- Code: ---if(isRequirementsMatched("Support_NewHealth\tSupport_SpeedFactor\tSupport_EEEE")) { exec("./main.cs"); } --- End code --- |
| Navigation |
| Message Index |