Author Topic: Adding An Item  (Read 605 times)

How do you add an item to the player's inventory if their inventory is not full?

Code: [Select]
if(%cl.JailRPC < $JailRP::Price::sKnife)
{
messageClient(%cl, "", "\c6You can't afford a Small Knife.");
return;
}

for(%i=0; %i<%cl.player.getDatablock().maxTools; %i++)
{
%tool = %cl.player.tool[%i];
if(%tool == 0)
{
%cl.player.tool[%i] = swordItem.getID();
%cl.player.weaponCount++;
messageClient(%cl, 'MsgItemPickup', '', %i, swordItem.getID());
%i = %cl.player.getDatablock().maxTools;
%transfersuccess = true;
}
}

if(%transferSuccess)
{
%cl.JailRPC -= $JailRP::Price::sKnife;
messageClient(%cl, "", "\c6Alright, here's your Small Knife.  Keep it hidden.");
}
else
messageClient(%cl, "", "\c6I don't think you can hold another item.");

This is from a JailRP mod I made like a year back.  I think it takes code from the additem event.

Looking at it, I think you need a break; after the line %transfersucess = true;
« Last Edit: January 16, 2012, 11:46:56 AM by Nexus »

Thanks!

Off Topic:

Should this work?
Code: [Select]
package Write_To_File {
//=========================================================================
// Writing To File
//=========================================================================
function WriteToFile(%filePath, %string)
{
%file = new fileObject();
%file.openForAppend(%filePath);

%file.writeLine(%string);
   
%file.close();
%file.delete();
}
//=========================================================================
// Find Last Path
//=========================================================================
function findLastPath()
{
%file = new fileObject();
%file.openForRead("config/client/ChatBot/LastFilePath.txt");
while(!%file.isEOF())
{
%line = %file.readLine();
}

%file.readLine();
   
%file.close();
%file.delete();

return %line;
}
//=========================================================================
// Word Detect
//=========================================================================
function NMH_Type::Send(%msg)
{
%firstWord = getWord(%msg, 0);

%path = getWord(%msg, 1);

%line = getWords(%msg, 2, 102);

%lastPath = findLastPath();


if(%firstWord $= "@Write")
{
if(%path $= " ")
{
WriteToFile(%lastPath, %line);
}

else
{
WriteToFile(%path, %line);


%file = new FileObject();
%file.openForWrite("config/client/ChatBot/LastFilePath.txt");

%file.writeLine(%path);

%file.close();
%file.delete();

}
}

else
{
parent::Send(%msg);
}
}


}; activatePackage(Write_To_File);



Why not?
Where do I start... hmm.... Oh yes.

The argument for NMH_Type::Send() is %this. the message is %this.getValue();

And also, what is findLastPath() supposed to do?

And also, what is findLastPath() supposed to do?

Get the last written path in case no path is specified (if you wanted to type individual lines in individual messages). Although, you'd have to type a double space between @Write and the contents.
« Last Edit: January 16, 2012, 02:29:41 PM by Port »

looks okay

remove the extra readline in the second function.

I don't really know much about the function you will hopefully package, but I am not sure you should use getword if there will be no word.