Skip to content
Merged
Changes from 4 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
26 changes: 20 additions & 6 deletions addons/sourcemod/scripting/Shop_ZRSkins.sp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Plugin myinfo =
name = "[Shop] ZR Skins",
author = "AlexTheRegent, .Rushaway",
description = "Buy ZR skins in the shop",
version = "1.2.0",
version = "1.2.1",
url = ""
};

Expand Down Expand Up @@ -112,11 +112,13 @@ void PopulateCategory(CategoryId category, const char[] source)
KeyValues kv = new KeyValues("Skins");
if ( !kv.ImportFromFile(path) ) {
LogError("File \"%s\" not found or broken", source);
delete kv;
return;
}

if ( !kv.GotoFirstSubKey() ) {
LogError("File \"%s\" is empty", source);
delete kv;
return;
}

Expand All @@ -125,16 +127,26 @@ void PopulateCategory(CategoryId category, const char[] source)
kv.GetSectionName(name, sizeof(name));
kv.GetString("skin", path, sizeof(path));
kv.GetString("anim", anim, sizeof(anim));
if ( !IsModelPrecached(path) ) {
PrecacheModel(path);
}

ItemId existingItemId = Shop_GetItemId(category, name);
if (existingItemId != INVALID_ITEM && Shop_IsItemExists(existingItemId)) {
Shop_UnregisterItem(existingItemId);
LogMessage("Item %s already existed and was removed before re-adding", name);
}

if ( path[0] == '\0' ) {
LogError("Item \"%s\" has an empty skin path, skipping", name);
continue;
}

if ( !IsModelPrecached(path) ) {
int precacheIndex = PrecacheModel(path);
if ( precacheIndex == 0 ) {
LogError("Model \"%s\" could not be precached (model table full or invalid path), skipping item \"%s\"", path, name);
continue;
}
}

Shop_StartItem(category, name);

Shop_SetInfo(name, "", kv.GetNum("price", 99999999), kv.GetNum("sell_price", -1), Item_Togglable, kv.GetNum("duration", 86400));
Expand All @@ -145,6 +157,8 @@ void PopulateCategory(CategoryId category, const char[] source)
Shop_EndItem();

} while ( kv.GotoNextKey() );

delete kv;
}

public ShopAction OnSkinSelected(int client, CategoryId category_id, const char[] category, ItemId item_id, const char[] item, bool isOn, bool elapsed)
Expand Down Expand Up @@ -278,7 +292,7 @@ public Action Timer_ChangeSkin(Handle timer, any userid)

void SetSkinSafe(int client, const char[] skin)
{
if ( skin[0] != 0 ) {
if ( skin[0] != 0 && IsModelPrecached(skin) ) {
SetEntityModel(client, skin);
}
Comment thread
Rushaway marked this conversation as resolved.
}
Expand Down Expand Up @@ -525,4 +539,4 @@ stock int GetEdictsCount()
}

return iCount;
}
}
Loading