I have a similar approach on Maloria, although instead I make sure to load all the important classes upon login before proceeding with adding any weapons.
PHP Code:
function onActionServerSide(temp.command)
{
if (temp.command == "initialized") {
player.triggerAllWeapons("onPlayerInitialized");
player.removeWeapon(this.name);
}
}
public function loadClasses()
{
if (player.classesLoaded)
return echo(format("[%s]: Classes already loaded for player %s, aborting...", this.name, player.communityName));
temp.classList = { // Array with the classes you want to preload
};
for (temp.className: temp.classList)
player.join(temp.className);
player.classesLoaded = true;
triggerClient("gui", this.name, "loadClasses", temp.classList);
}
function onPlayerLogout(temp.playerObject)
temp.playerObject.classesLoaded = false;
//#CLIENTSIDE
const DEBUG_MODE = true;
function onActionClientSide(temp.command)
{
// Return if it's not the trigger sent from loadClasses()
if (temp.command != "loadClasses")
return;
// Return if classes has already been loaded this session
if (player.classesLoaded)
return;
temp.classList.copyFrom(params[1]);
for (temp.className: temp.classList) {
// Load the class to the player
if (!player.isInClass(temp.className)) {
player.join(temp.className);
debug(format("[%s]: Joining class '%s'...", this.name, temp.className));
}
// Maybe the class is loaded already?
if (isClassLoaded(temp.className)) {
continue;
}
loadClass(temp.className);
debug(format("[%s]: Class '%s' not loaded yet, loading...", this.name, temp.className));
while (!isClassLoaded(temp.className))
sleep(0.05);
}
player.classesLoaded = true;
debug(format("[%s]: All classes loaded!", this.name));
triggerServer("gui", this.name, "initialized");
}
function debug(temp.text)
{
if (DEBUG_MODE)
echo(temp.text);
}