Question regarding commands

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Question regarding commands

Postby decompile » Fri Jan 22, 2016 3:00 pm

Hey,

I need your help since im not getting what I want.

I tried to add a !info <mapname> command, when its just !info it uses currentMap

Syntax: Select all

@SayCommand("!info")
@ClientCommand("sm_info")
def printInfoStats(command, index, team=None):
userid = userid_from_index(index)
if command.get_arg_count(): #0 if just !info
mapName = command.get_arg_string(0).lower()
if not validMap(mapName):
return tell(player.userid, "map_not_found", {"mapName": mapName})
else:
mapName = global_vars.map_name
#insert code xxx


Would this work? It seems the arg_count removes the !info command, but how can you actually get the first argument or the 2nd one etc.
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Postby iPlayer » Fri Jan 22, 2016 3:07 pm

command.get_arg(0) ?
command[0] ?
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Jan 22, 2016 3:25 pm

Do you want the command or the 1st argument? The command is at index 0, the first argument is at index 1. I would probably use something like this:

Syntax: Select all

@SayCommand('!info')
def map_info(command, index, team_only):
if command.get_arg_count():
map_name = command[1]
else:
map_name = global_vars.map_name
Image
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Postby decompile » Fri Jan 22, 2016 3:41 pm

Realy weird

decompile : !info surf_the_gloaming
Print MapName: q@.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Jan 25, 2016 3:30 pm

That seems really strange. I am not encountering that at all, and it works fine for my testing. The only issue I noticed when testing is that I forgot that the command is included in the count of command.get_arg_count(), so we need to check if there is more than 1:

Syntax: Select all

@SayCommand('!info')
def map_info(command, index, team_only):
if command.get_arg_count() > 1:
map_name = command[1]
else:
map_name = global_vars.map_name

print('MapName:', map_name)
Image
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Mon Jan 25, 2016 4:06 pm

I talked to him about this issue via steam. He was passing the Command object to a thread. So, when the thread was using the object, the internal pointer was probably already deallocated, which resulted in reading invalid memory blocks. As a workaround I suggested to pass tuple(command) to the thread. This will create a tuple containing all arguments of the Command object.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 146 guests