function ItemData::onPickup(%this,%obj,%user,%amount)
{
if (%user.client.edit) {
SarumanStaffProjectile::onCollision(%this,%user,%obj,0,0,0);
return;
}
//added purchasing code -DShiznit
%shizname = %obj.getShapeName();
%word0 = getword(%shizname,0);
%word1 = getword(%shizname,1);
%word2 = getword(%shizname,2);
%word3 = getword(%shizname,3);
%word4 = getword(%shizname,4);
%word5 = getword(%shizname,5);
%word6 = getword(%shizname,6);
if(%word0 == "$"){%debt = %word1;}
if(%word1 == "$"){%debt = %word2;}
if(%word2 == "$"){%debt = %word3;}
if(%word3 == "$"){%debt = %word4;}
if(%word4 == "$"){%debt = %word5;}
if(%word5 == "$"){%debt = %word6;}
if(%debt <= %user.client.studmoney)
{
%user.client.studmoney = user.client.studmoney - %debt;
}
else if(%debt > %user.client.studmoney)
{
messageClient(%user, 'Msg', "\c2You can\'t afford that.");
return;
}
parent::onPickup(%this,%obj,%user,%amount);
}

this is some code i'm working on to make items purchasable, by getting a price from the name assigned with the editor staff. At present, all it does is makes all items unable to pick up, but does not message the client (wait, now I think see why, it needs to be %user.client, not %user). The only console error are five "string always evaluates to 0" errors, probably from where I used %obj.getShapeName();

I ran into this same problem when I tried getskinname(); to determine the value of coins, and to work around by adding another variable to the coins when created. I don't want to have to resort to this for items, as I really want to be able to get the price from the name.

EDIT- no responses in over a day? weak...
hmm, sorry, for some reason this didn't show up on my new posts list.

insert echo's every couple lines to determine where the error is occurring, makes things a lot easier.
I 'm almost certain it's occuring where it defines the debt owed if one of the first six words is a $, as it gives me 6 "string always evaluates to 0" errors, but I'll add in some echo's just to be sure.
actually, scratch that, its because you're using == and not $=
It works now, after fixing a few other minor problems in addition to that (<= doesn't work, had to substitute < || =, etc.) It works so beautifully I could cry, allthough there are still two minor problems.

1. The system will charge money regardless of whether or not the item has been picked up (the code that regulates whether an item is added to the inventory is elsewhere, probably inventory.cs) though I think I can write in an array variable like %user.hasitem[%obj] to do that simple check.

2. The system is based on the floaty name (%obj.shapename), which is saved on bricks and switches, not weapon items. I think this is handled in tbmzips.cs.dso, but I am uncertain, as it could be related to the item's classname (this is why the lightsabres were able to be picked up multiple times, their classname was "weapon" not "tool") which I think is handled in inventory.cs. I should really check that script. huh?
You should indeed check the script. Glad you got the issues ironed out here; this is why I hate the lack of operator standardization across languages. Eg, Matlab uses ~= for C's !=, and PHP uses !== and === for binary inequality and equality respectively where C uses the comparison operators for all types.
DShiznit wrote:
2. The system is based on the floaty name (%obj.shapename), which is saved on bricks and switches, not weapon items. I think this is handled in tbmzips.cs.dso, but I am uncertain, as it could be related to the item's classname (this is why the lightsabres were able to be picked up multiple times, their classname was "weapon" not "tool") which I think is handled in inventory.cs. I should really check that script. huh?


I'm quite sure its not tbmzips.
When I was talking about tbmzips.cs, I was wondering if it was discriminating between items and bricks, and if that discrimination included whether or not shapename is saved.

As for the other problem, I checked inventory.cs, but I don't really understand how it relates to the item::onPickup function. I'll keep studying it, maybe I'll have a revelation or something...

EDIT- figured out how to check if an item is in the inventory, but it ignores the rest of my code when I do, picking up the item without charging it, and without any of the echos I put in:

if (%user.client.inv[%obj.getname] $= 0)
{
%shizname = %obj.getShapeName();
echo("%shizname defined");
%word0 = getword(%shizname,0);
%word1 = getword(%shizname,1);
%word2 = getword(%shizname,2);
%word3 = getword(%shizname,3);
%word4 = getword(%shizname,4);
%word5 = getword(%shizname,5);
%word6 = getword(%shizname,6);
echo("%words defined");
if(%word0 $= "$"){%debt = %word1;}
if(%word1 $= "$"){%debt = %word2;}
if(%word2 $= "$"){%debt = %word3;}
if(%word3 $= "$"){%debt = %word4;}
if(%word4 $= "$"){%debt = %word5;}
if(%word5 $= "$"){%debt = %word6;}
echo (%debt@" defined as debt");
if(%debt == %user.client.studmoney || %debt < %user.client.studmoney)
{
%user.client.studmoney = %user.client.studmoney - %debt;
echo (%user.client.name@" has $"@%user.client.studmoney);
commandToClient(%user.client, 'SetStudCounter', %user.client.studmoney);
if (%debt != 0)
{
messageClient(%user.client, 'Msg', "\c2You just spent $"@%debt);
ServerPlay3D(MoneyStudSound, %user.getTransform());
}
}
else if(%debt > %user.client.studmoney)
{
messageClient(%user.client, 'Msg', "\c2You can\'t afford that.");
return;
}
}


this is in item.cs in the onPickup function, just after the edit mode check.

when I try it this way:

if (%user.client.inv[%obj.getname] == false)

it charges regardless if the item is in the inventory. I'm gonna try $= false next, then maybe $= "0" if that doesn't work, or $= "false"

EDIT- damnit, every time I ask for a string it ignores the code completely, and if I ask for a numerical value, it ALWAYS charges. I'm out of ideas, How do I use this command?
$= is only for strings, == is for numerical values
I get that now, but I still can't figure out this inventory checking system. I know that command uses a numerical variable, not a string, but for some reason that variable is ALWAYS 0, so I guess that command isn't even used. RTB did this why the fuck can't I? Seriously, the rest of their money system is primative and almost useless, but they were able to figure out friggin inventory detection. I usually don't resort to this, but I'll take a peek at their system to see how they did it. I won't copy it, though I may manually type in whatever command they used for inventory detection.
Quote:

function ShapeBase::getInventory(%this,%data)
{
// Return the current inventory amount
return %this.inv[%data.getName()];
}


I believe in this case %this is the player and not the client, and %data is an ItemData object.
according to GreyMario, RTB never solved this problem, it was just unnoticed since they make you press e to pickup items. That means I'm still ahead of them, and I don't need to see their code.

I'll try user.inv[%obj.name] == false
(false of course is the same as 0)
DShiznit wrote:
according to GreyMario, RTB never solved this problem, it was just unnoticed since they make you press e to pickup items. That means I'm still ahead of them, and I don't need to see their code.

I'll try user.inv[%obj.name] == false
(false of course is the same as 0)



use !%user.inv[%obj.name]
nope. damnit. is there a way to get the itemdata associated with %obj? I'm thinking that may be the problem.
wait, no, %this is is the item data (the function is itemdata::onPickup) so, if (!%user.inv[%this.getname()]) should have worked, but it didn't. could if (%user.inv[%this.getname()] == false) work? Or is that pretty much the same thing...
DShiznit wrote:
nope. damnit. is there a way to get the itemdata associated with %obj? I'm thinking that may be the problem.


try this:


echo(%obj);
echo(%obj.name);

DShiznit wrote:
wait, no, %this is is the item data (the function is itemdata::onPickup) so, if (!%user.inv[%this.getname()]) should have worked, but it didn't. could if (%user.inv[%this.getname()] == false) work? Or is that pretty much the same thing...




! flips a boolean, so its essentially the same thing as comparing to 0, since any non-0 value is treated as boolean truth.
when picking up a cutlass

echo(%obj);
echo(%obj.name);
echo(%obj.getname());
echo(%this.getname());

gives me

4023


cutlass

then it proceeds to define %shizname and etc. even though I already have a cutlass.

EDIT- it would appear that %obj is the null name, that tidbit could be useful somewhere.
the .inv code isn't actually used anymore. lol.


Code:

%item = %this
%player = %user;
%data = %player.getDataBlock();
//If there is an open inventory slot put it there
%itemin = -1;
for(%i = 0; %i < %data.maxItems; %i++) {
  if (%player.inventory[%i] == %this)
       %itemin= %i;
       break;
  }
}
if(%itemin<0){
echo("WE DON'T HAVE ONE");
}
else if(%itemin == %data.maxItems{
echo("NO ROOM AT THE INN");
}


where is that code? it can't be item.cs, that part of my item.cs looks like this:

Code:
//-----------------------------------
   %player = %user;
   %data = %player.getDataBlock();
   //If there is an open inventory slot put it there
   %freeslot = -1;
   for(%i = 0; %i < %data.maxItems; %i++) {
     if (%player.inventory[%i] == 0 && %freeslot == -1)
       %freeslot = %i;
          else if (%player.inventory[%i] == %this) {
            %freeslot = -1;
            break;
            }
   }
   if(%freeslot != -1)
   {
      if (%obj.isStatic())
         %obj.respawn();
      else
         %obj.delete();
      
      %player.inventory[%freeslot] = %this;
      // Inform the client what they got.
      if (%user.client)
      messageClient(%user.client, 'MsgItemPickup', '', %freeslot, %this.invName);
      return true;
   }
   else {
          %obj.hide(0);
   }

   // If the item is a static respawn item, then go ahead and
   // respawn it, otherwise remove it from the world.
   // Anything not taken up by inventory is lost.
}


//-----------------------------------------------------------------------------

And I never get told what I got, so I doubt this is used. Or does the message part just not work, and what you post is from tbg? Bah, I'll just move my code into where it says if freeslot or whatever and see what happens.

EDIT- Huzza! It works now. Thanks for all your help.

EDIT- wait I'm not done yet, I still need to get the text on items to save. Is there any discrimination between items and bricks and what dynamic fields and such are saved within tbmzips.cs? I'll check iGobs.cs for now.

EDIT- From what I can tell, there is no discrimination between switch items, and weapon items. That means tbmzips.cs.dso probably isn't responsible. I'll check weapon.cs next maybe.
just open a .save file Wink

and that was TBM/TBG code with some alterations for your situation
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement