Need Help In Writing Plugin!

Assassin

Plugin Developer
Plugin Developer
Apr 9, 2017
190
195
43
25
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:


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!!
 

salva

Friendly self-taught developer
Administrator
Jan 31, 2016
576
610
63
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:


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()
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,065
4,486
113
At your house.
github.com
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:


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

Assassin

Plugin Developer
Plugin Developer
Apr 9, 2017
190
195
43
25
Iran

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,065
4,486
113
At your house.
github.com
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

Assassin

Plugin Developer
Plugin Developer
Apr 9, 2017
190
195
43
25
Iran
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
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,065
4,486
113
At your house.
github.com
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
NetUser.MessageFrom(

No.

Replace NetUser with CraftingEvent.Player
 
  • Like
Reactions: Assassin

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,065
4,486
113
At your house.
github.com
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
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!")
 

Assassin

Plugin Developer
Plugin Developer
Apr 9, 2017
190
195
43
25
Iran
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."