| Blockland Forums > Modification Help |
| Adding An Item |
| (1/2) > >> |
| jes00:
How do you add an item to the player's inventory if their inventory is not full? |
| Nexus:
--- Code: ---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."); --- End code --- 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; |
| jes00:
Thanks! Off Topic: Should this work? --- Code: ---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); --- End code --- |
| Ipquarx:
--- Quote from: jes00 on January 16, 2012, 01:48:35 PM ---Off Topic: Should this work? --- End quote --- Nope. |
| jes00:
--- Quote from: Ipquarx on January 16, 2012, 01:56:01 PM ---Nope. --- End quote --- Why not? |
| Navigation |
| Message Index |
| Next page |