Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Custom Chest Help (https://forums.graalonline.com/forums/showthread.php?t=134264539)

Astram 09-12-2011 11:26 PM

Custom Chest Help
 
Howdy Forums, there happens to be something wrong with my custom chest script, when it updates the chest as I put something in, it just leaves a blank line in the (Inside the chest textlist). When I take that out of the chest, THEN it removes it from my inventory. Its really weird, can someone please help me, I've posted my current script below.
NOTE TO OTHER SERVERS: Please do not take this script with my approval.


Heres the chest class:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.image "woodenchest.png";
  
setimgpart("woodenchest.png",0,0,32,32);
}
function 
onPlayerTouchsMe() {
  
openChestGui(this.inside);
  ( @ 
"Chests_Window_" this.chestid).show();
}
function 
openChestGui(inside) {
    new 
GuiWindowCtrl("Chests_Window_"@this.chestid) {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "498,302";

    
canmaximize false;
    
canminimize false;
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide false;
    
text "Chests";
    
423;
    
198;

    new 
GuiButtonCtrl("Chests_Window_Button1") {
      
profile GuiBlueButtonProfile;
      
height 42;
      
text "Put in Chest";
      
width 498;
      
218;
    }
    new 
GuiButtonCtrl("Chests_Window_Button2") {
      
profile GuiBlueButtonProfile;
      
height 42;
      
text "Take from Chest";
      
width 498;
      
260;
    }
    new 
GuiScrollCtrl("Chests_Window_TextList1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 171;
      
hscrollbar "alwaysOff";
      
vscrollbar "dynamic";
      
width 181;
      
21;
      
24;

      new 
GuiTextListCtrl("Chests_Window_TextList1") {
        
profile GuiBlueTextListProfile;
        
height 34;
        
horizsizing "width";
        
sortcolumn 181348608;
        
width 177;
        
clearrows();
        for (
temp.0temp.inside.size(); temp.++) {
          
addrow(temp.i,inside[(@temp.i)]);
          
sort();
        }
      }
    }
    new 
GuiTextCtrl("Chests_Window_Text1") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "Chest";
      
width 34;
      
89;
      
4;
    }
    new 
GuiScrollCtrl("Chests_Window_TextList2_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 173;
      
hscrollbar "alwaysOff";
      
vscrollbar "dynamic";
      
width 192;
      
282;
      
23;

      new 
GuiTextListCtrl("Chests_Window_TextList2") {
        
profile GuiBlueTextListProfile;
        
height 34;
        
horizsizing "width";
        
sortcolumn 181345792;
        
width 188;
        
clearrows();
        for (
temp.0temp.player.weapons.size(); temp.++) {
          if (!(
player.weapons[(@temp.e)].name.starts("-") || player.weapons[(@temp.e)].name in this.notallowed) || player.weapons[(@temp.e)].name.starts("Astram")) {
            
addrow(temp.e,player.weapons[(@temp.e)].name);
            
sort();
          }
        }
      }
    }
    new 
GuiTextCtrl("Chests_Window_Text2") {
      
profile GuiBlueTextProfile;
      
height 20;
      
text "My Items";
      
width 51;
      
355;
      
4;
    }
  }
}

function 
Chests_Window_Button1.onAction() {
  
triggerserver"gui""Astram/Chests""PutIn"Chests_Window_TextList2.getSelectedText());
  
this.inside.add(Chests_Window_TextList2.getSelectedText());
  
openChestGui(this.inside);
}

function 
Chests_Window_Button2.onAction() {
  
triggerserver"gui""Astram/Chests""TakeOut"Chests_Window_TextList1.getSelectedText());
  
this.inside.remove(Chests_Window_TextList1.getSelectedText());
  
openChestGui(this.inside);


Heres the NPC Code:
PHP Code:

this.chestid = 0947479;
join("chest"); 

Heres the weapon Coding:
PHP Code:

function onActionServerSide() {
  if (
params[0] == "PutIn") {
    
player.removeweapon(params[1]);
  }
  if (
params[0] == "TakeOut") {
    
player.addweapon(params[1]);
  }



fowlplay4 09-12-2011 11:43 PM

You need to store 'this.inside' in a DB-NPC and use chestid to make 'this.inside' unique.

I.e: this.("chest_" @ this.chestid)

The Chest GUI should be created in the weapon npc.

1. Player Touches Chest

2. Call 'Chest Weapon' with Chest ID to load chest.
I.e: findweapon("-GUI/Chest").loadChest(this.chestid);

3. Trigger Server: Get contents of Chest ID (optional: Check Chest Owner)
I.e: triggerserver("gui", this.name, "loadChest", this.chestid);

4. Trigger Client: Contents of Chest ID
I.e: player.triggerclient(this.name, "chestContents", this.contents);

5. Store Contents on Clientside and Draw Chest GUI
I.e: this.contents = params[1];

I'd store the data in a DB-NPC called DB_Chests and use public functions to access and modify the data. I.e:

PHP Code:

public function getChest(chestid) {
  
// Return contents of chest
  
return this.("chest_" chestid);
}

public function 
addToChest(chestidweaponName) {
  
// Add Weapon to Chest
  
this.("chest_" chestid).add(weaponName);
}

public function 
removeFromChest(chestidweaponName) {
  
// Remove Weapon From Chest
  
this.("chest_" chestid).remove(weaponName);
}

public function 
hasInChest(chestidweaponName) {
  
// Check if Weapon is in Chest
  
return weaponName in this.("chest_" chestid);


Then you can use:

DB_Chests.getChest(chestid);
DB_Chests.addToChest(chestid, weaponName);
DB_Chests.removeFromChest(chestid, weaponName);
DB_Chests.hasInChest(chestid, weaponName);

To access and modify the contents of chests.

Also keep in mind that variables you set on the server-side are inaccessible on the client-side, I would recommend using attrs to get around that. I.e:

In your chest class:

PHP Code:

function onCreated() {
  
this.attr[2] = this.chestid;
  
this.attr[3] = this.chestowner// (optional)
}

//#CLIENTSIDE

function loadChest() {
  
temp.chestid this.attr[2];
  
temp.chestowner this.attr[3];
  
// do stuff with it.
}

// your other code... 



All times are GMT +2. The time now is 10:37 PM.

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