Author Topic: I'm doing something wrong. I'm trying to remove the armor from inventory.  (Read 1832 times)

http://forum.blockland.us/index.php?topic=266715.0

So I like these armors a lot so I'm trying to edit them to fit my needs. The armors can be put on or off at any given moment. This can lead to abuse as people can remove their armors at any given time and reapply new undamaged armor.

I'm trying to get the armor to remove from the inventory, not going so well.


Code: [Select]
function gc_HeavyPlateHelmetMountedImage::onFire(%this, %obj, %slot)
{
    %obj.playthread(2, ThrowingspearThrow);
    serverPlay3D(ThrowingspearFireSound, %obj.getTransform());
    Parent::OnFire(%this, %obj, %slot);

    %currSlot = %obj.gc_HeavyPlateHelmetMountedSlot;
    %obj.tool[%currSlot] = 0;
    %obj.weaponCount--;
    messageClient(%obj.client,'MsgItemPickup','',%currSlot,0);
    serverCmdUnUseTool(%obj.client);
}

function gc_HeavyPlateHelmetMountedImage::onDone(%this,%obj,%slot)
{
    %obj.unMountImage(%slot);
}



function gc_HeavyPlateHelmetMountedImage::onMount(%image, %player, %slot) {
//Hide all hat and accent nodes
for(%i=0; $hat[%i] !$= ""; %i++)
%player.hideNode($hat[%i]);

for(%i=0; $accent[%i] !$= ""; %i++)
%player.hideNode($accent[%i]);
}

function gc_HeavyPlateHelmetMountedImage::onUnmount(%image, %player, %slot) {
if(isObject(%client = %player.client)) {
%client.schedule(100, applyBodyParts);
%client.schedule(100, applyBodyColors);
}
}


Ignore the spear sound thing I was just trying something.

Change this
%currSlot = %obj.gc_HeavyPlateHelmetMountedSlot;
to this
%currSlot = %obj.currTool;

You can also add a 1 to this if you want it to not make the beeping noise.
messageClient(%obj.client,'MsgItemPickup','',%currSlot,0);

It didn't work. So not only it doesn't remove from the inventory it also doesn't mount onto the player.

Try putting this in the onFire or onDone function
Quote from: Code
//Make sure it's the hand image, not the worn armor image
%image = YourArmorItemImage;
//Check 5
for(%i=0;%i<5;%i++)
{
    //Inventory Slots
    %toolDB = %obj.tool[%i];
    //And see if it matches our image
    if(%toolDB $= %image.item.getID())    
    {
        //Remove the item from our hand and inventory
        %obj.tool[%i] = 0;
        %obj.weaponCount--;
        serverCmdUnUseTool(%obj.client);
        messageClient(%obj.client,'MsgItemPickup','',%i,0);
        //Ends the loop check
        break;
    }
}

Don't do what Goth said. It's overly complicated and doesn't support playertypes with more than 5 inventory slots.

Post the image datablock too, so I can know what went wrong.

Don't do what Goth said. It's overly complicated and doesn't support playertypes with more than 5 inventory slots.

Post the image datablock too, so I can know what went wrong.
I don't see how it's overly complicated, but yes it only supports the default 5 slot player. You can easily change the value of the count in the code, or check the datablocks max tools

Code: [Select]
%count= %obj.client.player.getDatablock().maxTools;
for(%i=0;%i<%count;%i++)

?

I don't see how it's overly complicated
Because you don't need to cycle through their inventory. You can just remove their active item.

Because you don't need to cycle through their inventory. You can just remove their active item.
It checks the inventory just in case the player has 2 of the same item, but I suppose you could
do

Code: [Select]
   %currSlot = %obj.currTool;
    %obj.tool[%currSlot] = 0;
    %obj.weaponCount--;
    messageClient(%obj.client,'MsgItemPickup','',%currSlot,0);
    serverCmdUnUseTool(%obj.client);

instead

Your code won't remove multiple items because you put in a break; after it removes the first one.
but I suppose you could
do

Code: [Select]
   %currSlot = %obj.currTool;
    %obj.tool[%currSlot] = 0;
    %obj.weaponCount--;
    messageClient(%obj.client,'MsgItemPickup','',%currSlot,0);
    serverCmdUnUseTool(%obj.client);

instead
Which is exactly what I told him to do. Which he said didn't work. So I'm assuming it's a problem with the weapon states or something.

Code: [Select]
^stateTimeoutValue[0] = 0.1;

^stateTransitionOnTimeout[0] = "Idle";



^stateName[1] = "Idle";

^stateAllowImageChange[1] = true;

};



function gc_HeavyPlateHelmetMountedImage::onFire(%this, %obj, %slot)

//Make sure it's the hand image, not the worn armor image

%image [color=red]##=##[/color] gc_HeavyPlateHelmetMountedImage;

//Check 5

for(%i=0;%i<5;%i++)

{

    //Inventory Slots

    %toolDB = %obj.tool[%i];

    //And see if it matches our image

    if(%toolDB $= %image.item.getID())   

    {

        //Remove the item from our hand and inventory
>>> Error report complete.

ADD-ON "Item_Medieval_Armor" CONTAINS SYNTAX ERRORS

Something is going on with the code I copied from you. I figured it was suppose to be written $= instead of = but that didn't fix it either.

Code: [Select]
function gc_HeavyPlateHelmetMountedImage::onFire(%this, %obj, %slot)

%image [color=red]##=##[/color] gc_HeavyPlateHelmetMountedImage;

ADD-ON "Item_Medieval_Armor" CONTAINS SYNTAX ERRORS
You're missing an open brace.

-edit nevermind
« Last Edit: March 15, 2016, 08:01:43 AM by Goth77 »

You could do something like this instead of a loop code:

Code: server.cs (16 lines)
    //..code..
    if(isObject(%client = %obj.client))
    {
        %currSlot = %obj.currTool; //Object's current slot
        %item = %obj.tool[%currSlot]; //The item (usually it's an ID)
        %image = %obj.tool[%currSlot].image; //Get the image of the current tool the guy is holding
        if(isObject(%item) && isObject(%image)) //Make sure they both exist
            if(%image == %this) //%this = the current image the object is holding, usually it's an ID, you could also do -> if(nameToID(%image) == nameToID(%this))
            {
                %obj.tool[%currSlot] = 0;
                %obj.weaponCount--;
                messageClient(%client, 'MsgItemPickup', '', %currSlot, 0);
                serverCmdUnUseTool(%client);
            }
    }
    //..code..


I'm assuming that what I told him worked. As he hasn't posted since the syntax error was fixed.