Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Need some help with GUIs (https://forums.graalonline.com/forums/showthread.php?t=134257107)

OiRodgar 11-29-2009 01:31 AM

Need some help with GUIs
 
I need some help with GS2 again :p

After I scripted a little shop, I wanted to script a shop with a GUI.
I made a GUI but somehow the text in GuiMLTextCtrl won't change when I select something in GuiTextListCtrl.

Here is my script

PHP Code:

//#CLIENTSIDE
function onPlayertouchsme() {

  new 
GuiWindowCtrl("Shop_Window4") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "544,447";
    
visible true;
    
canmove true;
    
canresize false;
    
canmaximize false;
    
closequery false;
    
destroyonhide true;
    
text "Willkommen im Waffenshop";
    
29;
    
115;

    new 
GuiScrollCtrl("Shop_TextList1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 426;
      
hscrollbar "alwaysOff";
      
vscrollbar "dynamic";
      
width 120;
      
9;
      
15;

      new 
GuiTextListCtrl("Shop_TextList1") {
        
profile GuiBlueTextListProfile;
        
height 426;
        
horizsizing "width";
        
width 99;

        
clearrows();
        
addrow(0,"Bombe");
        
addrow(1,"Bogen");
        
addrow(2,"Nukeshot");
        
addrow(3,"Fire Ball");
      }
    }
    new 
GuiScrollCtrl("Shop_MultiLine1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 426;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 403;
      
138;
      
14;

      new 
GuiMLTextCtrl("Shop_MultiLine1") {
        
profile GuiBlueMLTextProfile;
        
height 16;
        
horizsizing "width";
        
text "<center><h1>Willkommen im Waffenshop!</h1><br> Hier erhalten sie eine Vielzahl an Mitteln um Ihre Gegner auszulöschen</center>";
        
width 378;
      }
    }
    new 
GuiButtonCtrl("Shop_Button1") {
      
profile GuiBlueButtonProfile;
      
text "Kaufen";
      
width 80;
      
286;
      
380;
    }
  }
}

function 
Shop_TextList1.onSelect(0,Bombe,1) {
Shop_MultiLine1.setText("Info Info Info");
}

function 
Shop_Button1.onAction() {
  
// Button "Kaufen" has been pressed



fowlplay4 11-29-2009 02:18 AM

You shouldn't specify numbers as parameters like that, in fact that's why it doesn't work.

Script compiler output for Scratch (in level jerretnpc.nw at pos (30, 30)):
error: unexpected symbol 0 at line 9: function Shop_TextList1.onSelect(0,Bombe,1) {

Try replacing the onSelect function with this:

PHP Code:

function Shop_TextList1.onSelect(entryidentrytextentryindex) {
  
Shop_MultiLine1.setText(entrytext);



OiRodgar 11-29-2009 02:43 PM

Okay, thanks. But when I click on "Bombe", I want that in the descriptionfield the description for the bomb appears. How can I do that?

Codein 11-29-2009 04:31 PM

Quote:

Originally Posted by OiRodgar (Post 1541133)
Okay, thanks. But when I click on "Bombe", I want that in the descriptionfield the description for the bomb appears. How can I do that?

PHP Code:

function Shop_TextList1.onSelectentryidentrytextentryindex ) {
  switch ( 
entrytext ) {
    case 
"Bombe":
       
temp.description "put descriptions here";
       break;
    
    case 
"Whatever":
      
temp.description "whatever";
      break;
  }

  
Shop_MultiLine1.setTexttemp.description );      


Try something like that but I'd really put all descriptions in a database or something and call that to get the information, if you want it to be used countless times throughout your project.

OiRodgar 11-29-2009 08:41 PM

Okay, thank you. Now I want when I press the button that I can purchase something. When I press the button, the weapon won't get added into my inventory and my money will decrased by 15 and then increase by 15 again.

PHP Code:

//#CLIENTSIDE

function onActionbuy()
  {

  if(
this.item == Jeep)

  {
    if(
player.rupees>=15)
      {
      
addweapon Jeep2;
      
player.rupees-=15;
      
Shop_MultiLine1.setText("Danke für den Einkauf");

    }
    else
      {
      
Shop_MultiLine1.setText("Nich genug Geld");
    }

  }

}


function 
onPlayertouchsme() {

  new 
GuiWindowCtrl("Shop_Window4") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "544,447";
    
visible true;
    
canmove true;
    
canresize false;
    
canmaximize false;
    
closequery false;
    
destroyonhide true;
    
text "Willkommen im Waffenshop";
    
29;
    
115;

    new 
GuiScrollCtrl("Shop_TextList1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 426;
      
hscrollbar "alwaysOff";
      
vscrollbar "dynamic";
      
width 120;
      
9;
      
15;

      new 
GuiTextListCtrl("Shop_TextList1") {
        
profile GuiBlueTextListProfile;
        
height 426;
        
horizsizing "width";
        
width 99;

        
clearrows();
        
addrow(0,"Jeep");
      }
    }
    new 
GuiScrollCtrl("Shop_MultiLine1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 426;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 403;
      
138;
      
14;

      new 
GuiMLTextCtrl("Shop_MultiLine1") {
        
profile GuiBlueMLTextProfile;
        
height 16;
        
horizsizing "width";
        
text "<center><h1>Willkommen im Waffenshop!</h1><br> Hier erhalten sie eine Vielzahl an Mitteln um Ihre Gegner auszulöschen</center>";
        
width 378;
      }
    }
    new 
GuiButtonCtrl("Shop_Button1") {
      
profile GuiBlueButtonProfile;
      
text "Kaufen";
      
width 80;
      
286;
      
380;
    }
  }
}

function 
Shop_TextList1.onSelectentryidentrytextentryindex ) {
  switch ( 
entrytext ) {
    case 
"Jeep":
    
this.item "Jeep";
    
temp.description "<center><h1>Bombe</h1><br> Sprenge deine Gegner in die Luft!</center> Preis: 15g";
    break;
  }

  
Shop_MultiLine1.setTexttemp.description );
}

function 
Shop_Button1.onAction() {
  {
    
triggeraction(x,y,"buy","buy");
  }
  
// Button "Kaufen" has been pressed



fowlplay4 11-29-2009 10:04 PM

You can only add weapons and decrease rupees on the server-side, you have the right idea but let's just modify it a little.

PHP Code:

function onActionServerSide() {
  
// The parameters are received from the client-side
  // in an array like so: {"buy", "jeep"}
  // Assuming "jeep" was in this.item when it was triggered
  
if (params[0] == "buy") {
    switch (
params[1]) {
      case 
"jeep":
        
// Check to see if they enough rupees
        
temp.cost 15;
        if (
player.rupees >= temp.cost) {
          
// Add weapon and deduct rupees from player 
          
addweapon("Jeep2");
          
player.rupees -= temp.cost;
        }
        break;
    }
  }
}

//#CLIENTSIDE 

function onPlayertouchsme() { 

  new 
GuiWindowCtrl("Shop_Window4") { 
    
profile GuiBlueWindowProfile
    
clientrelative true
    
clientextent "544,447"
    
visible true
    
canmove true
    
canresize false
    
canmaximize false
    
closequery false
    
destroyonhide true
    
text "Willkommen im Waffenshop"
    
29
    
115

    new 
GuiScrollCtrl("Shop_TextList1_Scroll") { 
      
profile GuiBlueScrollProfile
      
height 426
      
hscrollbar "alwaysOff"
      
vscrollbar "dynamic"
      
width 120
      
9
      
15

      new 
GuiTextListCtrl("Shop_TextList1") { 
        
profile GuiBlueTextListProfile
        
height 426
        
horizsizing "width"
        
width 99

        
clearrows(); 
        
addrow(0,"Jeep"); 
      } 
    } 
    new 
GuiScrollCtrl("Shop_MultiLine1_Scroll") { 
      
profile GuiBlueScrollProfile
      
height 426
      
hscrollbar "dynamic"
      
vscrollbar "dynamic"
      
width 403
      
138
      
14

      new 
GuiMLTextCtrl("Shop_MultiLine1") { 
        
profile GuiBlueMLTextProfile
        
height 16
        
horizsizing "width"
        
text "<center><h1>Willkommen im Waffenshop!</h1><br> Hier erhalten sie eine Vielzahl an Mitteln um Ihre Gegner auszulöschen</center>"
        
width 378
      } 
    } 
    new 
GuiButtonCtrl("Shop_Button1") { 
      
profile GuiBlueButtonProfile
      
text "Kaufen"
      
width 80
      
286
      
380
    } 
  } 


function 
Shop_TextList1.onSelectentryidentrytextentryindex ) { 
  switch ( 
entrytext ) { 
    case 
"Jeep"
    
this.item "Jeep"
    
temp.description "<center><h1>Bombe</h1><br> Sprenge deine Gegner in die Luft!</center> Preis: 15g"
    break; 
  } 

  
Shop_MultiLine1.setTexttemp.description ); 


function 
Shop_Button1.onAction() { 
  
// Button "Kaufen" has been pressed
  // Triggers onActionServerside (on the server-side of course)
  // sending "buy" and this.item as parameters.
  
if (checkCost(this.item)) {
    
// Display Item Purchased
    
Shop_MultiLine1.setText("Danke für den Einkauf");
    
// Trigger the server and get it to add the weapon  
    
triggerserver("gui"this.name"buy"this.item);
  }
  else 
Shop_MultiLine1.setText("Nich genug Geld"); 
}

// This function returns true or false depending on whether they
// have enough rupees for the certain item.
function checkCost(temp.item) {
  switch (
temp.item) {
     case 
"jeep":
       
temp.cost 15;
       break;
     default:
       return 
false;
       break;
  }
  if (
player.rupees >= temp.cost) return true;
  else return 
false;



OiRodgar 11-29-2009 10:49 PM

Okay, now I understand that script. But somehow it won't run again :eek:

fowlplay4 11-29-2009 10:56 PM

If you're using it in a level npc, you'll have to make a few modifications. Assuming that's the problem, you'll need to give a few more details to clear that up.

The npc needs a blocking shape on the server-side, and you have to use triggeraction instead unless you know the npc name which is a little more complicated.

PHP Code:

function onCreated() {
  
// Allows triggers sent from the client-side able to be received on the server-side.
  
setshape(13232);
}

function 
onActionServerSide() { 
  
// The parameters are received from the client-side 
  // in an array like so: {"buy", "jeep"} 
  // Assuming "jeep" was in this.item when it was triggered 
  
if (params[0] == "buy") { 
    switch (
params[1]) { 
      case 
"jeep"
        
// Check to see if they enough rupees 
        
temp.cost 15
        if (
player.rupees >= temp.cost) { 
          
// Add weapon and deduct rupees from player  
          
addweapon("Jeep2"); 
          
player.rupees -= temp.cost
        } 
        break; 
    } 
  } 


//#CLIENTSIDE  

function onPlayertouchsme() {  

  new 
GuiWindowCtrl("Shop_Window4") {  
    
profile GuiBlueWindowProfile;  
    
clientrelative true;  
    
clientextent "544,447";  
    
visible true;  
    
canmove true;  
    
canresize false;  
    
canmaximize false;  
    
closequery false;  
    
destroyonhide true;  
    
text "Willkommen im Waffenshop";  
    
29;  
    
115;  

    new 
GuiScrollCtrl("Shop_TextList1_Scroll") {  
      
profile GuiBlueScrollProfile;  
      
height 426;  
      
hscrollbar "alwaysOff";  
      
vscrollbar "dynamic";  
      
width 120;  
      
9;  
      
15;  

      new 
GuiTextListCtrl("Shop_TextList1") {  
        
profile GuiBlueTextListProfile;  
        
height 426;  
        
horizsizing "width";  
        
width 99;  

        
clearrows();  
        
addrow(0,"Jeep");  
      }  
    }  
    new 
GuiScrollCtrl("Shop_MultiLine1_Scroll") {  
      
profile GuiBlueScrollProfile;  
      
height 426;  
      
hscrollbar "dynamic";  
      
vscrollbar "dynamic";  
      
width 403;  
      
138;  
      
14;  

      new 
GuiMLTextCtrl("Shop_MultiLine1") {  
        
profile GuiBlueMLTextProfile;  
        
height 16;  
        
horizsizing "width";  
        
text "<center><h1>Willkommen im Waffenshop!</h1><br> Hier erhalten sie eine Vielzahl an Mitteln um Ihre Gegner auszulöschen</center>";  
        
width 378;  
      }  
    }  
    new 
GuiButtonCtrl("Shop_Button1") {  
      
profile GuiBlueButtonProfile;  
      
text "Kaufen";  
      
width 80;  
      
286;  
      
380;  
    }  
  }  
}  

function 
Shop_TextList1.onSelectentryidentrytextentryindex ) {  
  switch ( 
entrytext ) {  
    case 
"Jeep":  
    
this.item "Jeep";  
    
temp.description "<center><h1>Bombe</h1><br> Sprenge deine Gegner in die Luft!</center> Preis: 15g";  
    break;  
  }  

  
Shop_MultiLine1.setTexttemp.description );  
}  

function 
Shop_Button1.onAction() {  
  
// Button "Kaufen" has been pressed 
  // Triggers onActionServerside (on the server-side of course) 
  // sending "buy" and this.item as parameters. 
  
if (checkCost(this.item)) { 
    
// Display Item Purchased 
    
Shop_MultiLine1.setText("Danke für den Einkauf"); 
    
// Trigger the NPC and get it to add the weapon   
    
triggeraction(this.1this.1"serverside""buy"this.item); 
  } 
  else 
Shop_MultiLine1.setText("Nich genug Geld");  


// This function returns true or false depending on whether they 
// have enough rupees for the certain item. 
function checkCost(temp.item) { 
  switch (
temp.item) { 
     case 
"jeep"
       
temp.cost 15
       break; 
     default: 
       return 
false
       break; 
  } 
  if (
player.rupees >= temp.cost) return true
  else return 
false



cbk1994 11-29-2009 11:10 PM

Quote:

Originally Posted by fowlplay4 (Post 1541238)
If you're using it in a level npc, you'll have to make a few modifications. Assuming that's the problem, you'll need to give a few more details to clear that up.

The npc needs a blocking shape on the server-side, and you have to use triggeraction instead

I hope I'm not confusing anyone here, but I've always found it better to use DB NPCs for something like this

PHP Code:


function Shop_Button1.onAction() {  
  if (
checkCost(this.item)) { 
    
Shop_MultiLine1.setText("Danke für den Einkauf");

    
// trigger a DB NPC:
    
triggerServer("npc""ShopControl""buy"this.item);
  } 
  else 
Shop_MultiLine1.setText("Nich genug Geld");  


then have a DB NPC named "ShopControl"

PHP Code:

function onActionServerSide() {
  
// The parameters are received from the client-side 
  // in an array like so: {"buy", "jeep"} 
  // Assuming "jeep" was in this.item when it was triggered 
  
if (params[0] == "buy") { 
    switch (
params[1]) { 
      case 
"jeep"
        
// Check to see if they enough rupees 
        
temp.cost 15
        if (
player.rupees >= temp.cost) { 
          
// Add weapon and deduct rupees from player  
          
addweapon("Jeep2"); 
          
player.rupees -= temp.cost
        } 
      break; 
    } 
  }  


It doesn't really make a difference I guess, just another way to do it. It's probably more reliable than using setShape and triggerAction(x, y) since other NPCs can get in the way, etc.

Quote:

unless you know the npc name which is a little more complicated.
You can't trigger level NPCs from clientside anyway (by name); it has to be a DB NPC (or putnpc2, same thing).

fowlplay4 11-29-2009 11:15 PM

Quote:

Originally Posted by cbk1994 (Post 1541241)
post

Nifty.

OiRodgar 11-29-2009 11:16 PM

Quote:

Originally Posted by fowlplay4 (Post 1541238)
If you're using it in a level npc, you'll have to make a few modifications. Assuming that's the problem, you'll need to give a few more details to clear that up.

The npc needs a blocking shape on the server-side, and you have to use triggeraction instead unless you know the npc name which is a little more complicated.

PHP Code:

function onCreated() {
  
// Allows triggers sent from the client-side able to be received on the server-side.
  
setshape(13232);
}

function 
onActionServerSide() { 
  
// The parameters are received from the client-side 
  // in an array like so: {"buy", "jeep"} 
  // Assuming "jeep" was in this.item when it was triggered 
  
if (params[0] == "buy") { 
    switch (
params[1]) { 
      case 
"jeep"
        
// Check to see if they enough rupees 
        
temp.cost 15
        if (
player.rupees >= temp.cost) { 
          
// Add weapon and deduct rupees from player  
          
addweapon("Jeep2"); 
          
player.rupees -= temp.cost
        } 
        break; 
    } 
  } 


//#CLIENTSIDE  

function onPlayertouchsme() {  

  new 
GuiWindowCtrl("Shop_Window4") {  
    
profile GuiBlueWindowProfile;  
    
clientrelative true;  
    
clientextent "544,447";  
    
visible true;  
    
canmove true;  
    
canresize false;  
    
canmaximize false;  
    
closequery false;  
    
destroyonhide true;  
    
text "Willkommen im Waffenshop";  
    
29;  
    
115;  

    new 
GuiScrollCtrl("Shop_TextList1_Scroll") {  
      
profile GuiBlueScrollProfile;  
      
height 426;  
      
hscrollbar "alwaysOff";  
      
vscrollbar "dynamic";  
      
width 120;  
      
9;  
      
15;  

      new 
GuiTextListCtrl("Shop_TextList1") {  
        
profile GuiBlueTextListProfile;  
        
height 426;  
        
horizsizing "width";  
        
width 99;  

        
clearrows();  
        
addrow(0,"Jeep");  
      }  
    }  
    new 
GuiScrollCtrl("Shop_MultiLine1_Scroll") {  
      
profile GuiBlueScrollProfile;  
      
height 426;  
      
hscrollbar "dynamic";  
      
vscrollbar "dynamic";  
      
width 403;  
      
138;  
      
14;  

      new 
GuiMLTextCtrl("Shop_MultiLine1") {  
        
profile GuiBlueMLTextProfile;  
        
height 16;  
        
horizsizing "width";  
        
text "<center><h1>Willkommen im Waffenshop!</h1><br> Hier erhalten sie eine Vielzahl an Mitteln um Ihre Gegner auszulöschen</center>";  
        
width 378;  
      }  
    }  
    new 
GuiButtonCtrl("Shop_Button1") {  
      
profile GuiBlueButtonProfile;  
      
text "Kaufen";  
      
width 80;  
      
286;  
      
380;  
    }  
  }  
}  

function 
Shop_TextList1.onSelectentryidentrytextentryindex ) {  
  switch ( 
entrytext ) {  
    case 
"Jeep":  
    
this.item "Jeep";  
    
temp.description "<center><h1>Bombe</h1><br> Sprenge deine Gegner in die Luft!</center> Preis: 15g";  
    break;  
  }  

  
Shop_MultiLine1.setTexttemp.description );  
}  

function 
Shop_Button1.onAction() {  
  
// Button "Kaufen" has been pressed 
  // Triggers onActionServerside (on the server-side of course) 
  // sending "buy" and this.item as parameters. 
  
if (checkCost(this.item)) { 
    
// Display Item Purchased 
    
Shop_MultiLine1.setText("Danke für den Einkauf"); 
    
// Trigger the NPC and get it to add the weapon   
    
triggeraction(this.1this.1"serverside""buy"this.item); 
  } 
  else 
Shop_MultiLine1.setText("Nich genug Geld");  


// This function returns true or false depending on whether they 
// have enough rupees for the certain item. 
function checkCost(temp.item) { 
  switch (
temp.item) { 
     case 
"jeep"
       
temp.cost 15
       break; 
     default: 
       return 
false
       break; 
  } 
  if (
player.rupees >= temp.cost) return true
  else return 
false




I see.. But it still won't work xD

@cbk1994

I gonna try that after I got the level NPC working.


All times are GMT +2. The time now is 09:07 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.