Author Topic: Loop to display bottom print  (Read 1353 times)

Hello, I'm wondering how you set up a loop to display things like variables in a bottom print for all players who join the server, so if the variables for one player changes, it can show the variables in the bottom print for that player. (not everyone) I'm assuming %client is for the individual player, but I could be mistaken. I'm pretty new to coding and any help is greatly appreciated :)

The only thing I've learned how to do so far is to display chat messages when a / command is entered, to show a variable in chat;

Code: [Select]
package Gold
{
function ServerCmdGold(%client)
{
%gold = 5;
messageClient(%client,'',"<color:FFFF00>You have "@%gold@" gold.");
}
};
ActivatePackage(Gold);

why did you package it

Functions that exist are usually required to be packaged to be prevented.

Example:

Code: [Select]
package YesCommand
{
    function serverCmdYes(%this)
    {
    parent::serverCmdYes(%this);
    messageClient(%this,"You said yes!");
    }
};
activatepackage(YesCommand);
Without the package, it is more likely to mess up the function.

When doing a basic function that doesn't exist already, it doesn't really need a package.

To find out if a function exists, you can use echo(isFunction(functionName));

Custom server cmds/functions do not require packages.

Functions that exist are usually required to be packaged to be prevented.

Example:

Code: [Select]
package YesCommand
{
    function serverCmdYes(%this)
    {
    parent::serverCmdYes(%this);
    messageClient(%this,"You said yes!");
    }
};
activatepackage(YesCommand);
Without the package, it is more likely to mess up the function.

When doing a basic function that doesn't exist already, it doesn't really need a package.

To find out if a function exists, you can use echo(isFunction(functionName));
Custom server cmds/functions do not require packages.
Thank you, I didn't know; do you know how I would go about doing a loop every second or two to display variables to people on the server?

Example for MultiVariables:

Code: [Select]
function gameconnection::startTaskLoop(%this)
{
%this.VarA = 5;
%this.VarB = 3;
commandtoclient(%this,'BottomPrint',%this.VarA SPC %this.VarB,1,3);
%this.TaskLoop = %this.schedule(100, startTaskLoop);
}

Example for MultiVariables:

Code: [Select]
function gameconnection::startTaskLoop(%this)
{
%this.VarA = 5;
%this.VarB = 3;
commandtoclient(%this,'BottomPrint',%this.VarA SPC %this.VarB,1,3);
%this.TaskLoop = %this.schedule(100, startTaskLoop);
}
Please use indentation.

Example for MultiVariables:

Code: [Select]
function gameconnection::startTaskLoop(%this)
{
%this.VarA = 5;
%this.VarB = 3;
commandtoclient(%this,'BottomPrint',%this.VarA SPC %this.VarB,1,3);
%this.TaskLoop = %this.schedule(100, startTaskLoop);
}

You need to cancel your loops. Add cancel(%this.taskLoop); at the beginning.

You need to cancel your loops. Add cancel(%this.taskLoop); at the beginning.
Code: [Select]
cancel(%this.taskLoop);
function gameconnection::startTaskLoop(%this)
{
%this.VarA = 5;
%this.VarB = 3;
commandtoclient(%this,'BottomPrint',%this.VarA SPC %this.VarB,1,3);
%this.TaskLoop = %this.schedule(100, startTaskLoop);
}


Am I doing this wrong?
The console says that the script executed fine, is it a problem with the loop?

Am I doing this wrong?
The console says that the script executed fine, is it a problem with the loop?
Are you calling the function?
You need to call it for every client (%client.startTaskLoop();)
You'd probably want to package the function that's called when a client first finishes loading and spawns (I forget what it's called, you can use trace(1) to find it) and call the loop from there.

Are you calling the function?
You need to call it for every client (%client.startTaskLoop();)
You'd probably want to package the function that's called when a client first finishes loading and spawns (I forget what it's called, you can use trace(1) to find it) and call the loop from there.
Thank you, I did trace(1); and found this:

so is GameConnection::spawnPlayer() the correct function for when someone finishes loading and spawns?

Solved, thank you to headcrab zombie :)
Fixed code below if anyone needs it for their things
Code: [Select]
package firstspawn
{
        function gameconnection::oncliententergame(%this)
        {
            Parent::onClientEnterGame(%this);
            %this.startTaskLoop();
        }
};
activatepackage(firstspawn);

function gameconnection::startTaskLoop(%this)
 {
    cancel(%this.taskLoop);
    %this.Gold = 5;
    %this.Level = 1;
    commandtoclient(%this,'BottomPrint',"<color:FFFFFF>Gold: " @ %this.Gold @ "    Level " @ %this.Level,1,3); // 1.3 seconds
    %this.TaskLoop = %this.schedule(100, startTaskLoop);
}

Not that I am ever going to use your script, but thank you for not being selfish.