Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Shop_GiveClientItem (probably unfinished, need tests) #112

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions addons/sourcemod/scripting/shop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ConVar g_hHideCategoriesItemsCount;
#include "shop/item_manager.sp"
#include "shop/player_manager.sp"
#if defined _SteamWorks_Included
#include "shop/stats.sp"
#include "shop/stats.sp"
#endif

public Plugin myinfo =
Expand Down Expand Up @@ -1511,15 +1511,15 @@ bool RemoveItemEx(int client, const char[] sItemId, int count = 1)
return PlayerManager_RemoveItemEx(client, sItemId, count);
}

bool GiveItem(int client, int item_id)
bool GiveItem(int client, int item_id, int giveCount = 1)
{
char sItemId[16];
IntToString(item_id, sItemId, sizeof(sItemId));

return GiveItemEx(client, sItemId);
return GiveItemEx(client, sItemId, giveCount);
}

bool GiveItemEx(int client, const char[] sItemId)
bool GiveItemEx(int client, const char[] sItemId, int giveCount = 1)
{
int category_id, price, sell_price, count, duration;
ItemType type;
Expand All @@ -1536,7 +1536,7 @@ bool GiveItemEx(int client, const char[] sItemId)
{
char category[SHOP_MAX_STRING_LENGTH];
ItemManager_GetCategoryById(category_id, category, sizeof(category));
if (!ItemManager_OnItemBuyEx(client, category_id, category, StringToInt(sItemId), item, type, price, sell_price, (type == Item_Finite) ? count : duration))
if (!ItemManager_OnItemBuyEx(client, category_id, category, StringToInt(sItemId), item, type, price, sell_price, (type == Item_Finite) ? giveCount : duration))
{
return false;
}
Expand All @@ -1546,7 +1546,9 @@ bool GiveItemEx(int client, const char[] sItemId)
{
if (ClientHasItemEx(client, sItemId))
{
return false;
int timeleft = PlayerManager_GetItemTimeleftEx(client, sItemId);
if(timeleft <= 0) return true; // Do not change a time of an infinite item
return PlayerManager_SetItemTimeleftEx(client, sItemId, timeleft + duration * giveCount);
}
}
}
Expand Down
50 changes: 13 additions & 37 deletions addons/sourcemod/scripting/shop/player_manager.sp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ public int PlayerManager_GiveClientItem(Handle plugin, int numParams)
ThrowNativeError(SP_ERROR_NATIVE, error);
}

int item_id = GetNativeCell(2);

return GiveItem(client, item_id);
return GiveItem(client, GetNativeCell(2), GetNativeCell(3));
}

public int PlayerManager_BuyClientItem(Handle plugin, int numParams)
Expand All @@ -155,9 +153,7 @@ public int PlayerManager_BuyClientItem(Handle plugin, int numParams)
if (!CheckClient(client, error, sizeof(error)))
ThrowNativeError(SP_ERROR_NATIVE, error);

int item_id = GetNativeCell(2);

return BuyItem(client, item_id, true);
return BuyItem(client, GetNativeCell(2), true);
}

public int PlayerManager_SellClientItem(Handle plugin, int numParams)
Expand All @@ -170,9 +166,7 @@ public int PlayerManager_SellClientItem(Handle plugin, int numParams)
ThrowNativeError(SP_ERROR_NATIVE, error);
}

int item_id = GetNativeCell(2);

return SellItem(client, item_id);
return SellItem(client, GetNativeCell(2));
}

public int PlayerManager_UseClientItem(Handle plugin, int numParams)
Expand All @@ -183,9 +177,7 @@ public int PlayerManager_UseClientItem(Handle plugin, int numParams)
if (!CheckClient(client, error, sizeof(error)))
ThrowNativeError(SP_ERROR_NATIVE, error);

int item_id = GetNativeCell(2);

return UseItem(client, item_id, true);
return UseItem(client, GetNativeCell(2), true);
}

public int PlayerManager_RemoveClientItem(Handle plugin, int numParams)
Expand All @@ -196,10 +188,7 @@ public int PlayerManager_RemoveClientItem(Handle plugin, int numParams)
if (!CheckClient(client, error, sizeof(error)))
ThrowNativeError(SP_ERROR_NATIVE, error);

int item_id = GetNativeCell(2);
int count = GetNativeCell(3);

return PlayerManager_RemoveItem(client, item_id, count);
return PlayerManager_RemoveItem(client, GetNativeCell(2), GetNativeCell(3));
}

public int PlayerManager_GetClientItemCount(Handle plugin, int numParams)
Expand All @@ -210,9 +199,7 @@ public int PlayerManager_GetClientItemCount(Handle plugin, int numParams)
if (!CheckClient(client, error, sizeof(error)))
ThrowNativeError(SP_ERROR_NATIVE, error);

int item_id = GetNativeCell(2);

return PlayerManager_GetItemCount(client, item_id);
return PlayerManager_GetItemCount(client, GetNativeCell(2));
}

public int PlayerManager_SetClientItemCount(Handle plugin, int numParams)
Expand All @@ -223,9 +210,7 @@ public int PlayerManager_SetClientItemCount(Handle plugin, int numParams)
if (!CheckClient(client, error, sizeof(error)))
ThrowNativeError(SP_ERROR_NATIVE, error);

int item_id = GetNativeCell(2);

PlayerManager_SetItemCount(client, item_id, GetNativeCell(3));
PlayerManager_SetItemCount(client, GetNativeCell(2), GetNativeCell(3));
}

public int PlayerManager_GetClientItemSellPrice(Handle plugin, int numParams)
Expand All @@ -236,9 +221,7 @@ public int PlayerManager_GetClientItemSellPrice(Handle plugin, int numParams)
if (!CheckClient(client, error, sizeof(error)))
ThrowNativeError(SP_ERROR_NATIVE, error);

int item_id = GetNativeCell(2);

return PlayerManager_GetItemSellPrice(client, item_id);
return PlayerManager_GetItemSellPrice(client, GetNativeCell(2));
}

public int PlayerManager_SetClientItemTimeleft(Handle plugin, int numParams)
Expand Down Expand Up @@ -275,9 +258,7 @@ public int PlayerManager_IsClientItemToggled(Handle plugin, int numParams)
if (!CheckClient(client, error, sizeof(error)))
ThrowNativeError(SP_ERROR_NATIVE, error);

int item_id = GetNativeCell(2);

return PlayerManager_IsItemToggled(client, item_id);
return PlayerManager_IsItemToggled(client, GetNativeCell(2));
}

public int PlayerManager_IsClientHasItem(Handle plugin, int numParams)
Expand All @@ -288,9 +269,7 @@ public int PlayerManager_IsClientHasItem(Handle plugin, int numParams)
if (!CheckClient(client, error, sizeof(error)))
ThrowNativeError(SP_ERROR_NATIVE, error);

int item_id = GetNativeCell(2);

return PlayerManager_ClientHasItem(client, item_id);
return PlayerManager_ClientHasItem(client, GetNativeCell(2));
}

public int PlayerManager_ToggleClientItem(Handle plugin, int numParams)
Expand All @@ -301,10 +280,7 @@ public int PlayerManager_ToggleClientItem(Handle plugin, int numParams)
if (!CheckClient(client, error, sizeof(error)))
ThrowNativeError(SP_ERROR_NATIVE, error);

int item_id = GetNativeCell(2);
ToggleState toggle = GetNativeCell(3);

return ToggleItem(client, item_id, toggle, true);
return ToggleItem(client, GetNativeCell(2), GetNativeCell(3), true);
}

void PlayerManager_OnPluginStart()
Expand Down Expand Up @@ -601,12 +577,12 @@ public int PlayerManager_ToggleClientCategoryOff(Handle plugin, int numParams)
if (!CheckClient(client, error, sizeof(error)))
ThrowNativeError(SP_ERROR_NATIVE, error);

int category_id = GetNativeCell(2);

h_KvClientItems[client].Rewind();
if (!h_KvClientItems[client].GotoFirstSubKey())
return;

int category_id = GetNativeCell(2);

char sItemId[16];
do
{
Expand Down
4 changes: 2 additions & 2 deletions addons/sourcemod/scripting/shop/stats.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ stock const char API_KEY[] = "e34fa2f3adb922bf76fb7b06807caa3c";
stock const char URL[] = "http://stats.tibari.ru/api/v1/add_server";

/* Stats pusher */
public int SteamWorks_SteamServersConnected()
public void SteamWorks_SteamServersConnected()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to change it

{
int iIp[4];
char iIp[4];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, why you have changed it


// Get ip
if (SteamWorks_GetPublicIP(iIp))
Expand Down