Graal Forums

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

pig132 10-08-2011 08:46 AM

Chest class
 
So I made my own custom chest and I think its pretty good (for my abilities at least). I'm curious as to how I can improve it or if anyone sees anything wrong with it.

Thank you :D

PHP Code:

function onActionTakeItem() {
  
player.addweapon(params[0]);
  
serverr.chestitems.remove(params[0]);
  
player.chat "Received " params[0] @ "!";
}

function 
onActionAddItem() {
  
player.removeweapon(params[0]);
  
serverr.chestitems.add(params[0]);
  
player.chat "Added " params[0] @ "!";
}

function 
onActionAddItemList() {
  
serverr.chestitems = {"Public/pig132/Strafe""Personal/pig132/Boots"};
}


//#CLIENTSIDE
function onCreated() {  
  
//triggeraction(this.x + 1, this.y + 1, "AddItemList");
  
  
new GuiWindowCtrl("Chest_Main") {
    
profile GuiBlueWindowProfile;
    
    
visible false;
    
    
player.x;
    
player.y;
    
    
width 200;
    
height 200;
    
    
canmaximize canminimize canresize canclose false;
    
destroyonhide false;
    
    
text "Chest";
    
  new 
GuiScrollCtrl("Chest_Scroll") {
    
profile GuiBlueScrollProfile;
    
    
10;
    
30;
    
    
width 130;
    
height 160;
    
    
hScrollBar "dynamic";
    
vScrollBar "alwaysOff";
    
  new 
GuiTextListCtrl("Chest_List") {
    
profile GuiBlueTextListProfile;
    
    
0;
    
width 130;
    
fitparentwidth true;
    
    
clearrows();
    
addrow(0serverr.chestitems[0]);
    
addrow(1serverr.chestitems[1]);
    
setSelectedRow(0);
  }
  }
  
  new 
GuiButtonCtrl("Button_Take") {
    
profile GuiBlueButtonProfile;
    
    
145;
    
30;
    
width 40;
    
height 25;
    
text "Take";
  }
  
  new 
GuiButtonCtrl("Button_Add") {
    
profile GuiBlueButtonProfile;
    
    
145;
    
60;
    
width 40;
    
height 25;
    
text "Add";
  }
  
  new 
GuiButtonCtrl("Button_Close") {
    
profile GuiBlueButtonProfile;
    
    
145;
    
165;
    
width 40;
    
height 25;
    
text "Close";
  }
  }
// main window (200 x 200)
}

function 
onPlayerTouchsme() {
  
Chest_Main.show();
}

function 
Button_Close.onAction() {
  
Chest_Main.hide();
}

function 
Button_Take.onAction() {
  
this.item Chest_List.getselectedtext();
  
this.ritem Chest_List.getselectedid();
  
triggeraction(this.1this.1"TakeItem"this.item);
  
Chest_List.removerowbyid(this.ritem);
}

function 
Button_Add.onAction() {
  
this.additem player.weapon.name;
  
triggeraction(this.1this.1"AddItem"this.additem);
  
Chest_List.addrow(rowcount 1this.additem);



Hezzy002 10-09-2011 04:12 PM

You can add any weapon to yourself if you replace the string sent to the server.

Gunderak 10-09-2011 04:25 PM

You should probably make checks serverside to make sure the player has the weapon and if the chest has it.

ffcmike 10-09-2011 04:59 PM

Won't the use of the same GUI control names within multiple different level NPCs cause problems?
For instance opening a chest in one level will also invoke the actions within chests you've seen within different levels.
You could either move the GUI scripts into a weapon and communicate with that weapon from the class, or create GUIs with dynamic names and use catchevent(); to be able to receive the action.

fowlplay4 10-09-2011 07:09 PM

Use a DB-NPC to store chest contents instead of serverr flags.

You can do that like this:

PHP Code:

function onCreated() {
  
this.db YourDatabaseNPCsName;
  if (!
this.chest_id) {
    echo(
"Chest created in " this.level.name " without chest id!");
    
destroy();
  }
}

function 
onActionAddItem(item) {
  
// Make sure item is in chest
  
if (item in getItems()) {
    
// Remove weapon from chest
    
takeItem(item);
    
// Add weapon to player
    
player.addweapon(item);
  }
}

function 
onActionTakeItem(item) {
  
// Make sure the item isn't already in chest
  
if (!(item in getItems())) {
    
// Remove weapon from Player
    
player.removeweapon(item);
    
// Add item to chest
    
addItem(item);
  }
}

/* Chest functions to interact with database */

function getItems() {
  return 
this.db.("chest_" this.chestid);
}

function 
addItem(item) {
  
this.db.("chest_" this.chestid).add(item);
}

function 
takeItem(item) {
  
this.db.("chest_" this.chestid).remove(item);


then when you add chests to levels:

PHP Code:

function onCreated() {
  
this.chest_id "someuniqueid";
  
join("your_chest_class");


You'll have to update how you send the chest data to the client though.


All times are GMT +2. The time now is 02:49 PM.

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