AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Store (https://forums.alliedmods.net/forumdisplay.php?f=157)
-   -   Developer question: creating a permanent item (https://forums.alliedmods.net/showthread.php?t=209299)

Franc1sco 02-24-2013 00:27

Developer question: creating a permanent item
 
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), OnGetPlayerWatergunGetClientSerial(client)); // a category only for watergun :p
}

public 
OnGetPlayerWatergun(ids[], countany:serial// callback
{
    new 
client GetClientFromSerial(serial);
    
    if (
client == 0)
        return;
        
    
    for (new 
index 0index countindex++)
    {
        
decl String:itemName[32];
        
Store_GetItemName(ids[index], itemNamesizeof(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 
IsValidClientclient 

    if ( !( 
<= client <= MaxClients ) || !IsClientInGame(client) ) 
        return 
false
     
    return 
true
}


// This will be called when players use our item in their inventory.
public Store_ItemUseAction:OnWatergunUse(clientitemIdbool:equipped)
{    
    if (
equipped)
    {
    
        
decl String:displayName[STORE_MAX_DISPLAY_NAME_LENGTH];
        
Store_GetItemDisplayName(itemIddisplayNamesizeof(displayName));
        
        
PrintToChat(client"%s%t"STORE_PREFIX"Unequipped item"displayName);
        return 
Store_UnequipItem;
    }
    else
    {
        
        
decl String:displayName[STORE_MAX_DISPLAY_NAME_LENGTH];
        
Store_GetItemDisplayName(itemIddisplayNamesizeof(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"

alongub 02-24-2013 00:53

Re: Developer question: creating a permanent item
 
There's one thing you should change: In Store_GetEquippedItemsByType the 2nd parameter is the type name, not the category. That's also true for Store_RegisterItemType. Type name is a lowered-case, no spaces, and maximum 32 characters string. Change it to watergun, and also change it in the web panel (In edit item, change the item type to watergun).

Oh, and add

Code:

g_watergun[client] = equipped;
to your OnWatergunUse callback.

I'll write a tutorial for creating permanent items soon.

Franc1sco 02-24-2013 17:49

Re: Developer question: creating a permanent item
 
1 Attachment(s)
Quote:

Originally Posted by alongub (Post 1900623)
There's one thing you should change: In Store_GetEquippedItemsByType the 2nd parameter is the type name, not the category. That's also true for Store_RegisterItemType. Type name is a lowered-case, no spaces, and maximum 32 characters string. Change it to watergun, and also change it in the web panel (In edit item, change the item type to watergun).

Oh, and add

Code:

g_watergun[client] = equipped;
to your OnWatergunUse callback.

I'll write a tutorial for creating permanent items soon.

Ok, now my item works well and I understand better how to add items :)


but
Code:

g_watergun[client] = equipped;
will not work correctly because would be reversed because when you take it off the booleand are reversed to as is wanted.


As appreciation I share my article that I created I had to create a new category to add items.


I have also added a simple tracers item.


"alongub" you can check my plugin and tell me if all is fine? surely I will make more items :)


Added: this plugin is working in my servers

alongub 02-25-2013 12:33

Re: Developer question: creating a permanent item
 
yeah, it looks great


All times are GMT -4. The time now is 13:00.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.