Author Topic: GUI displaying a variable?  (Read 3450 times)

I wanted something where I could have a gui then have something that says
Wood: X/10

How would I make X take on the role of a variable named
Code: [Select]
%client.player.Roleplay["Lumber"]
Edit: I have yet to find a mod that displays a variable in a gui.

client.cs
Code: [Select]
function clientCmdUpdateLumber(%amount)
{
        TextControl.setText("Lumber: " @ %amount);
}
server.cs
Code: [Select]
commandToClient(%client,'UpdateLumber',%client.player.Roleplay["Lumber"]);

client.cs
Code: [Select]
function clientCmdUpdateLumber(%amount)
{
        TextControl.setText("Lumber: " @ %amount);
}
server.cs
Code: [Select]
commandToClient(%client,'UpdateLumber',%client.player.Roleplay["Lumber"]);
So, from my tree cutting code. This is just a snip.
Code: [Select]
if(getRandom(1, 100) > 80)
{
%this.resources--;
%client.player.Roleplay["Lumber"] += 1;
commandToClient(%client,'UpdateLumber',%client.player.Roleplay["Lumber"]);
Is that where I would put your line?

And for the GUI thing, would I replace Textcontrol with the GUI Variable's name?

So, from my tree cutting code. This is just a snip.
Code: [Select]
if(getRandom(1, 100) > 80)
{
%this.resources--;
%client.player.Roleplay["Lumber"] += 1;
commandToClient(%client,'UpdateLumber',%client.player.Roleplay["Lumber"]);
Is that where I would put your line?

And for the GUI thing, would I replace Textcontrol with the GUI Variable's name?
You name the GUI's TextCtrl then replace TextControl with the GUI TextCrontol Name.

I got it working. I want to finish all my GUI and then release the GUI so people can play in my server, but how do I force the player's client to have the client_HeedGUI.zip in their addons folder or to have the GUI data registered?

Also, what about closing with the same keybind. I have a key set to G for the resource gui. How do I make it so when I push G, it opens the gui, then I push it again and it closes it? THis is what I have so far.
Code: [Select]
if (!$ResourceBinds)
{
$remapDivision[$remapCount] = "RPG";
$remapName[$remapCount] = "Resource GUI";
$remapCmd[$remapCount] = "Resource_Open";
$remapCount++;
$ResourceBinds = 1;
}

function Resource_Open(%x)
{
if(%x)
{ if(!Resource.isAwake())
{
canvas.pushDialog(ResourceGUI);
}
else
{
canvas.popDialog(ResourceGUI);
}
}

}
« Last Edit: January 19, 2010, 08:56:48 PM by heedicalking »

Code: [Select]
if (!$[GuiName]Bindings)
{
   $remapDivision[$remapCount] = "[GuiName]";
   $remapName[$remapCount] = "Activate/Deacticate";
   $remapCmd[$remapCount] = "[GuiName]Toggle";
   $remapCount++;
   $[GuiName]Bindings=true;
}

So you can bind a key to the GUI, which I would suggest, but if you insist on it being 'G' then

Code: [Select]
GlobalActionMap.bindCmd(keyboard, "G", "", "toggle[GuiName]();");

function toggle[GuiName]()
{
   if([GuiName].isAwake())
      canvas.popDialog([GuiName]);
   else
      canvas.pushDialog([GuiName]);
}

I got the other stuff working. what about a gui like the healthbbar that does not effect gameplay but is on screen

a gui like the healthbbar that does not effect gameplay but is on screen
Wait what? I think I might know what you mean, but can you say exactly what you want this gui to do or have?

Wait what? I think I might know what you mean, but can you say exactly what you want this gui to do or have?
You know how when you press the excape menu and stuff, you can;t shoot, scroll through weapons, or jet because the mouse is activate and the gui is open. I want a gui like the player's energy bar. It is there but it doesn't stop you from jumping, shooting and stuff. Sort of like when you play any other game. There is the on screen overlay showing the time, points, radar and stuff but you can still move around. When you hit esc, pause or whatever, a menu pops up and you stop moving. I want an overlay type gui.

How do I find out who pushed the GUI? I am making a shop gui and need to know who pushed the button.
Code: [Select]
function BuyArrow()
{
commandToClient(%client, 'centerPrint' , "\c6Lumber obtained. Lumber is " @ %client.player.Roleplay["Lumber"] @ "", 1);
}
I need to make it know who %client is.

I got it working. I want to finish all my GUI and then release the GUI so people can play in my server, but how do I force the player's client to have the client_HeedGUI.zip in their addons folder or to have the GUI data registered?

Code: [Select]
function servercmdHasHeedGUI(%this)
{
          $HasHeedGUI[%this] = 1;
}
function GameConnection::autoAdminCheck(%this)
{
          parent::autoAdminCheck(%this);
          commandToClient(%this,'hasHeedGUI');
          if(!$HasHeedGUI[%this]) { %this.delete("You need Heed's GUI to play on this server."); }
}

Client
Code: [Select]
function clientcmdHasHeedGUI()
{
          commandToServer('HasHeedGUI');
}

Didn't test, but should work.

1. The time it takes for the client to receive 'hasHeedGui' and then send it back as a server command depends on their ping, and it will take much longer then 0-7 milliseconds (the average time for each line to be evaled) unless the client is the host, because pings usually range from 40-1000 if they're not living in the host's street. 'hasHeedGui' needs to be sent with the client's request, similar to how RTB sends the information to the server saying the client has RTB. To do this, look through RTB's code. (not sure which module, but I've seen it)
2. autoAdminCheck needs to be packaged.

Code: [Select]
function servercmdHasHeedGUI(%this)
{
          $HasHeedGUI[%this] = 1;
}
function GameConnection::autoAdminCheck(%this)
{
          parent::autoAdminCheck(%this);
          commandToClient(%this,'hasHeedGUI');
          if(!$HasHeedGUI[%this]) { %this.delete("You need Heed's GUI to play on this server."); }
}

Client
Code: [Select]
function clientcmdHasHeedGUI()
{
          commandToServer('HasHeedGUI');
}

Didn't test, but should work.

It's laughable that you wander around announcing that you've "finished learning to script" and you can make anything, then you write something like that. :cookieMonster:

It's laughable that you wander around announcing that you've "finished learning to script" and you can make anything, then you write something like that. :cookieMonster:
Not even to mention his website is crap, and he doesn't know how to link an image in his signature.

1. The time it takes for the client to receive 'hasHeedGui' and then send it back as a server command depends on their ping, and it will take much longer then 0-7 milliseconds (the average time for each line to be evaled) unless the client is the host, because pings usually range from 40-1000 if they're not living in the host's street. 'hasHeedGui' needs to be sent with the client's request, similar to how RTB sends the information to the server saying the client has RTB. To do this, look through RTB's code. (not sure which module, but I've seen it)
2. autoAdminCheck needs to be packaged.

1. You could always add a schedule depending on .getPing()
2. The code is a small piece, which is meant to be inserted in a package.