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.
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;
}
Cyanide - Project Launcher & Developer SA-MP Team - San Andreas Multiplayer Modification.
I think it's better to create item and then add them to players.
String comparison is not so good as checking system and the saving system probabily won't be useful for all end-users. For example in my rp server, you enter with a nickname that can be or not RP, and then manage your account (a system that provides multiaccount linked to a main account) Therefore, would be better let users implement a saving system theirselfs. Anyway, nice work. |
if(newkeys & KEY_YES)
{
new
itemName[30],
itemDescription[100],
itemAmount,
index;
strdel(DialogString, 0, sizeof(DialogString));
strcat(DialogString, COLOR_HEX_RED"Item\t\t\t\t\tAnzahl\n");
while(listInventoryItems(playerid, itemName, itemDescription, itemAmount, index))
{
format(DialogString, sizeof(DialogString), COLOR_HEX_WHITE"%s%s\t\t\t%d\n", DialogString, itemName, itemAmount);
index++;
}
ShowPlayerDialog(playerid, DIALOG_INVENTORY, DIALOG_STYLE_LIST, "Inventar", DialogString, "Auswдhlen", "Abbrechen");
}
case DIALOG_INVENTORY:
{
if(response)
{
}
}
COMMAND:i(playerid, params[]) { new ilist[780]; new itemName[ 30 ], itemDesc[ 100 ], itemAmm, idx; while( listInventoryItems( playerid, itemName, itemDesc, itemAmm, idx ) ) { format( ilist, sizeof ilist, "{FFFFFF}%s - %s (Amount: %i)\n%s", itemName, itemDesc, itemAmm , ilist); idx ++; } ShowPlayerDialog(playerid, 789, DIALOG_STYLE_LIST, "Inventory", ilist, "Close", "Close"); return 1; }