Weapon Quantities

Hey guys, I’m having a tough time on this idea.

I need a “item quantity” system for weapons. Item quantities simply mean that each time the weapon is used, the number of that weapon you have goes down 1. For example, if you have 10 Magic Potions, using it would leave you with 9 Magic Potions. Now, that isn’t the hard part. The hard part is that I want to display the number of uses left the Weapon has using a system NPC weapon. How would I pass a quantity to the system NPC weapon, keeping in mind that there are at least 39 other weapons with quantities that also want to be displayed at the same time?

The ideas I’ve come up with are:
Store Weapon Indexes and Quantities in string lists/arrays databases. Might work, but easy to hack in offline play.
Dual callweapons, one callweapon by the system NPC to the item weapon, and one back to the system NPC with the item quantity as a parameter. I don’t know if callweapon is immediate though, and if it is not it might interfere with other callweapons I have.
Not to display item quantities on inventory, where you have to right-click on the item, calling its showinfo eventflag to display its description and quantity.

if(playertouchsme) {
  toweapons [B][I]weaponname[/I][/B];
  setstring client.[B][I]weaponname[/I][/B],5;

if(weaponfired) {
  if(strtofloat(#s(client.[B][I]weaponname[/I][/B])>0) {
    setstring client.[B][I]weaponname[/I][/B],#v(strtofloat(#s(client.[B][I]weaponname[/I][/B])) - 1);
    setplayerprop #c,[#s(client.[B][I]weaponname[/I][/B]) / 5 ];
  if(strtofloat(#s(client.[B][I]weaponname[/I][/B])<=0) destroy;

Also, Weapon Indexes can change around, a lot.

[code]// NPC made by Onijustin //usually used in a timeout
if(strequals(#w,weapon)){ //shows # of uses left whenever selected
showtext 300,186,32,arial,#s(blahuses); //might want to add this to other weapons
changeimgvis 300,5; //so the number wont stay when using an item with inf uses.

//alt way, for system npc.

showtext 300,pixelx,pixely,arial,#s(#w uses); //don’t forget to change the pixelx/y to a number. :stuck_out_tongue:
changeimgvis 300,5; //uses string : yourweaponnamehere uses
…hope it makes sense for anyone here. :S

you could also use toinventory, iirc.

toinventory flag; puts the npc into the player's inventory until the flag is unset

I did this idea when working on some q menu that lagged the shit out of players.
So basically I would set a client string as such:
setstring client.Ranger bootsquantity,5;

and then

for (this.i=800;this.i<801+weaponscount;this.i++){
    if (!startswith(-,#w(this.i-800))){
      showimg this.i,#W(this.i-800),this.placex,this.placey;
      changeimgvis this.i,5;
      showtext this.i+64,this.placex,this.placey+22,arial,l,#s(client.#w(this.i-800)quantity);
      changeimgzoom this.i+64,.5;
      changeimgcolors this.i+64,.5,1,.5,1;
      changeimgvis this.i+64,6;

Make the quantity show as a text in the qmenu though this could easily be applied to other things.

I only did it this way because I was going to have a weight restriction so the player would only be holding 30 or so weapons at a time so it wouldnt clog up client flags too much.

Thanks everyone. Beholder, I made a check to ensure that even if the weapon indexes were not the same, they will still be addressed correctly.

Tricxta, I was thinking of doing the exact same method. However, you have one string for every item. Is that really okay performance wise? I was wondering if a string list would make it any faster.

performance wise its fine. Elegancy wise its crap…If you could some how manage to give each weapon a unique identifier you could then store things through one client array. An idea for unique identification is in each weapon scripting have something like this: (retrieving the id for use in a script)

if (getID){
setstring client.weaponID,0;
callweapon someweaponindex,getID,;

Assuming you use a different number each time the number acts as an array index. Might want to think a bit since my scripting methods are “retarded” in some peoples eyes.

All weapons have unique indexes, yes. But should one get removed or updated, the indexes will switch around.

Yeah, I think that’s why tricxta is saying to give the weapons a predefined ID in them.

Thanks, tricxta. I’ve decided simply use a string for each new item. It certainly is ungraceful, but it doesn’t seem to suffer any efficiency loss. I may consider using a Database Weapon to send all my callweapon requests in the future. Something like…

callweapon systemDB,getQuantity,item;

and inside the systemDB weapon, handle the item quantity and showtext?

Would that work?