This is my Python code:
import es, popuplib, cmdlib
info = es.AddonInfo()
info['name'] = "bilbodog Vaaben Menu"
info['version'] = "1.1"
info['author'] = "bilbodog"
info['url'] = ""
info['description'] = "En vaaben menu der kan give vaaben til spillere"
def load():
es.regclientcmd('bm_version', 'bm/bm_version')
cmdlib.registerSayCommand('!wpa', sendBmMenu, 'Send BM Menu')
es.msg('#multi', '#green[bilbodog Vaaben Menu] #defaultblev loaded!')
global bilbodog, bilbodogSelf, bilbodogOther, bilbodogSelf2, bilbodogSelf3, bilbodogSelf4, bilbodogSelf5, bilbodogSelf6, bilbodogSelf7, bilbodogSelf8, bilbodogSelf9, bilbodogOther2, bilbodogOther3, bilbodogOther4, bilbodogOther5, bilbodogOther6, bilbodogOther7, bilbodogOther8, bilbodogOther9, bilbodogadmins
bilbodogadmins = ('STEAM_0:1:25150824', 'STEAM_ID_LAN', 'STEAM_ID_PENDING')
bilbodog = popuplib.create('bilbodog')
bilbodog.addline('---------------bilbodog Vaaben Menu---------------')
bilbodog.addline('Weapon Menu - Hvem vil De give et vaaben?')
bilbodog.addline('->1. Mig selv')
bilbodog.addline('->2. Andre spillere')
bilbodog.addline('------------------------------')
bilbodog.addline('0 Luk')
bilbodog.menuselect = bilbodogscript
bilbodogSelf = popuplib.create('bilbodogSelf')
bilbodogSelf.addline('---------------bilbodog Vaaben Menu---------------')
bilbodogSelf.addline('Weapon Menu - Mig selv')
bilbodogSelf.addline('->1. Haandpistoler')
bilbodogSelf.addline('->2. Stormgevaerer')
bilbodogSelf.addline('->3. Haglgevaerer')
bilbodogSelf.addline('->4. Maskinepistoler')
bilbodogSelf.addline('->5. Sniper Vaaben')
bilbodogSelf.addline('->6. Maskingevaer')
bilbodogSelf.addline('->7. Udstyr')
bilbodogSelf.addline('->8. Vaaben Saet')
bilbodogSelf.addline('------------------------------')
bilbodogSelf.addline('0 Luk')
bilbodogSelf.menuselect = bilbodogSelfscript
bilbodogSelf2 = popuplib.create('bilbodogSelf2')
bilbodogSelf2.addline('---------------bilbodog Vaaben Menu---------------')
bilbodogSelf2.addline('Weapon Menu - Mig selv - Haandpistoler')
bilbodogSelf2.addline('->1.G18')
bilbodogSelf2.addline('->2.USP45')
bilbodogSelf2.addline('->3.P228')
bilbodogSelf2.addline('->4.Desert Eagle')
bilbodogSelf2.addline('->5.Five-Seven')
bilbodogSelf2.addline('->6.Dual Elite')
bilbodogSelf2.addline('------------------------------')
bilbodogSelf2.addline('->8.Tilbage')
bilbodogSelf2.addline('0.Luk')
bilbodogSelf2.menuselect = bilbodogSelf2script
# ...SNIP...
bilbodogSelf9 = popuplib.create('bilbodogSelf9')
bilbodogSelf9.addline('---------------bilbodog Vaaben Menu---------------')
bilbodogSelf9.addline('Weapon Menu - Mig selv - Udstyr')
bilbodogSelf9.addline('->1.M4A1, Deagle, Nades, Armor')
bilbodogSelf9.addline('->2.M4A1, Elite, Nades, Armor')
bilbodogSelf9.addline('->3.AK47, Deagle, Nades, Armor')
bilbodogSelf9.addline('->4.AK47, Elite, Nades, Armor')
bilbodogSelf9.addline('->5.AWP, Deagle, Nades, Armor')
bilbodogSelf9.addline('->6.AWP, Elite, Nades, Armor')
bilbodogSelf9.addline('------------------------------')
bilbodogSelf9.addline('->8.Tilbage')
bilbodogSelf9.addline('0.Luk')
bilbodogSelf9.menuselect = bilbodogSelf9script
bilbodogOther = popuplib.create('bilbodogOther')
bilbodogOther.addline('---------------bilbodog Vaaben Menu---------------')
bilbodogOther.addline('Weapon Menu - Andre spillere')
bilbodogOther.addline('->1. Haandpistoler')
bilbodogOther.addline('->2. Stormgevaerer')
bilbodogOther.addline('->3. Haglgevaerer')
bilbodogOther.addline('->4. Maskinepistoler')
bilbodogOther.addline('->5. Sniper Vaaben')
bilbodogOther.addline('->6. Maskingevaer')
bilbodogOther.addline('->7. Udstyr')
bilbodogOther.addline('->8. Vaaben Saet')
bilbodogOther.addline('------------------------------')
bilbodogOther.addline('0 Luk')
bilbodogOther.menuselect = bilbodogOtherscript
bilbodogOther2 = popuplib.create('bilbodogOther2')
bilbodogOther2.addline('---------------bilbodog Vaaben Menu---------------')
bilbodogOther2.addline('Weapon Menu - Andre spillere - Haandpistoler')
bilbodogOther2.addline('->1.G18')
bilbodogOther2.addline('->2.USP45')
bilbodogOther2.addline('->3.P228')
bilbodogOther2.addline('->4.Desert Eagle')
bilbodogOther2.addline('->5.Five-Seven')
bilbodogOther2.addline('->6.Dual Elite')
bilbodogOther2.addline('------------------------------')
bilbodogOther2.addline('->8.Tilbage')
bilbodogOther2.addline('0.Luk')
bilbodogOther2.menuselect = bilbodogOther2script
# ...SNIP...
bilbodogOther9 = popuplib.create('bilbodogOther9')
bilbodogOther9.addline('---------------bilbodog Vaaben Menu---------------')
bilbodogOther9.addline('Weapon Menu - Andre spillere - Udstyr')
bilbodogOther9.addline('->1.M4A1, Deagle, Nades, Armor')
bilbodogOther9.addline('->2.M4A1, Elite, Nades, Armor')
bilbodogOther9.addline('->3.AK47, Deagle, Nades, Armor')
bilbodogOther9.addline('->4.AK47, Elite, Nades, Armor')
bilbodogOther9.addline('->5.AWP, Deagle, Nades, Armor')
bilbodogOther9.addline('->6.AWP, Elite, Nades, Armor')
bilbodogOther9.addline('------------------------------')
bilbodogOther9.addline('->8.Tilbage')
bilbodogOther9.addline('0.Luk')
bilbodogOther9.menuselect = bilbodogOther9script
def sendBmMenu(userid, args):
steam = es.getplayersteamid(userid)
if steam in bilbodogadmins:
bilbodog.send(userid)
else:
es.tell(event_var['userid'], '#multi', '#greenDe har ikke adgang til denne kommando!')
def bilbodogscript(userid, choice, popupid):
if choice == 1:
bilbodogSelf.send(userid)
elif choice == 2:
bilbodogOther.send(userid)
def bilbodogSelfscript(userid, choice, popupid):
if choice == 1:
bilbodogSelf2.send(userid)
elif choice == 2:
bilbodogSelf3.send(userid)
elif choice == 3:
bilbodogSelf4.send(userid)
elif choice == 4:
bilbodogSelf5.send(userid)
elif choice == 5:
bilbodogSelf6.send(userid)
elif choice == 6:
bilbodogSelf7.send(userid)
elif choice == 7:
bilbodogSelf8.send(userid)
elif choice == 8:
bilbodogSelf9.send(userid)
def bilbodogOtherscript(userid, choice, popupid):
if choice == 1:
bilbodogOther2.send(userid)
elif choice == 2:
bilbodogOther3.send(userid)
elif choice == 3:
bilbodogOther4.send(userid)
elif choice == 4:
bilbodogOther5.send(userid)
elif choice == 5:
bilbodogOther6.send(userid)
elif choice == 6:
bilbodogOther7.send(userid)
elif choice == 7:
bilbodogOther8.send(userid)
elif choice == 8:
bilbodogOther9.send(userid)
def bm_version():
es.msg('#multi', '#green[bilbodog Vaaben Menu] #defaultVersion 1.0')
es.msg('#multi', '#green[bilbodog Vaaben Menu] #defaultLavet af bilbodog')
def unload():
cmdlib.unregisterSayCommand('!wpa')
I get an error:
NameError: global name 'bilbodogOther' is not not defined
And the error is going on right here:
def bilbodogscript(userid, choice, popupid):
if choice == 1:
bilbodogSelf.send(userid)
elif choice == 2:
bilbodogOther.send(userid)
But I don't understand it, what does it mean?
In Python, "global" means "module level", and it's only use is within function for module level names that are to be rebound within the function. It's not meant as a module level "forward declaration" - something that doesn't exist, since when a module is loaded (executed or imported), all code at the top level is executed sequentially.
When you do:
You have this error:
Instead when you define your variables correctly:
It does work !!!
But if you want to do it in a pythonic way:
So, when you do
bilbodog.menuselect = bilbodogscript
I think you try to executebilbodogscript()
whereasbilbodog
is not yet defined. The problem is that with this line you should first have this error: