Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-12-2011, 11:26 PM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
Post 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]);
  }

__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #2  
Old 09-12-2011, 11:43 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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... 
__________________
Quote:
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:47 AM.


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