04.09.2011, 12:34
→ About
Cyanide's Inventory System's name explains itself. This project was launched about three weeks ago.
→ Advantages
→ Functions ( inventorySystem.inc required )
→ Functions Examples ( inventorySystem.inc required )
→ Download
.inc download.
→ Credits
→ Other Notes
The default saving and loading directory is playerInventories/%s.ini, you can configurate that setting by opening inventorySystem.inc and changing line 36 ( INVENTORY_DIRECTORY ). You will need to create the folder for the files to actually save and load.
Cyanide's Inventory System's name explains itself. This project was launched about three weeks ago.
→ Advantages
- Loading and Saving Support.
- Great for Roleplay Servers.
- User Friendly.
- Useful Callbacks.
- Useful Functions.
pawn Код:
public onPlayerReceiveItem( playerid, itemName[ ], description[ ], amount )
{
printf(" Player %i got a %s", playerid, itemName );
}
public onPlayerRemoveItem( playerid, itemName[ ], amount )
{
printf(" Player %i lost %i of %s", playerid, amount, itemName );
}
public onPlayerInventorySaved( playerid, directory[ ] )
{
printf( "Player %i's inventory was just saved to %s", playerid, directory );
}
public onPlayerInventoryLoaded( playerid, directory[ ] )
{
printf( "Player %i's inventory was just loaded from %s", playerid, directory );
}
Код:
countInventoryItems( clientid ) - Counts the amount of inventory items a player has. listInventoryItems( clientid, inv_name[ ], inv_description[ ], &inv_int, &index ) - Lists all inventory items, view forum topic for information. saveInventory( clientid, directory[ ] = INVENTORY_DIRECTORY ) - Saves a inventory. loadInventory( clientid, directory[ ] = INVENTORY_DIRECTORY ) - Laods a inventory. getInventoryItemDesc( clientid, itemName[ ] ) - Gets a item's description. checkInventoryItemQuanity( clientid, itemName[ ] ) - Checks the amount of a item a player has. checkInventoryItem( clientid, itemName[ ] ) - Checks if a player has a inventory item. addInventoryItem( clientid, itemName[ ], description[ ], amount ) - Adds a inventory item. removeInventoryItem( clientid, itemName[ ], amount = 0 ) - Removes a inventory item. resetInventory( clientid ) - Resets a player's inventory. onPlayerReceiveItem( playerid, itemName[ ], description[ ], amount ) - Called when a player gets item. onPlayerRemoveItem( playerid, itemName[ ], amount ) - Called when a player loses a item. onPlayerInventorySaved( playerid, directory[ ] ) - Called when a inventory is saved. onPlayerInventoryLoaded( playerid, directory[ ] ) - Called when a inventory is loaded.
pawn Код:
new
bool:p_logged[ MAX_PLAYERS ]
;
public OnPlayerConnect( playerid )
{
addInventoryItem( playerid, "cow", "this animal echos moo.", 2 ); // The player has two cows!
addInventoryItem( playerid, "Pencil", "You can write with this object", 1 ); // The player has one pencil.
}
public OnPlayerDisconnect( playerid, reason )
{
if( p_logged[ playerid ] == true )
saveInventory( playerid );
return true;
}
public OnPlayerCommandText( playerid, cmdtext[ ] )
{
if( !strcmp( cmdtext, "/login", true ) )
{
...
OnPlayerLogin( playerid, password );
}
if( !strcmp( cmdtext, "/moo", true ) )
{
if( !checkInventoryItem( playerid, "cow" ) )
return SendClientMessage( playerid, 0x0, "{FFFFFF}Since you don't have a cow, you cannot use this command" );
...
}
if( !strcmp( cmdtext, "/myinventory", true ) )
{
new
string[ 150 ],
itemName[ 30 ],
itemDesc[ 100 ],
itemAmm
idx
;
SendClientMessage( playerid, 0x0, "{FFFFFF}You have the following items in your inventory:" );
while( listInventoryItems( playerid, itemName, itemDesc, itemAmm, idx ) )
{
format( string, sizeof string, "{FFFFFF}%s - %s (Amount: %i)", itemName, itemDesc, itemAmm );
SendClientMessage( playerid, 0x0, string );
idx ++;
}
/*
From the items given in OnPlayerConnect, this would print:
cow - this animal echos moo (Amount: 2)
Pencil - You can write with this object (Amount: 1)
*/
}
}
public onPlayerReceiveItem( playerid, itemName[ ], description[ ], amount )
{
if( !strcmp( itemName, "cow", true ) )
return printf("Player %i is now cow-friendly", playerid );
}
public OnPlayerLogin( playerid, password )
{
loadInventory( playerid );
p_logged[ playerid ] = true;
}
.inc download.
→ Credits
Код:
Cyanide - Project Launcher & Developer SA-MP Team - San Andreas Multiplayer Modification.
The default saving and loading directory is playerInventories/%s.ini, you can configurate that setting by opening inventorySystem.inc and changing line 36 ( INVENTORY_DIRECTORY ). You will need to create the folder for the files to actually save and load.