Raised This Month: $51 Target: $400
 12% 

Developer question: creating a permanent item


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Franc1sco
Veteran Member
Join Date: Oct 2010
Location: Spain (Madrid)
Old 02-24-2013 , 00:27   Developer question: creating a permanent item
Reply With Quote #1

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"
__________________
Veteran Coder -> Activity channel
Coding on CS2 and taking paid and free jobs.

Contact: Steam, Telegram or discord ( franug ).

You like my work? +Rep in my steam profile comments or donate.


Last edited by Franc1sco; 02-24-2013 at 00:31.
Franc1sco is offline
Send a message via MSN to Franc1sco
alongub
Veteran Member
Join Date: Aug 2009
Location: Israel
Old 02-24-2013 , 00:53   Re: Developer question: creating a permanent item
Reply With Quote #2

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.
__________________

Last edited by alongub; 02-24-2013 at 00:57.
alongub is offline
Franc1sco
Veteran Member
Join Date: Oct 2010
Location: Spain (Madrid)
Old 02-24-2013 , 17:49   Re: Developer question: creating a permanent item
Reply With Quote #3

Quote:
Originally Posted by alongub View Post
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
Attached Files
File Type: zip store-franugitems.zip (31.9 KB, 105 views)
__________________
Veteran Coder -> Activity channel
Coding on CS2 and taking paid and free jobs.

Contact: Steam, Telegram or discord ( franug ).

You like my work? +Rep in my steam profile comments or donate.


Last edited by Franc1sco; 02-24-2013 at 18:59.
Franc1sco is offline
Send a message via MSN to Franc1sco
alongub
Veteran Member
Join Date: Aug 2009
Location: Israel
Old 02-25-2013 , 12:33   Re: Developer question: creating a permanent item
Reply With Quote #4

yeah, it looks great
__________________
alongub is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:46.


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