Author Topic: Slot #4 not getting replaced.  (Read 1084 times)

It replaces everything in all the other slots but not in the last slot.

I found adding %player.tool[%i] = %ranWeapon; fixes the issue but then the player's inventory doesn't update.

Without that it replaces the item but not the last item.

Code: [Select]
function QuestionBoxItem::onPickup(%this, %obj, %player){
Parent::onPickup(%this, %obj, %player);
%weaponCount = "";
for(%i=0; %i<DatablockGroup.getCount(); %i++){
%obj = DatablockGroup.getObject(%i);
if(%obj.getClassname() $= "ItemData" && %obj.getName() !$= "QuestionBoxItem")
%weapon[%weaponCount++] = %obj;
}
%ranWeapon = %weapon[getRandom(0,%weaponCount)];

for(%i=0; %i<=4; %i++){
if(%player.tool[%i] == %this){
messageClient(%player,'MsgItemPickup','',%i,%ranWeapon);
break;
}
}
}

I don't see where it's supposed to replace the player's inventory.

Code: [Select]
for(%i=0; %i<=4; %i++){
if(%player.tool[%i] == %this){
messageClient(%player,'MsgItemPickup','',%i,%ranWeapon);
break;
}
}

It loops to find the slot that QuestionBoxItem is in, puts the random weapon in that slot then ends the loop.

You have to be kidding me, Mister "Theres nothing left for me to learn in Torquescript anymore".

the MsgItemPickup just tells the client what image to display in the gui - it won't actually set %player.tool[whatever] to the weapon. It'll just fool the client into thinking they have it.

Quote
I found adding %player.tool[%i] = %ranWeapon; fixes the issue but then the player's inventory doesn't update.

And if you'd like to go back and read that post I don't actually say that there's nothing left for me to learn.

Also, why do you have to flame me every time I ask for help.

Not sure if this will help, but try changing the for loop to stop at <=5 rather than 4.

I'm not used to for loops however, I usually use whiles.

Yes I do realize that the inventory list is 0-4.

Also, the MsgItemPickup does update the server, I just tested.

It done it on my server but not on others, maybe because I was the host or I was playing single-player.
« Last Edit: January 19, 2008, 04:23:16 PM by MrPickle »

I've fixed it, I was sending the wrong variable to the function.