Solved Python help

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
So im converting from JS to Python (To increase my python skills :p)
I only have 2 problems while converting.
The first one has to do with variables:
JS version:
JavaScript:
function On_DoorUse(Player, DoorUseEvent) {
    if (toggled(Player)) {
       DoorUseEvent.Open = true;
    }
}
What I have so far: (In Python)
Code:
def On_DoorUse(self, Player, DoorUseEvent):
        if self.toggled(Player):
            if DataStore.Get("AdminPlus", "AccessDoors") == "true":
                DoorUseEvent.Open
Now the problem is in JS DoorUseEvent.Open = true works fine but in Python it thinks its a variable.
This one im not too sure whats going here but using the code below spams the console with:
Code:
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
Unresponsive for 11.478 seconds!
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
Unresponsive for 12.479 seconds!
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
ArgumentTypeException: On_EntityHurt() takes exactly 1 argument (2 given)
It spams about 10 times before stopping then destroying the object. Even if not an admin it will spam BUT will not destroy the object
Python code:
Code:
    def On_EntityHurt(self, HurtEvent):
        if HurtEvent.Attacker.Admin:
            if DataStore.Get("AdminPlus", "DestroyEnabled") == "true":
                if HurtEvent.WeaponName == DataStore.Get("AdminPlus", "DestroyWeapon"):
                    if HurtEvent.Entity.Name != None:
                        HurtEvent.Entity.Destroy()
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
1. DoorUseEvent.Open = True

2. Weird
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
Self stands for the inside methods of the class. Check my github. You need to create a class and then use self at every method. Self is the second arg which u dont have.

Sent from my Samsung Galaxy S4
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
2. is weird if the On_EntityHurt is in the main class, as it should be...
or am I too tired again? :D
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
Can u paste ur code? I wanna see what did u screw about sellffff xd

Sent from my Samsung Galaxy S4
Python:
__title__ = 'AdminPlus'
__author__ = 'Jakkee'
__version__ = '1.0'

import clr

clr.AddReferenceByPartialName("UnityEngine")
clr.AddReferenceByPartialName("Fougerite")

import UnityEngine
import Fougerite

class AdminPlus:
    def On_PluginInit(self):
        Util.ConsoleLog(__title__ + " by " + __author__ + " Version: " + __version__ + " loaded.", False)
        if not Plugin.IniExists("Settings"):
            Plugin.CreateIni("Settings")
            ini = Plugin.GetIni("Settings")
            ini.AddSetting("Config", "DestroyEnabled", "true")
            ini.AddSetting("Config", "DestroyWeapon", "9mm Pistol")
            ini.AddSetting("Config", "TPDistance", "30")
            ini.AddSetting("Commands", "InvisibleSuit", "true")
            ini.AddSetting("Commands", "WoodKit", "true")
            ini.AddSetting("Commands", "MetalKit", "true")
            ini.AddSetting("Commands", "UberKit", "true")
            ini.AddSetting("Commands", "KevlarKit", "true")
            ini.AddSetting("Commands", "AccessDoors", "true")
            ini.AddSetting("Commands", "ClearInventory", "true")
            ini.AddSetting("Commands", "TpAdmin", "true")
            ini.AddSetting("Players", "76561198135558142", "Jakkee")
            ini.Save()
        ini = Plugin.GetIni("Settings")
        DataStore.Add("AdminPlus", "DestroyEnabled", ini.GetSetting("Config", "DestroyEnabled"))
        DataStore.Add("AdminPlus", "Distance", ini.GetSetting("Config", "TPDistance"))
        DataStore.Add("AdminPlus", "DestroyWeapon", ini.GetSetting("Config", "DestroyWeapon"))
        DataStore.Add("AdminPlus", "InvisibleSuit", ini.GetSetting("Commands", "InvisibleSuit"))
        DataStore.Add("AdminPlus", "MetalKit", ini.GetSetting("Commands", "MetalKit"))
        DataStore.Add("AdminPlus", "TpAdmin", ini.GetSetting("Commands", "TpAdmin"))
        DataStore.Add("AdminPlus", "WoodKit", ini.GetSetting("Commands", "WoodKit"))
        DataStore.Add("AdminPlus", "UberKit", ini.GetSetting("Commands", "UberKit"))
        DataStore.Add("AdminPlus", "KevlarKit", ini.GetSetting("Commands", "KevlarKit"))
        DataStore.Add("AdminPlus", "AccessDoors", ini.GetSetting("Commands", "AccessDoors"))
        DataStore.Add("AdminPlus", "ClearInventory", ini.GetSetting("Commands", "ClearInventory"))

    def On_DoorUse(self, Player, DoorUseEvent):
        if self.toggled(Player):
            if DataStore.Get("AdminPlus", "AccessDoors") == "true":
                DoorUseEvent.Open = True

    def On_Command(self, Player, cmd, args):
        if cmd == "admin":
            if Player.Admin:
                if len(args) == 0:
                    Player.MessageFrom("AdminPlus", "Commands;")
                    Player.MessageFrom("AdminPlus", "/tpadmin [name] (Teleports you 30units away from the target)")
                    Player.MessageFrom("AdminPlus", "/tpback (Teleports you back to where you were)")
                    Player.MessageFrom("AdminPlus", "/duty on / off (Tell the server if your on duty or not)")
                    Player.MessageFrom("AdminPlus", "/admin on / off (Inivisible suit)")
                    Player.MessageFrom("AdminPlus", "/admin metal (Spawns metal building parts)")
                    Player.MessageFrom("AdminPlus", "/admin wood (Spawns wood building parts)")
                    Player.MessageFrom("AdminPlus", "/admin uber (Spawns uber items)")
                    Player.MessageFrom("AdminPlus", "/admin kevlar (Spawns kevlar)")
                    Player.MessageFrom("AdminPlus", "/admin clear (Clears your inventory)")
                    Player.MessageFrom("AdminPlus", "/admin doors (Toggles you to open all doors)")
                elif len(args) == 1:
                    if args[0] == "on":
                        if DataStore.Get("AdminPlus", "InvisibleSuit") == "true":
                            Player.Inventory.RemoveItem(36)
                            Player.Inventory.RemoveItem(37)
                            Player.Inventory.RemoveItem(38)
                            Player.Inventory.RemoveItem(39)
                            Player.Inventory.AddItemTo("Invisible Helmet", 36, 1)
                            Player.Inventory.AddItemTo("Invisible Vest", 37, 1)
                            Player.Inventory.AddItemTo("Invisible Pants", 38, 1)
                            Player.Inventory.AddItemTo("Invisible Boots", 39, 1)
                            Player.MessageFrom("AdminPlus", "You're now Invisible!")
                        else:
                            Player.MessageFrom("AdminPlus", "This command has been disabled!")
                    elif args[0] == "off":
                        if DataStore.Get("AdminPlus", "InvisibleSuit") == "true":
                            Player.Inventory.RemoveItem(36)
                            Player.Inventory.RemoveItem(37)
                            Player.Inventory.RemoveItem(38)
                            Player.Inventory.RemoveItem(39)
                            Player.MessageFrom("AdminPlus", "You're now visible!")
                        else:
                            Player.MessageFrom("AdminPlus", "This command has been disabled!")
                    elif args[0] == "wood":
                        if DataStore.Get("AdminPlus", "WoodKit") == "true":
                            Player.Inventory.AddItem("Wood Pillar", 250)
                            Player.Inventory.AddItem("Wood Foundation", 250)
                            Player.Inventory.AddItem("Wood Wall", 250)
                            Player.Inventory.AddItem("Wood Doorway", 250)
                            Player.Inventory.AddItem("Wood Window", 250)
                            Player.Inventory.AddItem("Wood Stairs", 250)
                            Player.Inventory.AddItem("Wood Ramp", 250)
                            Player.Inventory.AddItem("Wood Ceiling", 250)
                            Player.Inventory.AddItem("Metal Door", 15)
                            Player.Inventory.AddItem("Metal Window Bars", 15)
                            Player.MessageFrom("AdminPlus", "Wood building parts spawned!")
                        else:
                            Player.MessageFrom("AdminPlus", "This command has been disabled!")
                    elif args[0] == "metal":
                        if DataStore.Get("AdminPlus", "MetalKit") == "true":
                            Player.Inventory.AddItem("Metal Pillar", 250)
                            Player.Inventory.AddItem("Metal Foundation", 250)
                            Player.Inventory.AddItem("Metal Wall", 250)
                            Player.Inventory.AddItem("Metal Doorway", 250)
                            Player.Inventory.AddItem("Metal Window", 250)
                            Player.Inventory.AddItem("Metal Stairs", 250)
                            Player.Inventory.AddItem("Metal Ramp", 250)
                            Player.Inventory.AddItem("Metal Ceiling", 250)
                            Player.Inventory.AddItem("Metal Door", 15)
                            Player.Inventory.AddItem("Metal Window Bars", 15)
                            Player.MessageFrom("AdminPlus", "Metal building parts spawned!")
                        else:
                            Player.MessageFrom("AdminPlus", "This command has been disabled!")
                    elif args[0] == "uber":
                        if DataStore.Get("AdminPlus", "UberKit") == "true":
                            Player.Inventory.AddItem("Uber Hatchet", 1)
                            Player.Inventory.AddItem("Uber Hunting Bow", 1)
                            Player.Inventory.AddItem("Arrow", 40)
                            Player.MessageFrom("AdminPlus", "Uber items spawned!")
                        else:
                            Player.MessageFrom("AdminPlus", "This command has been disabled!")
                    elif args[0] == "kevlar":
                        if DataStore.Get("AdminPlus", "KevlarKit") == "true":
                            Player.Inventory.RemoveItem(36)
                            Player.Inventory.RemoveItem(37)
                            Player.Inventory.RemoveItem(38)
                            Player.Inventory.RemoveItem(39)
                            Player.Inventory.AddItemTo("Kevlar Helmet", 36, 1)
                            Player.Inventory.AddItemTo("Kevlar Vest", 37, 1)
                            Player.Inventory.AddItemTo("Kevlar Pants", 38, 1)
                            Player.Inventory.AddItemTo("Kevlar Boots", 39, 1)
                            Player.MessageFrom("AdminPlus", "I hope you have a legitimate reason why need this!")
                        else:
                            Player.MessageFrom("AdminPlus", "This command has been disabled!")
                    elif args[0] == "clear":
                        if DataStore.Get("AdminPlus", "ClearInventory") == "true":
                            Player.Inventory.ClearAll()
                            Player.MessageFrom("AdminPlus", "Inventory cleared!")
                        else:
                            Player.MessageFrom("AdminPlus", "This command has been disabled!")
                    elif args[0] == "doors":
                        if DataStore.Get("AdminPlus", "AccessDoors") == "true":
                            self.toggle(Player)
                        else:
                            Player.MessageFrom("AdminPlus", "This command has been disabled!")
                    else:
                        Player.MessageFrom("AdminPlus", "Unknown command")
                else:
                    Player.MessageFrom("AdminPlus", "usage: /admin")
            else:
                Player.MessageFrom("AdminPlus", "You're not allowed to use this command!")
        elif cmd == "duty":
            if Player.Admin:
                if len(args) == 0:
                    Player.MessageFrom("AdminPlus", "Usage: /duty [on/off]")
                elif len(args) == 1:
                    if args[0] == "on":
                        DataStore.Add("AdminPlus", "DutyOn", Player.SteamID)
                        Server.Broadcast(Player.Name + " is now on duty! Let him/her know if you need anything!")
                    elif args[0] == "off":
                        DataStore.Remove("AdminPlus", "DutyOn")
                        Server.Broadcast(Player.Name + " is now on duty! Let him/her know if you need anything!")
                    else:
                        Player.MessageFrom("AdminPlus", "Unknown Command")
                else:
                    Player.MessageFrom("AdminPlus", "Usage: /duty [on/off]")
            else:
                Player.MessageFrom("AdminPlus", "You are not allowed to use that command!")
        elif cmd == "tpadmin":
            if Player.Admin:
                if DataStore.Get("AdminPlus", "TpAdmin") == "true":
                    if len(args) == 0:
                        Player.MessageFrom("AdminPlus", "Usage: /tpadmin [Player Name]")
                    elif len(args) > 0:
                        text = self.argsToText(args)
                        targetname = Player.Find(text)
                        if targetname != None:
                            DataStore.Add("SavedLocation", Player.SteamID, Player.Location)
                            Player.TeleportTo(targetname, 30)
                            Player.MessageFrom("AdminPlus", "Teleported: 30m Behind: " + text)
                            Player.MessageFrom("AdminPlus", "Use /tpback to go back to the last location")
                        else:
                            Player.Message("Can not find player: " +text)
                    else:
                        Player.MessageFrom("AdminPlus", "Unknown Command")
                else:
                    Player.MessageFrom("AdminPlus", "This command has been disabled!")
            else:
                Player.MessageFrom("AdminPlus", "You are not allowed to use that command!")
        elif cmd == "tpback":
            if Player.Admin:
                if len(args) == 0:
                    if DataStore.Get("SavedLocation", Player.SteamID):
                        BLocation = DataStore.Get("SavedLocation", Player.SteamID)
                        Player.TeleportTo(BLocation)
                        DataStore.Remove("SavedLocation", Player.SteamID)
                        Player.MessageFrom("AdminPlus", "Teleported back!")
                    else:
                        Player.MessageFrom("AdminPlus", "You have no last known locations")
                elif len(args) > 0:
                    Player.MessageFrom("AdminPlus", "Usage: /tpback")
            else:
                Player.MessageFrom("AdminPlus", "You are not allowed to use that command!")


    def On_PlayerDisconnected(self, Player):
        DataStore.Remove("SavedLocation", Player.SteamID)
        if DataStore.Get("AdminPlus", "DutyOn", Player.SteamID):
            DataStore.Remove("AdminPlus", "DutyOn")
            Server.Broadcast(Player.Name + " is now off duty! Please direct questions to another admin!")

    def On_EntityHurt(self, HurtEvent):
        if HurtEvent.Attacker.Admin:
            if DataStore.Get("AdminPlus", "DestroyEnabled") == "true":
                if HurtEvent.WeaponName == DataStore.Get("AdminPlus", "DestroyWeapon"):
                    if HurtEvent.Entity.Name != None:
                        HurtEvent.Entity.Destroy()

    def toggle(self, Player):
        ini = Plugin.GetIni("Settings")
        if ini.GetSetting("Players", Player.SteamID) == None:
            ini.AddSetting("Players", Player.SteamID, Player.Name)
            ini.Save()
            Player.MessageFrom("AdminPlus", "You have been added to the config!")
            Player.MessageFrom("AdminPlus", "You can now open any door")
        else:
            ini.DeleteSetting("Players", Player.SteamID)
            ini.Save()
            Player.MessageFrom("AdminPlus", "You have been removed from the config!")
            Player.MessageFrom("AdminPlus", "You can no longer open any door")

    def toggled(self, Player):
        ini = Plugin.GetIni("Settings")
        if ini.GetSetting("Players", Player.SteamID) != None:
            return True
        else:
            return False

    def argsToText(self, args):
        text = ""
        if len(args) == 1:
            text = args[0]
        else:
            for l in xrange(0, len(args)):
                l += 1
                if l == (len(args) - 1):
                    text += args[l]
                else:
                    text += args[l] + " "
        return text

EDIT:After restarting multiple times the spam has stopped and now works without spiting any errors.
 
Last edited by a moderator:

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
Lol. I wanted to say that i dont see any problems since you are using my structure/style and i even see some.converted methods, and ur entityhurt is under class with self. No idea. What i know that ironpy sometimes doesnt reload the plugins when u have an error. o_O. Good job on the syntax looking good ^^

Sent from my Samsung Galaxy S4
 

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
932
113
Australia
Lol. I wanted to say that i dont see any problems since you are using my structure/style and i even see some.converted methods, and ur entityhurt is under class with self. No idea. What i know that ironpy sometimes doesnt reload the plugins when u have an error. o_O. Good job on the syntax looking good ^^

Sent from my Samsung Galaxy S4
Yeah, I have been looking at your plugins for help ;)

Btw u can use code for pasting python code on the site. There is a syntax for it :p

Sent from my Samsung Galaxy S4
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
wow, you can't use python syntax with the Perfromance skin! Or does different skins uses different cache?
 

balu92

Retired Staff
Retired Staff
Trusted Member
Jul 11, 2014
338
75
28
34
What do you mean?

Sent from my Samsung Galaxy S4
I changed back to the other style and I don't see the other syntaxes, changed back the Dark, I see all now again.
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,093
4,784
113
At your house.
github.com
Looool i never remembered adding a style like zhat. Anyway i will still need to do something with the style it is greenish. I guess we can have a nice style with a logo and thats it.

Sent from my Samsung Galaxy S4
 

CorrosionX

Plugin Developer
Plugin Developer
Sep 3, 2014
212
85
18
California
Looool i never remembered adding a style like zhat. Anyway i will still need to do something with the style it is greenish. I guess we can have a nice style with a logo and thats it.

Sent from my Samsung Galaxy S4
It's the default, preinstalled style....XD


ALSO its just bbcode so CODE=PYTHON is what is needed :)
 
Last edited: