CmdManager and say commands

Please post any questions about developing your plugin here. Please use the search function before posting!
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

CmdManager and say commands

Postby arawra » Fri Aug 30, 2013 8:22 pm

Code: Select all

Caught an Exception:

TypeError: stats() takes 2 positional arguments but 3 were given


Code: Select all

from command_c import get_say_command



def load():
    global cmdmanager
   
    cmdmanager = get_say_command('!stats')
    cmdmanager.add_callback(stats)


def stats(player, CICommand):
    global player_database
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Aug 30, 2013 9:26 pm

Say command callbacks have 3 arguments:

http://www.sourcepython.com/showwiki.php?title=Wiki:commands+say

Satoon
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Postby arawra » Sat Aug 31, 2013 2:12 am

Code: Select all

@SayCommand(['!stats', '!stat'])
def sayStats(playerinfo, teamonly, ccommand):
    # some stuff for getting strings etc.
    tell(playerinfo, 'String %s %s %s'%(string1, string2, string3))

def tell(player, msg=[]):
    msg = '\x04[D&D] \x01%s'%msg
    i = index_from_playerinfo(player)
    m = messages.SayText2(index=i, chat=1, message=msg)
    m.send(i)


From _libs\players\helpers.py Line 47

Code: Select all

    return playerinfo.get_edict()

RuntimeError: Access violation - no RITI data!
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Sat Aug 31, 2013 7:45 pm

This an odd error I've been getting too. Try replaceing
index_from_playerinfo
with
player.get_edict().get_index()
Libraries: k2tools
Plugins (any): GSRPG (soon) | Pretty Status List | MySQLAds (soon)
Plugins (game-specific): None atm

If you happen to find a bug or need help, either post in the release threads or contact me in IRC gamesurge.net:6667 / #sourcepython
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Sep 01, 2013 1:26 am

That is very odd... That is exactly what index_from_playerinfo does. I will look into this issue when I have the time.

Satoon
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Sep 01, 2013 10:53 am

I cannot seem to reproduce this. Does this error always occur or just sometimes? Is the server Linux or Windows?

Satoon
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Postby arawra » Sun Sep 01, 2013 10:55 pm

I'll try firing up the server again. This is on Windows 7.

A note, I did not register the previous command. I'll do that and see if thats what is causing the issue.
E: Looks like you dont need to register when using @SayCommand
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Sep 01, 2013 11:42 pm

Using the decorator class SayCommand automatically registers the command for you. In fact, all of the decorator classes in Source.Python automatically register and unregister the function that follows to the specific functionality. That is exactly what they are designed to do.

Satoon
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Mon Sep 02, 2013 1:37 am

satoon101 wrote:I cannot seem to reproduce this. Does this error always occur or just sometimes? Is the server Linux or Windows?

Satoon


It's random. Though it might be more likely to happen if you pass it to other functions a bunch of timesm.

I read on the web it has something with variable going out of scope in python (getting garbage collected), and as such the C side then has some problems with accessing it.
Libraries: k2tools

Plugins (any): GSRPG (soon) | Pretty Status List | MySQLAds (soon)

Plugins (game-specific): None atm



If you happen to find a bug or need help, either post in the release threads or contact me in IRC gamesurge.net:6667 / #sourcepython

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 12 guests