Author Topic: More help on the GUI  (Read 11381 times)

That function also has no reason to be in a package, unless you're planning on deactivating it.

That function also has no reason to be in a package, unless you're planning on deactivating it.

i was hoping i could make it over-writable somehow but your right, it doesn't :P

i am having the worst time trying to get this to work...
i cant seem to get this to work properly, could someone explain what each part of the code provided means?

Client:
All your check boxes and the circles are all boonlean (forget spelling?)
You need to name each check box according to what they are to make it easy, and it's best to do a GUIUseScope_Blah format to be sure nothing is conflicting. Then you need to create a function for the done button, something like updatesettings() in UpdateSettings you need something like %UseScope=GUIname_UseScope.getValue();
Back in your client GUI code, you'll need to add onto the updateSettings function something like commandToServer('UpdateSettings','UseScope',%UseScope); and do this for each variable, ie each setting you want. So something like:
Code: [Select]
function UpdateSettings()
{
    %useScope=GUIname_useScope.getValue();
    commandToServer('UpdateSettings','UseScope',%useScope);
    %useAmmo=GUIname_useAmmo.getValue();
    commandToServer('UpdateSettings','UseAmmo',%useAmmo);
}




Server:
Then you need to make a server command function (be sure it's a server-sided script for this) like serverCmdUpdateSettings(%client,%globalVar,%value) add your admin check blah blah so it'll look something like
Code: [Select]
function servercmdUpdateSettings(%client,%globalVar,%value)
{
    if(!%client.SuperAdmin)
        return;
    switch$(%globalVar)
    {
        case UseScope:
            $UseScope = %var;
        case UseAmmo:
            $UseAmmo = %var;
    }
}

This can obviously be done way more efficiently but this is probably the easiest way.

so, for the part you want me to replace, GUIname, should this be the name provided here: new GuiControl(AdvWepsGui) or some other variable...

i currently have this in the GUI code, but dont know how you want me to set it up so its sending the right values to the client.cs for the UpdateSettings function,

Code: [Select]
           new GuiCheckBoxCtrl(ADVIronsights) {
               profile = "GuiCheckBoxProfile";
               horizSizing = "right";
               vertSizing = "bottom";
               position = "49 27";
               extent = "123 23";
               minExtent = "8 8";
               enabled = "1";
               visible = "1";
               clipToParent = "1";
               variable = "%UseScope";
               text = "Disable Iron-sights?";
               groupNum = "-1";
               buttonType = "ToggleButton";
            };

the code in my server.cs looks like:
Code: [Select]
function serverCmdADVGUI(%Client)
{
if(%client.isAdmin || %client.isSuperAdmin)
{
commandToClient(%client,'OpenADVGui');
}
}

function servercmdUpdateSettings(%client,%globalVar,%value)
{
    if(%client.isAdmin || %client.isSuperAdmin)
{
switch$(%globalVar)
{
case UseScope:
$UseScope = %var;
case UseAmmo:
$UseAmmo = %var;
}
}
}

the code in my client.cs looks like:
Code: [Select]
function clientCmdOpenADVGui()
{
    canvas.pushDialog(AdvWepsGui);
}

function UpdateADVSettings()
{
    %useScope=AdvWepsGui_useScope.getValue();
    commandToServer('UpdateSettings','UseScope',%useScope);
    %useAmmo=AdvWepsGui_useAmmo.getValue();
    commandToServer('UpdateSettings','UseAmmo',%useAmmo);
}

How can i set this up so that it applies the variables correctly to the server?
i seem to be having trouble understanding the purpose for/ syntax for the server commands here...

i am getting some console errors that look like:

Quote
Add-Ons/Weapon_Advanced_pack_V1.8/client.cs (10): Unable to find object: 'GUIname_useScope' attempting to call function 'getValue'
BackTrace: ->UpdateADVSettings


Add-Ons/Weapon_Advanced_pack_V1.8/client.cs (12): Unable to find object: 'GUIname_useAmmo' attempting to call function 'getValue'
BackTrace: ->UpdateADVSettings

Code: [Select]
           new GuiCheckBoxCtrl(ADVIronsights) {
               profile = "GuiCheckBoxProfile";
               horizSizing = "right";
               vertSizing = "bottom";
               position = "49 27";
               extent = "123 23";
               minExtent = "8 8";
               enabled = "1";
               visible = "1";
               clipToParent = "1";
               variable = "%UseScope";
               text = "Disable Iron-sights?";
               groupNum = "-1";
               buttonType = "ToggleButton";
            };

the code in my server.cs looks like:
Code: [Select]

function serverCmdADVGUI(%Client)
{
if(%client.isAdmin || %client.isSuperAdmin)
{
commandToClient(%client,'OpenADVGui');
}
}

function servercmdUpdateSettings(%client,%globalVar,%value)
{
    if(%client.isAdmin || %client.isSuperAdmin)
{
switch$(%globalVar)
{
case UseScope:
$UseScope = %var;
case UseAmmo:
$UseAmmo = %var;
}
}
}

the code in my client.cs looks like:
Code: [Select]
function clientCmdOpenADVGui()
{
    canvas.pushDialog(AdvWepsGui);
}

function UpdateADVSettings()
{
    %useScope=AdvWepsGui_useScope.getValue();
    commandToServer('UpdateSettings','UseScope',%useScope);
    %useAmmo=AdvWepsGui_useAmmo.getValue();
    commandToServer('UpdateSettings','UseAmmo',%useAmmo);
}
First servercmdUpdateSettings(%client,%globalVar,%value) has %value as the last variable, right? %client is there and gets used, %globalVar is there and gets used for the switch, but then you start tring to use %var instead of %value
As for the errors the name AdvWepsGui_useScope ins't being used on the GUI at all. So instead it should be ADVIronsights.getValue();
Last but not least having %useScope in the variable spot is wrong. When in the GUI's the variable is a global variable that it will try to change, so it sees that as $%useScope

First servercmdUpdateSettings(%client,%globalVar,%value) has %value as the last variable, right? %client is there and gets used, %globalVar is there and gets used for the switch, but then you start tring to use %var instead of %value
That one is your fault actually.

That one is your fault actually.
LOL, that's great. Another note is if a coder is helping you be sure that they actually write it down correctly.

sorry for the late response, but for this line in the GUI
Code: [Select]
               variable = "$UseScope";do i need to have a $ or not?

it seems to me like %value has no value at all, what are you trying to do with that?

my server scripts look like:
Code: [Select]
    if(%client.isAdmin || %client.isSuperAdmin)
{
switch$(%globalVar)
{
case UseScope:
$UseScope = %value;
case UseAmmo:
$UseAmmo = %value;
case FarSound:
$FarSound = %value;
case CommandReload:
$CommandReload = %value;
case StartingAmmo:
$StartingAmmo = %value;
}
}
else
{
CommandToClient(%Client,'CenterPrint',"You are not an admin",2);
}

client like:
Code: [Select]
function UpdateADVSettings()
{
%useScope = ADVIronsights.getValue();
    commandToServer('UpdateADVSettings','UseScope',%useScope);

%FarSound = ADVEchoSound.getValue();
    commandToServer('UpdateADVSettings','FarSound',%FarSound);

%CommandReload = ADVLightKey.getValue();
    commandToServer('UpdateADVSettings','CommandReload',%CommandReload);

%UseAmmo = ADVAmmoSys.getValue();
    commandToServer('UpdateADVSettings','UseAmmo',%UseAmmo);

%StartingAmmo = ADVPoolAmmoSpawn.getValue();
    commandToServer('UpdateADVSettings','StartingAmmo',%StartingAmmo);
}

and in the gui variables are formatted as such:
Code: [Select]
variable = "UseScope";
when i try and update a variable it is setting it to nothing...

Iirc .getValue() should work fine for boolean variables and such. Are you naming the actual elements of the GUI correctly? Like the check box itself for iron sights being named ADVIronsights?

Iirc .getValue() should work fine for boolean variables and such. Are you naming the actual elements of the GUI correctly? Like the check box itself for iron sights being named ADVIronsights?

yea, proper names and everything, im just wondering what part of the code defines %value

oh btw, the ammo pool one is a numeric value between 1 and 999, is that ok?
« Last Edit: October 04, 2014, 06:10:59 PM by zombekillz »

i just took a closer look as to why the variable is being set to nothing, its actually being set to 0, so getvalue is working to set the variable, just not to what the checkbox says...

and whenever i reopen the GUI nothing appears to hace been changed, im starting to thing its a problen with the name of the gui variable or somthing, perhaps i need to use
Code: [Select]
variable = "$UseScope"; instead of
Code: [Select]
variable = "UseScope";nvm, tried it, no difference made.
« Last Edit: October 04, 2014, 06:26:24 PM by zombekillz »

Well no, a it's using a standard switch case there to try to set it. You can try changing it to an if/else block to see if that changes anything. An example of a switch case that I have lying around is something like this:
Code: [Select]
switch$(%char)
{
case "a":
$thorABC=$thorABC SPC "a";
if($thorSharp[%char]!$="")
{
$thorABC = $thorABC @ "s";
}
if($thorFlat[%char]!$="")
{
$thorABC = $thorABC @ "f";
}
case "b":
Do_Stuff();
case "c":
Do_Stuff();
case "d":
Do_Stuff();
case "e":
Do_Stuff();
case "f":
Do_Stuff();
case "g":
Do_Stuff();
//blah blah

It messes with variables and does a bunch of other bs in the switch. It might be a problem with using getValue on the gui elements, idk if there's some other function supposed to be used for boolean values. Try putting in an echo on UpdateADVSettings() that tells all the info it's trying to send to the server.

thanks, i actually just figured it out...

i probably should have posted the entire function, as my problem lies within it...
Code: [Select]
function servercmdUpdateADVSettings(%client,%globalVar,%value)
{
$StartingAmmoPlaceHolder = $StartingAmmo;
$UseScopePlaceHolder = $UseScope;
$UseAmmoPlaceHolder = $UseAmmo;
$FarSoundPlaceHolder = $FarSound;
$CommandReloadPlaceHolder = $CommandReload;

    if(%client.isAdmin || %client.isSuperAdmin)
{
switch$(%globalVar)
{
case UseScope:
$UseScope = %value;
case UseAmmo:
$UseAmmo = %value;
case FarSound:
$FarSound = %value;
case CommandReload:
$CommandReload = %value;
case StartingAmmo:
$StartingAmmo = %value;
}
}
else
{
CommandToClient(%Client,'CenterPrint',"You are not an admin",2);
}

if($StartingAmmo != $StartingAmmoPlaceHolder)
{
messageall('MsgAdminForce', "\c2The amount of ammo players spawn with has been set to " @ $StartingAmmo @ "");
}

if($UseScope = 1 && $UseScope != $UseScopePlaceHolder)
{
messageall('MsgAdminForce', "\c2Ironsights are now OFF");
}
else if($UseScope != $UseScopePlaceHolder)
{
messageall('MsgAdminForce', "\c2Ironsights are now ON");
}

if($UseAmmo = 1  && $UseAmmo != $UseAmmoPlaceHolder)
{
messageall('MsgAdminForce', "\c2Ammo Usage is now OFF");
}
else if($UseAmmo != $UseAmmoPlaceHolder)
{
messageall('MsgAdminForce', "\c2Ammo Usage is now ON");
}

if($FarSound = 1  && $FarSound != $FarSoundPlaceHolder)
{
messageall('MsgAdminForce', "\c2Distant sounds are now OFF");
}
else if($FarSound != $FarSoundPlaceHolder)
{
messageall('MsgAdminForce', "\c2Distant sounds are now ON");
}

if($CommandReload = 1  && $CommandReload != $CommandReloadPlaceHolder)
{
messageall('MsgAdminForce', "\c2Light key reload command now is OFF");
}
else if($CommandReload != $CommandReloadPlaceHolder)
{
messageall('MsgAdminForce', "\c2Light key reload command is now ON");
}
}

the placeholders were loving stuff up, how to i replace those with a way that work?

EDIT:
so i might have figured this whole getvalue thing out...

is this acceptable?
Code: [Select]
$StartingAmmoPlaceHolder = $StartingAmmo.getValue();
$UseScopePlaceHolder = $UseScope.getValue();
$UseAmmoPlaceHolder = $UseAmmo.getValue();
$FarSoundPlaceHolder = $FarSound.getValue();
$CommandReloadPlaceHolder = $CommandReload.getValue();
« Last Edit: October 04, 2014, 06:46:33 PM by zombekillz »

For the server host it is, but global variables aren't usually shared so easily between server and client without a function in between.

For the server host it is, but global variables aren't usually shared so easily between server and client without a function in between.

for real? i thought this was a server sided deal right here?
what part of this is going through the client?

its getting the value from the server and comparing it to the server variable after the update function...