18.08.2009, 03:20
(
Last edited by Joe Staff; 04/04/2013 at 06:22 PM.
)
A relatively basic include I've made for an upcoming script, I've made this for releasing so it's easy to figure out, even easier to make an item with.
How To Install
1st. Place the a_playerinventory.inc into the "pawno/includes" folder found in your server's directory.
2nd. Open your gamemode's .pwn and add to the top the following line
3rd. Place the following functions in their respective callbacks
Functions
PlayerInventoryToggleWindow(playerid,toggle);
-Use this to bring up the menu so players can use their items. This menu is updated if the other functions are used so they player can see immediate changes if colors are changed or items added. A player uses the arrow keys to control it hit's the sprint button to use an item and the enter/exit vehicle button to close it.
PlayerInventoryAddItem(playerid,ItemName[],amount=1);
-Use this to add a specific item to a player's inventory, It's case sensitive. No more remembering item IDs! Returns 0 if Inventory is full, returns -1 if invalid item name or amount (EX: "Empty" and -1)
PlayerInventoryRemoveItem(playerid,ItemName[],amount=1);
-Use this to remove items from a player's inventory. Once a player's item runs to '0', it turns to "Empty" (or otherwise a useless non-usable item). Returns 0 if item not found, -1 if invalid Item Name or Amount
PlayerInventoryPlayerHasItem(playerid,ItemName[]);
-This is perfect for 'if' statements and can be used for missions to collect things like garbage or paper clips. Returns the amount of the item the player owns
PlayerInventoryPlayerItemData(playerid,slot,ItemNa me[],&Amount,len=sizeof(ItemName));
-Much like GetPlayerWeaponData, this can be used to record down all the items that the player has for saving or for removing
PlayerInventorySetLetterColor(playerid,code);
-This function is used to change the colors of the non-selected lines, the codes go as follows:
returns 0 if invalid code
PlayerInventorySetWindowColor(playerid,colorhex);
-This changes the window's box color, pretty simple. Uses Hexadecimal, but won't stop you from putting in a large decimal number
PlayerInventorySetFont(playerid,font);
-Let's you choose between the fonts found on this page https://sampwiki.blast.hk/wiki/TextDrawFont
Callback
PlayerInventoryUseItem(playerid,ItemName[]);
-This callback is called whenever a player 'uses' a valid (not "Empty") item in their inventory window with the sprint key. This is where you'll be placing your 'definitions' for your items, just like making commands
Download
http://************/d3893lu/files/scr...rinventory.inc -Right Click + Save As...
Pictures
Resources
This can potentially use 400 TextDraws (2 per player on a fuller server)
Also item names can only be 19 characters long, to prevent the textdraw from cutting off, but this will be fixed in the next SA-MP version.
How To Install
1st. Place the a_playerinventory.inc into the "pawno/includes" folder found in your server's directory.
2nd. Open your gamemode's .pwn and add to the top the following line
pawn Code:
#include <a_playerinventory>
pawn Code:
//Inside of OnGameModeInit
PlayerInventoryOnGameModeInit();
//Inside of OnPlayerUpdate
PlayerInventoryOnPlayerUpdate(playerid);
//Inside of OnPlayerKeyStateChange
PlayerInventoryOnPlayerKeyState(playerid,newkeys);
//Outside of any callbacks
public PlayerInventoryUseItem(playerid,ItemName[])
{
return 0;
}
PlayerInventoryToggleWindow(playerid,toggle);
-Use this to bring up the menu so players can use their items. This menu is updated if the other functions are used so they player can see immediate changes if colors are changed or items added. A player uses the arrow keys to control it hit's the sprint button to use an item and the enter/exit vehicle button to close it.
pawn Code:
if(!strcmp(cmdtext[1],"Inventory",true))
{
if(IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid,0xFF0000FF,"You cannot be in a vehicle when searching your inventory.");
PlayerInventoryToggleWindow(playerid,1); //setting to 0 closes the window
return 1;
}
-Use this to add a specific item to a player's inventory, It's case sensitive. No more remembering item IDs! Returns 0 if Inventory is full, returns -1 if invalid item name or amount (EX: "Empty" and -1)
pawn Code:
public OnPlayerPickUpPickup(playerid,pickupid)
{
if(pickupid==paperclip)
{
PlayerInventoryAddItem(playerid,"Paper Clip");
}
}
-Use this to remove items from a player's inventory. Once a player's item runs to '0', it turns to "Empty" (or otherwise a useless non-usable item). Returns 0 if item not found, -1 if invalid Item Name or Amount
pawn Code:
public OnPlayerEnterCheckPoint(playerid)
{
PlayerInventoryRemoveItem(playerid,"Paper Clip",PlayerInventoryPlayerHasItem(playerid,"Paper Clip"));
SendClientMessage(playerid,0xFF0000FF,"You've turned in your paper clips!");
}
-This is perfect for 'if' statements and can be used for missions to collect things like garbage or paper clips. Returns the amount of the item the player owns
pawn Code:
if(!strcmp(cmdtext[1],"ThrowRock",true))
{
if(PlayerInventoryPlayerHasItem(playerid,"Rock"))
{
return SendClientMessage(playerid,0xFF0000FF,"You threw a rock. Take THAT society!");
}
}
-Much like GetPlayerWeaponData, this can be used to record down all the items that the player has for saving or for removing
pawn Code:
if(!strcmp(cmdtext[1],"CheckInventory",true,14))
{
new string[MAX_ITEM_NAME+20];
new amount = strval(cmdtext[16]);
GetPlayerName(amount,string,sizeof(string));
format(string,sizeof(string),"%s has the following items:",string);
SendClientMessage(playerid,0xFF0000FF,string);
for(new index;index<MAX_ITEMS;index++)
{
PlayerInventoryPlayerItemData(playerid,index,string,amount);
format(string,sizeof(string),"%s -- %d",string,amount);
SendClientMessage(playerid,0xFF0000FF,string);
}
SendClientMessage(playerid,0xFF0000FF,"--------------------");
}
-This function is used to change the colors of the non-selected lines, the codes go as follows:
Code:
0 White 1 Green 2 Blue 3 Yellow 4 Purple 5 Black -- Needs a bright box color 6 Light Green 7 Light Blue 8 Light Yellow 9 Light Purple 10 Very Light Green 11 Very Light Blue 12 Very Light Purple
PlayerInventorySetWindowColor(playerid,colorhex);
-This changes the window's box color, pretty simple. Uses Hexadecimal, but won't stop you from putting in a large decimal number
pawn Code:
if(!strcmp(cmdtext[1],"setmyboxcolor",true,13))
{
PlayerInventorySetWindowColor(playerid,strval(cmdtext[15]));
return 1;
}
-Let's you choose between the fonts found on this page https://sampwiki.blast.hk/wiki/TextDrawFont
pawn Code:
if(!strcmp(cmdtext[1],"setmyfont",true,9))
{
PlayerInventorySetFont(playerid,strval(cmdtext[11]));
return 1;
}
PlayerInventoryUseItem(playerid,ItemName[]);
-This callback is called whenever a player 'uses' a valid (not "Empty") item in their inventory window with the sprint key. This is where you'll be placing your 'definitions' for your items, just like making commands
pawn Code:
public PlayerInventoryUseItem(playerid,ItemName[])
{
if(!strcmp(ItemName,"Cheese Burger",false))
{
new Float:tmp;
GetPlayerHealth(playerid,tmp);
SetPlayerHealth(playerid,tmp+10);
PlayerInventoryRemoveItem(playerid,"Cheese Burger");
return 1;
}
if(!strcmp(ItemName,"M4 Assault Rifle",false))
{
GivePlayerWeapon(playerid,31,100);
PlayerInventoryRemoveItem(playerid,"M4 Assault Rifle");
return 1;
}
if(!strcmp(ItemName,"Iron Ore",false))
{
new tmp = PlayerInventoryPlayerHasItem(playerid,"Iron Ore");
if(tmp<5)return SendClientMessage(playerid,0xFF0000FF,"You need 5 Iron Ores to make steel");
PlayerInventoryRemoveItem(playerid,"Iron Ore",5);
PlayerInventoryAddItem(playerid,"Steel Plate",1);
return 1;
}
return SendClientMessage(playerid,0xFF0000FF,"You can't use that item here.");
}
http://************/d3893lu/files/scr...rinventory.inc -Right Click + Save As...
Pictures
Resources
This can potentially use 400 TextDraws (2 per player on a fuller server)
Also item names can only be 19 characters long, to prevent the textdraw from cutting off, but this will be fixed in the next SA-MP version.