Author Topic: MsgItemPickup  (Read 806 times)

I'm in a bit of a pickle.

I'm trying to make a projectile that puts an item in the collision's inventory. This worked fine. Then, I tried to make the projectile bounce. It has somehow messed with my script.

Code: [Select]
function myProjectile::onCollision(%this,%obj,%col)
{
if(%col.getClassName() $= "Player"){
for(%i=0;%i<%col.getDatablock().maxTools;%i++){
if(!%col.tool[%i]){
%col.tool[%i] = myItem;
messageClient(%col.client, 'MsgItemPickup', '', %i, nameToID(myItem));
break;
}
}
}
parent::onCollision(%this,%obj,%col);
}
Is this just something simple flying over my head?

So wait, you're blaming it on the MsgItemPickup for what reason?

From your description the bounce appears to be messing things up.

I'm not "blaming it" on the MsgItemPickup. I just don't know why it's not working.


%col.getClassName()
I'd use getType() with a player type mask since some stuff such as interiors don't have getClassName()..

%col.tool[%i] = myItem;
Shouldn't this be a datablock ID, not unlike my below point..?

nameToID(myItem)
Seriously, I'd use myItem.getID().

%col.getClassName()
I'd use getType() with a player type mask since some stuff such as interiors don't have getClassName()..

%col.tool[%i] = myItem;
Shouldn't this be a datablock ID, not unlike my below point..?

nameToID(myItem)
Seriously, I'd use myItem.getID().
1. InteriorInstance
2. Unsure about that
3. Tried both

%col.getClassName()
I'd use getType() with a player type mask since some stuff such as interiors don't have getClassName()..

%col.tool[%i] = myItem;
Shouldn't this be a datablock ID, not unlike my below point..?

nameToID(myItem)
Seriously, I'd use myItem.getID().

Every object returns a value for getClassName. A type mask is not an object, its a mask.

nameToId does exactly the same thing as .getId

You said changing the bounce messed things up - if you change it back does it work again?

(%col.getType() & $TypeMasks::PlayerObjectType) works for both players and AIPlayers, instead of having to check the classname against both. Bitwise comparisons might be faster than string comparisons as well, but that's not a huge issue. Choose whichever you think is clearer.