Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Delete flag from DB? (https://forums.graalonline.com/forums/showthread.php?t=134258662)

DeCeaseD 04-06-2010 01:36 AM

Delete flag from DB?
 
Is there any way to totally remove a flag from a DBNPC? Atm, i'm using this.("test_"@ whatever) = NULL; but that just sets the flag to 0. I also tried using this.("test_"@ whatever).delete(); and this.("test_"@ whatever).remove(); but neither of them work. Can anyone help me out here?

fowlplay4 04-06-2010 01:39 AM

You can un-assign/destroy variables with:

this.("test_"@ whatever) = "";

WhiteDragon 04-06-2010 01:51 AM

Just remember that everything in GS2 is a string, and that NULL is a lie.

cbk1994 04-06-2010 02:17 AM

There is also obj.clearEmptyVars(); which will delete 0 or NULL values from the flags. It doesn't really matter, though, since they're removed on server restart and don't interfere with the operation of the DB anyway.

DustyPorViva 04-06-2010 02:23 AM

null = 0 != ""

However, sometimes it does, sometimes it doesn't...

cbk1994 04-06-2010 03:16 AM

Quote:

Originally Posted by DustyPorViva (Post 1567360)
null = 0 != ""

However, sometimes it does, sometimes it doesn't...

Nothing random about it. null shows up as 0. Using an empty string ("") causes it to not show up.

Either way it doesn't matter though.

DustyPorViva 04-06-2010 03:38 AM

Quote:

Originally Posted by cbk1994 (Post 1567376)
Nothing random about it. null shows up as 0. Using an empty string ("") causes it to not show up.

Either way it doesn't matter though.

Graal sometimes considers 0 as reason to clear the variable, but will render it as 0, was my point.

DeCeaseD 04-06-2010 08:34 AM

Yeah, it seems "" totally clears the variable. But yeah, usually when you set a client or clientr flag to NULL, Graal will recognize the 0 as nothing and just clear it. I figured the same applied to variables in NPC's, but I guess not. -.o Thanks anyways guys. :D

coreys 04-06-2010 05:24 PM

Quote:

Originally Posted by DustyPorViva (Post 1567382)
Graal sometimes considers 0 as reason to clear the variable, but will render it as 0, was my point.

Whenever I've made little clock systems to show the time using showimg with text, I always have to but a bugfix in my time system that changes 0 to "0".

DeCeaseD 04-06-2010 11:06 PM

Okay, so I figured instead of making a new thread, I would just post this issue here. I'm now having trouble checking for a clientr flag while using a for loop in the check. I'm setting temp.i using a for loop, than trying to check a clientr flag using temp.i, atm i'm trying clientr.backpack_size(@ i+1), but it keeps returning as null when it should return as either "Small" or "Medium" Can anyone tell me how to fix this? Here's the code:

PHP Code:

function displayBackPacks()
{
  
temp.mXY = {mousescreenxmousescreeny};
  for ( 
temp.0temp.clientr.backpack_slotstemp.i++ ) {
  
    
temp.displayXY = { screenwidth 240 + (58 i), screenheight 50 };
    
with findImg200 ) ) {
    
      
image "necro_gui_iconbox.gif";
      
mode 1;
      
layer 4;
      
red green blue 1;
      
alpha .65;
      
displayXY[0];
      
displayXY[1];
    }
    if ( 
clientr.backpack_size(@ i+) != nil ) {
      
with findImg205 ) ) {
    
        
image "necro_gui_backpack1_1.gif";
        
mode 1;
        
layer 5;
        
red green blue 1;
        
alpha .65;
        
displayXY[0] - 3;
        
displayXY[1] - 5;
      }
    }
    if ( 
mXY[0in |displayXY[0], displayXY[0] + 34| &&
         
mXY[1in |displayXY[1], displayXY[1] + 34| ) {
      
      
temp.sizeCheck clientr.backpack_size(@ i+1);
      
player.chat sizeCheck @" Backpack #"@  i+1;
    }
  }



fowlplay4 04-06-2010 11:20 PM

Are you trying to use an array?

These code snippets should help..

PHP Code:

// Declaring an array
clientr.backpack_size = {
  
"Small""medium""large""endless"
};

// Picking one element from an array
temp.bagsize clientr.backpack_size[2]; // bagsize = "large"

// Basic For Loop example
for (temp.0temp.clientr.backpack_size.size(); temp.i++) {
  
temp.bagsize clientr.backpack_size[temp.i];
  echo(
temp.bagsize);
}

// For-each example
for (temp.bagsizeclientr.backpack_size) {
  echo(
temp.bagsize);


If you're storing like so.. clientr.backpack_size1, clientr.backpack_size2, etc.

You can use makevar or through the dot notation way.

temp.bagsize = makevar("clientr.backpack_size" @ i + 1);
temp.bagsize = clientr.("backpack_size" @ i + 1);

DeCeaseD 04-06-2010 11:24 PM

No, i'm actually not using an array, i'm simply doing this:

clientr.backpack_slots=# (At the moment, I have it set to 2 in my chars attributes).

Using the slot flag, i'm checking for which slot the player is interacting with.

Than I'm doing clientr.backpack_size#=size;.. which in my case I have clientr.backpack_size1=Small, and clientr.backpack_size2=Medium.

What i'm trying to do is set temp.i to clientr.backpack_slots (Which is working because i'm displaying stuff using that flag.) than, i'm trying to display backpacks according to whether or not clientr.backpack_size is NULL or not. x_x

salesman 04-06-2010 11:47 PM

try
PHP Code:

clientr.(@ "backpack_size" 1); 


DeCeaseD 04-06-2010 11:57 PM

Quote:

Originally Posted by salesman (Post 1567526)
try
PHP Code:

clientr.(@ "backpack_size" 1); 


Yay, Sales you rule! :D Thanks for the attempt to help Jerret. ^^

fowlplay4 04-07-2010 12:16 AM

Quote:

Originally Posted by DeCeaseD (Post 1567528)
Yay, Sales you rule! :D Thanks for the attempt to help Jerret. ^^

I had edited that into my post around the time of your reply, but you're welcome.

DeCeaseD 04-07-2010 02:28 AM

Okay, so i've unfortunately ran into another problem.. Don't make fun of me. :cry: Okay so.. This probably isn't the best approach to making an "Item System", but here goes:

I've made 2 Databases for storing flags. 1st, is the BackpackStorage DB, which is the place where the items that the player has is stored, which backpack they are in, and how much of that item they have. Example: DeCeaseD_backpack_1="gun_Mp5,3".

2nd, is the ItemDatabase, which stores the stats for each of those items, like for instance: gun_Mp5="Actual Name", "Icon Image", "Gun Img", "Gun Dmg", etc.

Now.. for the "inventory". When the player opens up one of their bags, it's triggering to the server sending the players.account, along with which backpack is being opened, it than in turn looks to the DB, retrieves the items, than sends it to the client for storing. Once the items are stored, it than goes back to the server, and get's the stats for those items.. Now here's where my problem comes in. Everything works fine with the sending/retrieving of flags, but the problem is that, it's only retrieving/sending ONE of the items that I have in my backpack when it should be retrieving/sending two or more. I'll post the script, and can anyone tell me where I went wrong??


PHP Code:

function onActionServersidecmdd1d2d3d4d5 )
{
  if ( 
cmd == "InitializeSlot" ) {
  
    
clientr.backpack_slots 1;
    
clientr.backpack_size1 "Small";
    
player.chat "Recieved 1 "clientr.backpack_size1 @" backpack!";
  }
  if ( 
cmd == "RemoveSlot") {
  
    
clientr.backpack_slots NULL;
    
clientr.backpack_size1 NULL;
  }
  if ( 
cmd == "BackpackCheck" ) {
  
    
temp.npc findNPC("BackpackStorage");
    
temp.pl d1;
    
temp.backpack d2;
    
npc.(d1 @"_backpack_"backpack).add({"gun_Test"2});
  }
  if ( 
cmd == "ItemRefresh" ) {
  
    
temp.npc findNPC("BackpackStorage");
    
temp.pl d1;
    
temp.backpack d2;
    
temp.items npc.RetrieveItemsplbackpack );
    
temp.itemCount items.size();
    
triggerClient(this.name"ReturnItems"itemsitemCount);
    
//player.chat = "Item: "@ items[itemCount-1][0] @" Quantity: "@ items[itemCount-1][1] @" Item Count: "@ itemCount;
  
}
  if ( 
cmd == "GetItemStats" ) {
  
    
temp.npc findNPC("ItemDatabase");
    
temp.items npc.ReturnItemStatsd1 );
    
triggerClient(this.name"ReturnItemStats"items);
    
//player.chat = items;
  
}
}

//#CLIENTSIDE
function onCreated() {
  if ( 
clientr.backpack_slots <= ) {
  
    
triggerServer("gui"this.name"InitializeSlot");
  }
  
onTimeout();
}

function 
onActionClientsidecmdd1d2d3d4d5)
{
  if ( 
cmd == "ReturnItems" ) {
  
    
this.items d1;
    
this.itemCount d2;
    for ( 
temp.0temp.this.itemCounttemp.v++ ) {
    
      
triggerServer("gui"this.name"GetItemStats"d1[@ v][0]);
    }
  }
  if ( 
cmd == "ReturnItemStats" ) {
  
    
this.itemStats d1;
    
//player.chat = this.itemStats;
  
}
}

function 
onTimeout()
{
  
displayBackPacks(); 
  
//Contain OpenBackpack();
  //OpenBackpack will check for pack# and retrieve items
  //Contain DisplayItems();
  //DisplayItems will show items, and DisplayOptions()
  //Contain DisplayOptions();
  //DisplayOptions will display options for item usage.
  
setTimer(0.05);
}

function 
displayBackPacks()
{
  
temp.mXY = {mousescreenxmousescreeny};
  for ( 
temp.0temp.clientr.backpack_slotstemp.i++ ) {
  
    
temp.sizeCheck clientr.(@ "backpack_size" i+1);
    
temp.displayXY = { screenwidth 300 + (58 i), screenheight 50 };
    
with findImg200 ) ) {
    
      
image "necro_gui_iconbox.gif";
      
mode 1;
      
layer 4;
      
red green blue 1;
      
displayXY[0];
      
displayXY[1];
    }
    if ( 
sizeCheck != nil ) {
      
with findImg205 ) ) {
    
        
mode 1;
        
layer 5;
        
red green blue 1;
        
displayXY[0] - 3;
        
displayXY[1] - 5;
      }
    }
    if ( 
mXY[0in |displayXY[0], displayXY[0] + 34| &&
         
mXY[1in |displayXY[1], displayXY[1] + 34| ) {
      
      
this.overBackpack =  i+1;
      
findImg(200 i).alpha .9;
      
findImg(205 i).alpha .9;
      if ( 
leftmousebutton ) {
        if ( !
this.lmb ) {
          
this.lmb true;
          
this.selectedBackpack i+1;
          
play("necro_click2.wav");
          if ( 
this.overBackpack == this.selectedBackpack ) {
            if ( 
this.openBackpack != this.selectedBackpack ) {
            
              
findImg(205 i).image "necro_gui_backpack1_2.gif";
              
openBackpack();
            } else
            if ( 
this.openBackpack == this.selectedBackpack ) {
            
              
findImg(205 i).image "necro_gui_backpack1_1.gif";
              
this.openBackpack NULL;
              
this.selectedBackpack NULL;
              
this.itemsRefreshed false;
            }
          }
        }
      } else { 
this.lmb false; }
    } else {
      if ( 
this.selectedBackpack != i+|| this.selectedBackpack == NULL || this.overBackpack == NULL ) {
            
        
findImg(205 i).image "necro_gui_backpack1_1.gif";
        
findImg(200 i).alpha .45;
        
findImg(205 i).alpha .45;
      }
    }
  }
  if ( 
this.openBackpack != NULL openBackpack();
  if ( 
this.openBackpack == NULL this.itemsRefreshed false;
}

function 
openBackpack()
{
  
this.openBackpack this.selectedBackpack;
  if ( 
player.account == "DeCeaseD") {
    if ( !
this.itemsRefreshed ) {
    
      
this.itemsRefreshed true;
      
triggerServer("gui"this.name"ItemRefresh"player.accountthis.openBackpack);
      
//triggerServer("gui", this.name, "BackpackCheck", player.account, this.openBackpack);   
    

  }
  
displayItems();
}

function 
displayItems()
{
  for ( 
temp.0temp.this.itemCount-1temp.v++ ) {
  
    
temp.pItems this.itemStats;
    
player.chat "Items: "pItems;
  }



DeCeaseD 04-07-2010 09:01 PM

Sorry for the double post, but could someone PLEASE help me with this? I've seriously been sitting here trying to debug the script for a good hour or so and I've still gotten no luck with it. I'm getting really aggrivated! :cry:

Switch 04-07-2010 09:23 PM

What's the function that returns what you have?

DeCeaseD 04-07-2010 09:26 PM

Quote:

Originally Posted by Switch (Post 1567699)
What's the function that returns what you have?

For returning the items, I have this in the BackpackDB:

PHP Code:

public function RetrieveItemsplbackpack )
{
  return 
this.(pl @"_backpack_"backpack);


And for returning the stats of those items, I have this in the ItemDB:

PHP Code:

public function ReturnItemStatsitemitemCount 
{
  for ( 
temp.0temp.itemCounttemp.v++; ) {
  
    return 
this.(@ item)[temp.v];
    echo(
"Debug: "this.(@ item)[temp.v]);
  }



Switch 04-07-2010 09:31 PM

return will end a function, therefore it only returns the first item stat. you need to send the item stats all at once.

Also, how are the flags working on the retrieving of items?


All times are GMT +2. The time now is 09:11 AM.

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