I am trying to make a simple item for store.
My question is, how to check if the a client have a item? and how to save the item for the client (permanently)? I think as below but I am not sure
My plugin
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <store>
new bool:g_databaseInitialized = false;
new bool:g_watergun[MAXPLAYERS+1] = {false, ...};
public OnPluginStart()
{
LoadTranslations("store.phrases");
Store_RegisterItemType("TheWatergun", OnWatergunUse);
HookEvent("player_hurt", Event_PlayerHurt);
}
public Store_OnDatabaseInitialized()
{
g_databaseInitialized = true;
}
public OnClientPostAdminCheck(client)
{
if (!g_databaseInitialized)
return;
g_watergun[client] = false;
Store_GetEquippedItemsByType(Store_GetClientAccountID(client), "TheWatergun", Store_GetClientLoadout(client), OnGetPlayerWatergun, GetClientSerial(client)); // a category only for watergun :p
}
public OnGetPlayerWatergun(ids[], count, any:serial) // callback
{
new client = GetClientFromSerial(serial);
if (client == 0)
return;
for (new index = 0; index < count; index++)
{
decl String:itemName[32];
Store_GetItemName(ids[index], itemName, sizeof(itemName));
if ( StrEqual(itemName,"watergun") ) // if the client have item named watergun ??
g_watergun[client] = true; // now he have watergun
}
}
public Action:Event_PlayerHurt(Handle:event,const String:name[],bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
if(IsValidClient(client) && IsValidClient(attacker) && g_watergun[attacker])
{
SetVariantString("WaterSurfaceExplosion");
AcceptEntityInput(client, "DispatchEffect");
}
}
public OnLibraryAdded(const String:name[])
{
if (StrEqual(name, "store-inventory"))
{
Store_RegisterItemType("watergun", OnWatergunUse);
}
}
public IsValidClient( client )
{
if ( !( 1 <= client <= MaxClients ) || !IsClientInGame(client) )
return false;
return true;
}
// This will be called when players use our item in their inventory.
public Store_ItemUseAction:OnWatergunUse(client, itemId, bool:equipped)
{
if (equipped)
{
decl String:displayName[STORE_MAX_DISPLAY_NAME_LENGTH];
Store_GetItemDisplayName(itemId, displayName, sizeof(displayName));
PrintToChat(client, "%s%t", STORE_PREFIX, "Unequipped item", displayName);
return Store_UnequipItem;
}
else
{
decl String:displayName[STORE_MAX_DISPLAY_NAME_LENGTH];
Store_GetItemDisplayName(itemId, displayName, sizeof(displayName));
PrintToChat(client, "%s%t", STORE_PREFIX, "Equipped item", displayName);
return Store_EquipItem;
}
}
I am not sure if this works but at least compile well xD tell me if there are errors, is supposed that exist a category called "TheWatergun" and the item called "watergun"
__________________