基本要求
1.安装了完美平台互联插件(最新版本)
2.安装了Store插件(最新版本)
3.了解SourceMod的基础编译和编写
store.inc 头文件,没有请创建 并放到sourcemod 脚本编译器的include下
#if defined _store_included
#endinput
#endif
#define _store_included
int g_cvarChatTag = -1;
#define CHAT_TAG g_eCvars[g_cvarChatTag].sCache
#define ITEM_NAME_LENGTH 128
#define STORE_MAX_ITEMS 2048
#define STORE_MAX_HANDLERS 64
#define STORE_MAX_PLANS 8
#define STORE_MAX_SLOTS 32
#define STORE_ITEM_MAX_PRICE 999999
enum struct Item_Plan
{
char szName[ITEM_NAME_LENGTH];
int iPrice;
int iTime;
}
enum struct Store_Item
{
char szName[ITEM_NAME_LENGTH];
char szUniqueId[PLATFORM_MAX_PATH];
char szShortcut[64];
int iId;
int iPrice;
int iParent;
int iHandler;
int iFlagBits;
int iData;
int iPlans;
bool bBuyable;
bool bIgnoreVIP;
Handle hAttributes;
char szItemNote[100];
bool bException_Free;
char szAvailable_server_type[64];
char szUnAvailable_server_type[64];
bool bDisable;
int iSlot;
bool bGroupItem;
}
enum struct Type_Handler
{
char szType[64];
char szUniqueKey[32];
bool bEquipable;
bool bRaw;
Handle hPlugin;
Function fnMapStart;
Function fnReset;
Function fnConfig;
Function fnUse;
Function fnRemove;
}
enum struct Client_Item
{
int iId;
int iUniqueId;
bool bSynced;
bool bDeleted;
int iDateOfPurchase;
int iDateOfExpiration;
int iPriceOfPurchase;
}
native Store_RegisterHandler(String:type[], String:uniquekey[], Function:mapstart, Function:reset, Function:config, Function:use, Function:remove, bool:equipable = true, bool:raw = false);
native Store_RegisterMenuHandler(String:identifier[], Function:menu, Function:handler);
native Store_SetDataIndex(itemid, index);
native Store_GetDataIndex(itemid);
native Store_GetEquippedItem(client, String:type[], slot=0);
native Store_IsClientLoaded(client);
native Store_IsClientFullLoaded(client);
native Store_DisplayPreviousMenu(client);
native Store_SetClientMenu(client, num);
native Store_GetClientCredits(client);
native Store_SetClientCredits(client, credits);
native Store_IsClientVIP(client);
native Store_IsItemInBoughtPackage(client, itemid, uid=-1);
native Store_ShouldConfirm();
native Store_DisplayConfirmMenu(client, String:title[], Function:callback, data);
native int Store_GetItem(int itemid, any output[sizeof(Store_Item)]);
native void Store_GetHandler(int index, any output[sizeof(Type_Handler)]);
native Store_GiveItem(client, itemid, purchase=0, expiration=0, price=0);
native Store_RemoveItem(client, itemid);
native bool Store_GetClientItem(int client, int itemid, any output[sizeof(Client_Item)]);
native Store_GetClientTarget(client);
native Store_GiveClientItem(client, recipient, itemid);
native Store_HasClientItem(client, itemid);
native Store_IterateEquippedItems(client, &start, bool:attributes=false);
native Store_ReloadClient(int client);
native Store_GiveItemByUniqueId(int client, const char[] C_UniqueId, int C_purchase, int C_expiration, int C_price);
// forwards
forward Action Store_OnClientModelChanged(client, const char[] szModelPath,bool bIsArmsModel);
forward void Store_OnItemEquipPost(client, const char[] szType,const char[] m_szUniqueId,const char [] szitemName);//装备物品
forward void Store_OnItemUnEquipPost(client, const char[] szType,const char[] m_szUniqueId,const char [] szitemName);//取消装备物品
forward void Store_OnClientLoaded(int client,int Loadstats);
forward Action Store_OnInventoryLoad_Pre(int client,const char[] szType,const char[] m_szUniqueId);
//配置加载完成 Total_items 代表物品总数
forward void Store_OnConfigLoaded(int Total_items);
//如果 return Plugin_Changed; 则视为拥有. 默认请 return Plugin_Continue;
forward Action Store_OnClientHasItem_Pre(int client,int itemid,const char[] szType,const char[] m_szUniqueId);
//人物皮肤应用完成.
forward void Store_OnPlayerSkinAlreadyApplied(int client,bool is_arms,const char[] sModel,const char[] sArms,int iBodyID,int iSkinId,int iGender);
public SharedPlugin __pl_store =
{
name = "store",
file = "store.smx",
#if defined REQUIRE_PLUGIN
required = 1,
#else
required = 0,
#endif
};
#if !defined REQUIRE_PLUGIN
public void __pl_store_SetNTVOptional()
{
MarkNativeAsOptional("Store_GetDataIndex");
MarkNativeAsOptional("Store_GetEquippedItem");
MarkNativeAsOptional("Store_IsClientLoaded");
MarkNativeAsOptional("Store_IsClientFullLoaded");
MarkNativeAsOptional("Store_DisplayPreviousMenu");
MarkNativeAsOptional("Store_SetClientMenu");
MarkNativeAsOptional("Store_GetClientCredits");
MarkNativeAsOptional("Store_SetClientCredits");
MarkNativeAsOptional("Store_IsClientVIP");
MarkNativeAsOptional("Store_IsItemInBoughtPackage");
MarkNativeAsOptional("Store_ShouldConfirm");
MarkNativeAsOptional("Store_DisplayConfirmMenu");
MarkNativeAsOptional("Store_GetItem");
MarkNativeAsOptional("Store_GetHandler");
MarkNativeAsOptional("Store_GiveItem");
MarkNativeAsOptional("Store_RemoveItem");
MarkNativeAsOptional("Store_GetClientItem");
MarkNativeAsOptional("Store_GetClientTarget");
MarkNativeAsOptional("Store_GiveClientItem");
MarkNativeAsOptional("Store_HasClientItem");
MarkNativeAsOptional("Store_IterateEquippedItems");
MarkNativeAsOptional("Store_ReloadClient");
MarkNativeAsOptional("Store_GiveItemByUniqueId");
MarkNativeAsOptional("Store_SetPlayerSkinVIP");
MarkNativeAsOptional("Store_SetItemNote");
MarkNativeAsOptional("Store_SetItemName");
MarkNativeAsOptional("Store_GetItemIdByUniqueId");
MarkNativeAsOptional("Store_SetItemExceptionFree");
}
#endif
完美平台创建道具 并利用store进行直售
- 假设我们在完美平台创建一个道具 ID为 12345 名称为 人物皮肤(夏娜)
#pragma semicolon 1
#include <sourcemod>
#include <store>
#include <xnet_pwd_connect>
#define ITEMID 12345 //定义物品ID
//兑换命令注册 这里就以 !12345
public void OnPluginStart()
{
RegConsoleCmd("sm_12345",OnStoreItem);
}
//兑换命令 回调
public Action OnStoreItem(int client, int args)
{
//基本验证 确认玩家SteamID64 已被主插件获取.
if(!PWDItem_IsClientSteamValid(client))
{
PrintToChat(client," 由于系统未能获取您的数据 暂时无法使用 请稍后或重新加入服务器.");
return Plugin_Handled;
}
//向完美服务器发送物品信息请求.
PWDItem_GetUserItem(client,ITEMID);
return Plugin_Handled;
}
//当完美服务器返回道具信息请求时回调 【请注意 即使道具数量为0 counts也应该返回为0 没有收到说明请求发生失败】
public void PWDItem_OnGetItemAny(int client,int itemid,int counts)
{
if(itemid == ITEMID)
{
if(counts > 0)
{
//把命令发送给完美服务器 用掉物品id 12345 数量为1个
PWDItem_UseItem(client,12345,1);
}
}
}
// 使用物品结果反馈
public void PWDItem_OnItemUsePost(int client,int itemid,const char[] sDesc,int Amount)
{
// 判断是否成功 当完美服务器返回 物品id12345 数量为1 就代表了消耗了 Amount 数量的道具
if(itemid == 12345 && Amount == 1)
{
//Store_GiveItemByUniqueId(client, "Store物品解锁ID(取决于配置文件 unique_id属性)", 购买时间(timestamp), (到期timestamp 0 = 永久), (物品价值));//调用store API 下发物品
Store_GiveItemByUniqueId(client, "playerskin_abcd123", GetTime(), 0, 10000);
}
}
作者:admin 创建时间:2022-08-10 22:38
最后编辑:admin 更新时间:2024-09-25 02:22
最后编辑:admin 更新时间:2024-09-25 02:22