Author Topic: Displaying VCE in a GUI/HUD  (Read 1131 times)

Hello, I'm trying to get VCE variables to display in a GUI.

Code: [Select]
%error = forceRequiredAddOn("Event_Variables");
if(%error == $Error::AddOn_NotFound)
{
error("Server_AlxGUITest - required Add-On Event_Variables not found");
return;
}
if(isFile("Add-Ons/System_ReturnToBlockland/server.cs"))
{
if(!$RTB::RTBR_ServerControl_Hook)
exec("Add-Ons/System_ReturnToBlockland/RTBR_ServerControl_Hook.cs");
RTB_registerPref("level","AlxGUIPrints","$AlxGuiPrints::level","string 255","Server_AlxTestGui","",0,1);
}
else
{
if(isobject(localclientconnection))
clientCmdMessageBoxOk("Add-ons","Server_AlxGuiTest cannot run because you do not have RTB installed.");
else
error("Server_AlxGuiTest - cannot run because you do not have RTB installed.");
return;
}

package AlxGUIPrints
{
function GameConnection::spawnPlayer(%this)
{
%ret = Parent::spawnPlayer(%this);
%this.schedule(150,AlxGuiPrints);
return %ret;
}
function VariableGroup::setVariable(%group,%type,%name,%value,%obj) //for all non-special changes
{
Parent::setVariable(%group,%type,%name,%value,%obj);
if(%obj.getClassName() $= "Player")
%obj.client.AlxGuiPrints();
if(%obj.getClassName() $= "GameConnection")
%obj.AlxGuiPrints();
if(%obj.getClassName() $= "SetValue")
%obj.AlxGuiPrints();
}
function GameConnection::setScore(%this,%score) //for <var:cl:score> changes
{
%ret = Parent::setScore(%this,%score);
%this.AlxGuiPrints();
return %ret;
}
function Player::changeDatablock(%this,%data,%c) //for <var:pl:datablock> and <var:pl:maxhealth> changes
{
%ret = Parent::changeDatablock(%this,%data,%c);
if(isObject(%this.client))
%this.client.AlxGuiPrints();
return %ret;
}
function serverCmdUseTool(%client,%slot) //for <var:pl:currentitem> changes
{
Parent::serverCmdUseTool(%client,%slot);
%client.AlxGuiPrints();
}
function serverCmdUnUseTool(%client) //for <var:pl:currentitem> changes
{
Parent::serverCmdUnUseTool(%client);
%client.AlxGuiPrints();
}
function serverCmdUseSprayCan(%client,%color) //for <var:pl:currentitem> changes
{
Parent::serverCmdUseSprayCan(%client,%color);
%client.AlxGuiPrints();
}
function serverCmdUseFXCan(%client,%id) //for <var:pl:currentitem> changes
{
Parent::serverCmdUseFXCan(%client,%id);
%client.AlxGuiPrints();
}
function Armor::onDamage(%data,%this,%damage) //for <var:pl:health> and <var:pl:damage> changes
{
%ret = Parent::onDamage(%data,%this,%damage);
if(isObject(%this.client))
%this.client.AlxGuiPrints();
return %ret;
}
};
activatePackage(AlxGuiPrints);

function GameConnection::AlxGuiPrints(%this)
{
leveltext.SetValue("Level " @ $AlxGuiPrints::level);
}
(I took most of this code from Chrono's VCE HUD prints if you are wondering.)

leveltext is the text in the HUD, it successfully changes, but displays <var:cl:level> which I set in the RTB prefs, however I want it to display the variable.
Any help with this would be fantastic :)

« Last Edit: July 04, 2013, 10:07:37 AM by alex dude »

Note that displaying variables in a GUI needs to be handled client sided generally, while VCE variables are stored server side.

You would need to send a commandtoClient('function', "information"); in order to transfer the variables.
The client would then need a mod to accept that clientcmd, just as the server needs a servercmd to accept /commands.

Note that displaying variables in a GUI needs to be handled client sided generally, while VCE variables are stored server side.

You would need to send a commandtoClient('function', "information"); in order to transfer the variables.
The client would then need a mod to accept that clientcmd, just as the server needs a servercmd to accept /commands.
Oh right, do you have a quick example, or know of any add-ons which use this?

Oh right, do you have a quick example, or know of any add-ons which use this?
Code: (Server.cs) [Select]
function serverCmdGimmeMyToast(%client)
{
commandToClient(%client, 'giveToast', %client.toast);
}
Code: (Client.cs) [Select]
function clientCmdGiveToast(%toast)
{
echo("We have" SPC %toast SPC "piece(s) of toast!");
}

Alright, so there is a client GUI and a seperate server script now.
In the client:
Code: [Select]
$ALXGUI_HUD_toggleStatus = 0;
function ALXRPG_toggleHUD(%val, %client)
{
commandtoserver('GetVCEStuff');
if(%val == 0)
return;

$ALXGUI_HUD_toggleStatus = !$ALXGUI_HUD_toggleStatus;

if($ALXGUI_HUD_toggleStatus == 1)
{
ALXGUI.visible = false;
}
else
{
ALXGUI.visible = true;
}
}

function clientCmdRPG_SetData(%gold)
{
ALXGUI_Gold.setText(%gold);
}

In the server.cs :

Code: [Select]
function serverCmdGetVCEStuff(%client)
{
        %gold = "<var:cl:Gold>";
        commandtoclient(%client,'RPG_SetData',%gold @ "Gold");

}


The problem is (i'm guessing) that I need a function or something for it to link in to VCE

Is whats displayed currently

I looked through VCE's code and found this function;
Code: [Select]
function VariableGroup::getVariable(%group,%type,%name,%obj)
{
if(!isObject(%group) || $VCE::Server::SpecialVar[%obj.getClassName(),%name] !$= "")
return;
return %group.value[%type,%obj,%name];
}
The question is now, how would I implement it to display the variable? (that's if this is right)


when you put "<var:cl:Gold>" in quotes like that, it sends that information as a literal string, so just the text.

You need to look at how data is actually stored in the VCE system.  My recommendation is, as usual, to manage the variables yourself and not integrate events in any way.  For a small scale add-on where this is not practical, however, you need:
1. The brickgroup that stores the VCE information you want (each brickgroup has its own set of VCE variables)
2. The type of variable you want
3. The name of the variable you want