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 10-08-2011, 08:46 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
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

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);

Reply With Quote
  #2  
Old 10-09-2011, 04:12 PM
Hezzy002 Hezzy002 is offline
Registered User
Join Date: Jul 2011
Posts: 247
Hezzy002 is a jewel in the roughHezzy002 is a jewel in the rough
You can add any weapon to yourself if you replace the string sent to the server.
Reply With Quote
  #3  
Old 10-09-2011, 04:25 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
You should probably make checks serverside to make sure the player has the weapon and if the chest has it.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #4  
Old 10-09-2011, 04:59 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
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.
Reply With Quote
  #5  
Old 10-09-2011, 07:09 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
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.
__________________
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 06:57 PM.


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