Hello everyone,
I am trying to get skin name from an item but i don't get it, i just try the following code, but it won't give me the correct name of the applyed skin (@Wulf)
This code give me "assets/content/workshop/......"Code:Item item = ItemManager.CreateByName("pistol.semiauto", 1, 10087); if (item != null) { if (item.info.skins?.Length > 0) Puts(item.info.skins[0].name); }
skin 10087 should be "Contamination Pistol" aka See Oxide APICode:Item item = ItemManager.CreateByName("pistol.semiauto", 1, 10087); if (item != null) { if (item.info.skins?.Length > 0) Puts(item.info.skins[0].name); }
but it return me Polymer SAP skin name
Can someone have a tips about it?
Solved Getting skin name from item?
Discussion in 'Rust Development' started by sami37, Feb 25, 2017.
-
Well. Since there are multiple values within item.info.skins you would have to search and find which one matches. For the semi there is four or so, [0,1,2,3] so if you just loop through that and match the ID's then it should work.
Code:item.skin = 10087; for(var i = 0; i < item.info.skins.Length; i++){ if(item.info.skins[i].id == Convert.ToInt32(item.skin)){ Puts("Skin Name: "+item.info.skins[i].name); break; } continue; }
-
18:05 [Info] [Giveaway] assets/content/workshop/skin/pistol.semi/red shine/skin.semiautopistol.redshine.itemskin.asset
18:05 [Info] [Giveaway] assets/content/workshop/skin/pistol.semi/semiauto pistol reaper note/skin.semiautopistol.reapernotepistol.itemskin.asset
18:05 [Info] [Giveaway] assets/content/workshop/skin/pistol.semi/contamination pistol/skin.semiautopistol.contaminationpistol.itemskin.asset
18:05 [Info] [Giveaway] assets/content/workshop/skin/pistol.semi/halloween bat/skin.semiautopistol.halloweenbat.itemskin.asset
18:06 [Info] [Giveaway] Polymer SAP
18:06 [Info] [Giveaway] Polymer SAP
18:06 [Info] [Giveaway] Paint Rush SAP
18:06 [Info] [Giveaway] Golden Leaf SAP
18:06 [Info] [Giveaway] Salt Shaker SAP
18:06 [Info] [Giveaway] Tehno Pistol
18:06 [Info] [Giveaway] LCD Marine Sidearm
18:06 [Info] [Giveaway] Nightmare
18:06 [Info] [Giveaway] Desert Hunter
18:06 [Info] [Giveaway] Poseidon Semi Auto Pistol
18:06 [Info] [Giveaway] Ol' Greasy
[/CODE] -
Getting the english name is fairly easy:
Code:item.info.skins[0].invItem.displayName.english;
-
Nvm, i also have to check for id.
thanks for help -
@sami37 Could you release the code how you did it?
-
Code:
Item item = ItemManager.CreateByName(name, Convert.ToInt32(info.Value), skin); if (item != null) { var itemName = item.info.displayName.translated; if (item.info.skins?.Length > 0) { for (var si = 0; si < item.info.skins.Length; si++) { if (item.info.skins[si].id == (int) skin) { itemName += " (" + item.info.skins[si].invItem.displayName.english + " skin)"; } } } SendReply(player, string.Format( lang.GetMessage("ItemList", this, player.UserIDString), itemName, info.Value)); }