Heyo!
I've seen that there was a new hook added - CanCraft(PlayerBlueprints bps, ItemDefinition itemDef, int skinId)
But it doesn't seems to be called at all.
Here is my code:
Aaaand.... nothing. It's not being called at all.Code:void CanCraft(PlayerBlueprints bps, ItemDefinition itemDef, int skinId) { Puts("CanCraft new called!"); }
No matter what I'm doing - I can even start crafting and it's not working.
Can it be cos we already have the hook with the same name? (Also - why creating 2 hooks with the same name?)
New one:
The old one:Code:public bool CanCraft(int itemid, int skinItemId) { ItemDefinition itemDefinition = ItemManager.FindItemDefinition(itemid); if ((UnityEngine.Object) itemDefinition == (UnityEngine.Object) null) { object obj = Interface.CallHook("CanCraft", (object) this, (object) itemDefinition, (object) skinItemId); if (obj is bool) return (bool) obj; return false; } return (skinItemId == 0 || this.steamInventory.HasItem(skinItemId)) && (this.IsParentUnlocked(itemDefinition) && (double) this.baseEntity.currentCraftLevel >= (double) itemDefinition.Blueprint.workbenchLevelRequired) && this.HasUnlocked(itemDefinition); }
The last one seems working, but only if the player has required workbench aronud.Code:public bool CanCraft(ItemBlueprint bp, int amount = 1) { if (amount < 1 || amount > 9000) return false; object obj = Interface.CallHook("CanCraft", (object) this, (object) bp, (object) amount); if (obj is bool) return (bool) obj; foreach (ItemAmount ingredient in bp.ingredients) { if (!this.DoesHaveUsableItem(ingredient.itemid, (int) ingredient.amount * amount)) return false; } return true; }
So..... any ideas why the new one doesn't work?
New hook CanCraft not being called
Discussion in 'Rust Development' started by Vlad-00003, Oct 8, 2017.
-
Wulf Community Admin
Hooks can have the same name now with different arguments, that's what the hook 'overloading' is that @Mughisi added.
I suspect one issuing ignored though, so looking into it. Could you test with each one individually please? -
@Wulf, have you read the latest devblog? Maybe you can help me out.
They said that there is a new RPC - craftLevel
StringPool.GetNumber - no number for string craftLevel
Here is the code I'm using:
Code:[ChatCommand("test")] private void cmdTest(BasePlayer player, string command, string[] args) { if(args.Length < 1) { player.ChatMessage("Wrong args"); return; } int level; if(!int.TryParse(args[0], out level)) { player.ChatMessage("Arg must be int!"); return; } player.ClientRPCPlayer(null, player, "CraftLevel", level); }
-
Wulf Community Admin
For the craftLevel stuff, I'd suggest taking a look at NoWorkbench as I believe it makes use of it. Other than that i am not familiar with it. -
Wulf Community Admin
Should be good in the latest snapshot (on AppVeyor), appeared to have the hook index off a bit.
-
Gonna try and let you know.
[DOUBLEPOST=1507544810][/DOUBLEPOST]Unload doesn't seems to be working as well
[DOUBLEPOST=1507546262][/DOUBLEPOST]Ok, now both hooks seems to be working, but I was expecting the new one being called then the player attempt to craft something without worbench, so we can intercept it and allow players to craft it without workbench.
Looks like it's being handled by the client side, cos the hook doesn't even being called without workbench near it.... -
Wulf Community Admin
-
oh my... what was the main purpose of this? global.reload was interfearing with some games? Dang. That s*cks...