Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Questions about an Inventory (https://forums.graalonline.com/forums/showthread.php?t=79771)

Stryke 05-18-2008 10:12 PM

Questions about an Inventory
 
1. For dropping items, how would I drop an item in the Weapon List?
Something like this?
PHP Code:

putnpc2(playerx,playery,findNPC("Weapons/Sword of Heavens"));
Didn't work for me,. 

2. This is what my GUI displays:
PHP Code:

showimg(221,player.weapons[selectedweapon].image,14,85);
changeimgvis(221,7); 

But, when I am using my custom inventory, the image won't change.
It only works when I'm using a default inventory.
This is what I use to select items in my inventory:
PHP Code:

for(temp.i=0;temp.i<player.weapons.size();temp.i++;)
{
  if(
player.weapons[temp.i].name == obj.itemName)
  {
    
player.selectedweapon temp.i;
    return;
  }


Should I just use a custom "clientr.itemselected" variable?

cbk1994 05-18-2008 10:16 PM

You could use custom if you wanted.

For the question about dropping items, do something like this:

PHP Code:

function onActionServersidecmddxdywep )
{
  switch ( 
cmd )
  {
    case 
"dropWep":
    {
      
temp.putnpc2dxdy"" );
      
temp.i.join"object_droppeditem" );
      
temp.i.wep wep;
    }
  }


and then have a class object_droppeditem
PHP Code:

function onPlayerTouchsMe()
{
  
player.addWeaponthis.wep );
  
destroy();



[email protected] 05-18-2008 10:24 PM

PHP Code:

      temp.putnpc2dxdy"" );
      
temp.i.join"object_droppeditem" ); 

why must you do that?

PHP Code:

      with(putnpc2(playero.xplayero.y"object_droppeditem")).wep wep


cbk1994 05-18-2008 10:26 PM

Quote:

Originally Posted by [email protected] (Post 1391445)
PHP Code:

      temp.putnpc2dxdy"" );
      
temp.i.join"object_droppeditem" ); 

why must you do that?

PHP Code:

      with(putnpc2(playero.xplayero.y"object_droppeditem")).wep wep


Looks cleaner :)

Tigairius 05-18-2008 10:33 PM

Quote:

Originally Posted by [email protected] (Post 1391445)

PHP Code:

      with(putnpc2(playero.xplayero.y"object_droppeditem")).wep wep


That wouldn't work, it would have to be "join object_droppeditem"


PHP Code:

      temp.putnpc2dxdy"" );
      
temp.i.join"object_droppeditem" ); 

I disagree that this looks cleaner, but I also don't see why "sidney" questioned your script, since yours would work better than "hers"..

[email protected] 05-18-2008 10:41 PM

oh 4fog the 'join'.

how would that version work better? if anything
PHP Code:

putnpc2(x"join item");
i.wep wep

would be better.

DustyPorViva 05-18-2008 11:02 PM

You can't simply drop an item from an inventory onto the ground.
What you can do, is drop an NPC like you're doing, and enclose a variable with it with the name of the weapon and delete the players item. When the player touches the item, add that weapon via addweapon.

cbk1994 05-18-2008 11:10 PM

Why use GS1?

putnpc2( dx, dy, "join( \"item\" )" );

Deas_Voice 05-18-2008 11:31 PM

Quote:

Originally Posted by cbk1994 (Post 1391457)
Why use GS1?

putnpc2( dx, dy, "join( \"item\" )" );

whats with the \ \?
always wonderd why people add them :confused:

cbk1994 05-18-2008 11:36 PM

Quote:

Originally Posted by Deas_Voice (Post 1391460)
whats with the \ \?
always wonderd why people add them :confused:

Because otherwise the parser will think you are ending the string. Think like this:

PHP Code:

"join( "x" );" 

See how the quotes would have ended that string, and it would want to know what the x was doing outside of quotes? The backslash tells it that the quotes need to be IN the string, instead of ending/starting a string.

Stryke 05-19-2008 01:08 AM

PHP Code:

function onActionServersidecmddxdywep )
{
  switch ( 
cmd )
  {
    case 
"dropWep":
    {
      for(
temp.i=0;temp.i<player.weapons.size();temp.i++;)
      {
        if(
player.weapons[temp.i].name == wep)
        {
          
this.wepID temp.i;
          break;
        }
      }
      
removeweapon(wep);
      
temp.putnpc2dxdy"" );
      
temp.i.join("object_droppeditem");
      
temp.i.wep wep;
      
temp.i.img player.weapons[this.wepID].image;
    }
  }


Why is it giving me the wrong images?

DustyPorViva 05-19-2008 01:17 AM

Why are you doing all that looping? Send the current weapon in the triggerclient.

Stryke 05-19-2008 01:27 AM

If I don't do the looping, can't find the Weapon id needed to change the image. I've tried findWeapon(), so I used the loop instead. Can you tell me why it won't display the correct images..

cbk1994 05-19-2008 01:30 AM

In the class, perhaps try setimg( this.img)?

Also, you might need to join it AFTER setting this.img and this.wep so that it runs the functions when this.img actually exists.

DustyPorViva 05-19-2008 01:33 AM

You can still do it on the clientside.
PHP Code:

function onActionServersidecmddxdywepwepimg ) {
  switch ( 
cmd ) {
    case 
"dropWep": {
      
removeweapon(wep);
      
temp.putnpc2dxdy"" );
      
temp.i.join("object_droppeditem");
      
temp.i.wep wep;
      
temp.i.setimg(wepimg);
    }
  }
}
//#CLIENTSIDE
//stuff
temp.wep="Bomb";
temp.wepid=-1;
for (
temp.i=0;i<player.weapons.size();i++) {
  if (
wep == player.weapons[i].name) {
    
wepid=i;
    break;
  }
}
triggerserver("gui",this.name,"dropWep",dx,dy,wep,player.weapons[wepid].image); 


cbk1994 05-19-2008 01:39 AM

PHP Code:

triggerserver("dropWep",dx,dy,wep,player.weapons[wepid].image); 

Do you know something I don't?

I recall

PHP Code:

triggerserver"gui", [...] );
triggerserver"weapon", [...] ); 


Stryke 05-19-2008 01:41 AM

Solved. The problem was I was supposed to access the image of the player's weapon on the clientside, and i was trying to access it off the serverside. Thanks guys!

i'll give rep when i can cause ill gave in the last 24 hours

DustyPorViva 05-19-2008 01:46 AM

Quote:

Originally Posted by cbk1994 (Post 1391488)
PHP Code:

triggerserver("dropWep",dx,dy,wep,player.weapons[wepid].image); 

Do you know something I don't?

I recall

PHP Code:

triggerserver"gui", [...] );
triggerserver"weapon", [...] ); 


Oops!

Quote:

Originally Posted by Stryke (Post 1391490)
Solved. The problem was I was supposed to access the image of the player's weapon on the clientside, and i was trying to access it off the serverside. Thanks guys!

Heh, I'll just point out... if you're having problems like this, debug it. If you ever have a problem, start echoing crap that you suspect is the culprit. In this case, the image isn't setting? Most logical deduction would be that the variable you're assigning the image name to isn't correct. Thus, echo the variable you're using to set the image name. If it IS correct... then come here because something isn't right. If it's null, then you've messed up somewhere else when trying to set it. Go back and think hard and try to figure out what. Debugging is crucial and can most likely make you realize it was a simple problem that you could have caught a lot earlier on your own.

cbk1994 05-19-2008 02:54 AM

Quote:

Originally Posted by Stryke (Post 1391490)
Solved. The problem was I was supposed to access the image of the player's weapon on the clientside, and i was trying to access it off the serverside. Thanks guys!

i'll give rep when i can cause ill gave in the last 24 hours

You won't be able to give it to me anyway, as you already did.

And, for the record, it was a gray gem :cry:

But yes, it is a good idea to give rep to the people who help you; you in return will receive good rep, for the most part.

Be sure to leave your name :)

And Dusty, you beast! Double posting, tssk tssk.

zokemon 05-19-2008 06:18 AM

Don't put the join inside the putnpc's script please. Just join it upon creation and that's it. It's unhealthy and bad tact to put commands and function calls outside of function definitions.

[email protected] 05-19-2008 08:28 AM

do a check serverside, sending the weapon info clientside will make it insecure.


All times are GMT +2. The time now is 06:49 AM.

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