Need Help In Writing Plugin!

Assassin

Plugin Developer
Plugin Developer
Apr 9, 2017
190
200
43
26
Iran
Hi
here is my code:

Python:
class CraftLimiter:
    def On_Crafting(self, CraftingEvent):
        if CraftingEvent.Item.Name == "M4":
            CraftingEvent.Cancel()
but it is not working when i craft M4 and M4 Crafts successfully and this error happens:
b63l_234.jpg


then i decided to change If CraftingEvent.Item.Name == "M4": to If CraftingEvent.ItemName == "M4":
Then when i craft M4 nothing happens in the console and M4 Crafts successfully!!
 
Hi
here is my code:

Python:
class CraftLimiter:
    def On_Crafting(self, CraftingEvent):
        if CraftingEvent.Item.Name == "M4":
            CraftingEvent.Cancel()
but it is not working when i craft M4 and M4 Crafts successfully and this error happens:
b63l_234.jpg


then i decided to change If CraftingEvent.Item.Name == "M4": to If CraftingEvent.ItemName == "M4":
Then when i craft M4 nothing happens in the console and M4 Crafts successfully!!

Try whit.....

Python:
def On_Crafting(self, CraftingEvent):
        item = CraftingEvent.ResultItem
        if item.Name == "M4" :
            CraftingEvent.Cancel()
 
Hi
here is my code:

Python:
class CraftLimiter:
    def On_Crafting(self, CraftingEvent):
        if CraftingEvent.Item.Name == "M4":
            CraftingEvent.Cancel()
but it is not working when i craft M4 and M4 Crafts successfully and this error happens:
b63l_234.jpg


then i decided to change If CraftingEvent.Item.Name == "M4": to If CraftingEvent.ItemName == "M4":
Then when i craft M4 nothing happens in the console and M4 Crafts successfully!!
http://fougerite.com/wiki/craftingevent/
https://github.com/Notulp/Fougerite/blob/master/Fougerite/Fougerite/Events/CraftingEvent.cs

if CraftingEvent.ItemName == "M4":

or

if CraftingEvent.ResultItem.name == "M4":


You should just incase print out the name of the crafting item, so we know it's name:

Plugin.Log("Crafts", str(CraftingEvent.ItemName) + " Player: " + CraftingEvent.Player.Name)
 
  • Like
Reactions: Assassin
what is differnece between ItemName and ResultItem.name ?
No, sorry, missfired.

public string ItemName
{
get { return _block.name; }
}

public ItemDataBlock ResultItem
{
get { return _block.resultItem; }
}

If you use ItemName you will receive the Blueprint's name
If you use ResultItem.name you will receive the ItemDataBlock name
 
  • Like
Reactions: Assassin
Python:
    def On_Crafting(self, CraftingEvent):
        if CraftingEvent.ResultItem.name == "M4":
            CraftingEvent.Cancel()
        if NetUser.Inventory.HasItem("Low Quality Metal", 120) and NetUser.Inventory.HasItem("Paper", 10):
            NetUser.Inventory.AddItem("M4")
            NetUser.Inventory.RemoveItem("Low Quality Metal",120)
            NetUser.Inventory.RemoveItem("Paper",10)
            Plugin.Log("Gun", Player.Name + " maked M4 !")
            NetUser.MessageFrom(sys,"You maked a [color orange] M4[color orange] Great!")
            return
        else:
            NetUser.MessageFrom(sys, "You Don't have enough Material!")
            return
vwro_1244.jpg
 
Python:
    def On_Crafting(self, CraftingEvent):
        if CraftingEvent.ResultItem.name == "M4":
            CraftingEvent.Cancel()
        if NetUser.Inventory.HasItem("Low Quality Metal", 120) and NetUser.Inventory.HasItem("Paper", 10):
            NetUser.Inventory.AddItem("M4")
            NetUser.Inventory.RemoveItem("Low Quality Metal",120)
            NetUser.Inventory.RemoveItem("Paper",10)
            Plugin.Log("Gun", Player.Name + " maked M4 !")
            NetUser.MessageFrom(sys,"You maked a [color orange] M4[color orange] Great!")
            return
        else:
            NetUser.MessageFrom(sys, "You Don't have enough Material!")
            return
vwro_1244.jpg
NetUser.MessageFrom(

No.

Replace NetUser with CraftingEvent.Player
 
  • Like
Reactions: Assassin
Python:
    def On_Crafting(self, CraftingEvent):
        if CraftingEvent.ResultItem.name == "M4":
            CraftingEvent.Cancel()
        if NetUser.Inventory.HasItem("Low Quality Metal", 120) and NetUser.Inventory.HasItem("Paper", 10):
            NetUser.Inventory.AddItem("M4")
            NetUser.Inventory.RemoveItem("Low Quality Metal",120)
            NetUser.Inventory.RemoveItem("Paper",10)
            Plugin.Log("Gun", Player.Name + " maked M4 !")
            NetUser.MessageFrom(sys,"You maked a [color orange] M4[color orange] Great!")
            return
        else:
            NetUser.MessageFrom(sys, "You Don't have enough Material!")
            return
vwro_1244.jpg
Code is bleeding from several points.

Python:
def On_Crafting(self, CraftingEvent):
    Plugin.Log("Gun", CraftingEvent.Player.Name + " is making " + CraftingEvent.ResultItem.name)
    CraftingEvent.Player.MessageFrom("test", "Debug: " + CraftingEvent.ResultItem.name)
    if CraftingEvent.ResultItem.name == "M4":
        CraftingEvent.Cancel()
        if CraftingEvent.Player.Inventory.HasItem("Low Quality Metal", 120) and CraftingEvent.Player.Inventory.HasItem("Paper", 10):
            CraftingEvent.Player.Inventory.AddItem("M4")
            CraftingEvent.Player.Inventory.RemoveItem("Low Quality Metal",120)
            CraftingEvent.Player.Inventory.RemoveItem("Paper",10)
            CraftingEvent.Player.MessageFrom("test","You maked a [color orange] M4[color orange] Great!")
    else:
        CraftingEvent.Player.MessageFrom("test", "You Don't have enough Material!")
 
Code is bleeding from several points.

Python:
def On_Crafting(self, CraftingEvent):
    Plugin.Log("Gun", CraftingEvent.Player.Name + " is making " + CraftingEvent.ResultItem.name)
    CraftingEvent.Player.MessageFrom("test", "Debug: " + CraftingEvent.ResultItem.name)
    if CraftingEvent.ResultItem.name == "M4":
        CraftingEvent.Cancel()
        if CraftingEvent.Player.Inventory.HasItem("Low Quality Metal", 120) and CraftingEvent.Player.Inventory.HasItem("Paper", 10):
            CraftingEvent.Player.Inventory.AddItem("M4")
            CraftingEvent.Player.Inventory.RemoveItem("Low Quality Metal",120)
            CraftingEvent.Player.Inventory.RemoveItem("Paper",10)
            CraftingEvent.Player.MessageFrom("test","You maked a [color orange] M4[color orange] Great!")
    else:
        CraftingEvent.Player.MessageFrom("test", "You Don't have enough Material!")
see
if i use PluginLog beforce CraftingEvent.Cancel
then they can spam the Log file very Easy!also i can't know who maked m4 sucesfuly!
and whay do you mean with"Code is bleeding from several points."