Page 1 of 2
plugin conversion
Posted: Wed Oct 28, 2015 7:51 am
by Jerome69
Posted: Thu Oct 29, 2015 1:38 pm
by Jerome69
Posted: Thu Oct 29, 2015 2:08 pm
by Ayuto
I actually wanted to reply yesterday, but forgot to do so. I will help you when I get home today (~2 hours).
A small hint: You have to use the SimpleOption class to create selectable and highlighted options.
Posted: Thu Oct 29, 2015 5:35 pm
by Ayuto
Posted: Fri Oct 30, 2015 9:24 pm
by Jerome69
Ok thanks it works fine
Now, I added a PagedMenu for listing maps :
The attachment Menu.jpg is no longer available
How I can add a title (1)?
Is it possible to change the "10. Close" in "0. Close" (2)?
I would like to execute many actions like adding bots, changing maps, loading cfg files, ...
Before (with eventscript), I used this command (for changing map) : es.server.cmd("changelevel " + map.replace('.bsp',''))
How can I do with SP?
Thanks
Posted: Sat Oct 31, 2015 8:42 am
by Ayuto
The PagedMenu class has a "title" attribute, which you can also set in the constructor.
Syntax: Select all
from menus import PagedOption
from menus import PagedMenu
from events import Event
from engines.server import engine_server
def select_callback(menu, player_index, option):
engine_server.server_command('changelevel {};'.format(option.value))
maps_menu = PagedMenu(title='My menu', select_callback=select_callback)
# PagedOption(<display text>, <value>)
# In this case the display text and the value are the same. So, you could
# actually just use option.text in your select callback. However, it does
# make sense to use the value attribute. Maybe you want to change the display
# text some day.
maps_menu.append(PagedOption('de_dust2', 'de_dust2'))
maps_menu.append(PagedOption('cs_office', 'cs_office'))
The close button was not intended to be labeled with a "10". I will fix this.
Edit: Fixed!
https://github.com/Source-Python-Dev-Team/Source.Python/commit/73b4f0ec852822a4c8a8ecd330b163ded0e1189eA new download is available (or you just apply the fix manually).
Posted: Sat Oct 31, 2015 10:28 am
by Jerome69
Hello,
I added a title to the menu, I can change maps, add, kill and kick bots
Now, I would like to be able, thanks to the menu, to lock and unlock weapons and smoke with a cfg file.
For smokes only, this is my file (VerrouSmoke.cfg) :
sp load sprestrict //If sprestrict is not loaded
sprestrict @all weapon_smokegrenade
In GLOBAL VARIABLES I have this line :
VerrouSmoke = PLUGIN_PATH.joinpath('VerrouSmoke.cfg')
And I lunch it with :
engine_server.server_command(VerrouSmoke)
But it didn't work. Do you know why?
Thanks
[EDIT] When anyone say "!menu", the text appears in th chat. Is it possible to block it?
Posted: Sat Oct 31, 2015 10:51 am
by Ayuto
engine_server.server_command(<command>) only executes a server command and not a config file. But there is a server command to execute a config file, so you could just use this to execute it:
Syntax: Select all
engine_server.server_command('exec my_config_file.cfg;')
AFAIK, this can only execute a config file within the cfg directory. And that's actually good, because that's where config files belong to.
To block the !menu command you have to register a say command.
Syntax: Select all
from commands.say import SayCommand
@SayCommand('!menu')
def open_menu(command, player_index, teamonly):
pass
Posted: Sat Oct 31, 2015 12:50 pm
by Jerome69
Posted: Sat Oct 31, 2015 1:36 pm
by Ayuto
Posted: Sat Oct 31, 2015 2:23 pm
by satoon101
Not at home to test, but I think you don't want to use the .cfg in your exec line. So, try your first one again, but remove the extension. Also, what all is even in that config file? If it is just 1 line, you can just execute that line instead of the config file.
Posted: Sat Oct 31, 2015 2:35 pm
by Jerome69
Sorry, my fault. You also have to return CommandReturn.BLOCK to avoid the chat message.
Syntax: Select all
from commands import CommandReturn
from commands.say import SayCommand
@SayCommand('!menu')
def open_menu(command, player_index, teamonly):
return CommandReturn.BLOCK
When I use this, it blocks the "command" and the menu doesn't appears. I just want to block "IVG : !menu" in the chat. Is it possible? It's not very important, just a finition for me
Ayuto wrote:Where did you save your config file? I see that your are using PLUGIN_PATH, which is the path to the plugins directory (../addons/source-python/plugins). This not correct. To execute a config file it must be saved in the cfg directory and I think the path must be relative and not absolute.
But I'm wondering what you are trying to do. If you want to create and execute config files I suggest you to take a look at the config package. Here are a few examples.
http://wiki.sourcepython.com/pages/Examples:config
My config files are in my plugin "NewMenu.py" directory.
Posted: Sat Oct 31, 2015 2:39 pm
by satoon101
The server cannot execute config files outside the ../cfg/ directory. Please move them into there. But again, what all is in them and is it necessary to have a cfg file or will just executing the commands directly suffice?
Posted: Sat Oct 31, 2015 2:41 pm
by Jerome69
satoon101 wrote:The server cannot execute config files outside the ../cfg/ directory. Please move them into there. But again, what all is in them and is it necessary to have a cfg file or will just executing the commands directly suffice?
I have two lines in this file :
sp load sprestrict
@all weapon_smokegrenade
It works now. The plugin is loaded. But the second line is not understanded by SP : unknown command : @all
But in others files, I have 4 lines, or more...
Here there is the plugin I'm using for the weapon restriction and the differents files I used with an old plugin (which was working with eventscript). I would like to use the same.
Posted: Sat Oct 31, 2015 2:50 pm
by satoon101
ES has a command called mexec. What it does if the file is outside of the ../cfg/ directory, it copies it to the ../cfg/ directory as a temp file, executes it, and removes the temp file. Here at Source.Python, we believe everything has a proper place. For config files, that's the ../cfg/ directory. If these cfg files are truly necessary for your plugin, I suggest you create a new directory inside ../cfg/source-python/ with the name of your plugin to house these files.
Posted: Sat Oct 31, 2015 2:55 pm
by satoon101
Jerome69 wrote:satoon101 wrote:The server cannot execute config files outside the ../cfg/ directory. Please move them into there. But again, what all is in them and is it necessary to have a cfg file or will just executing the commands directly suffice?
I have two lines in this file :
sp load sprestrict
@all weapon_smokegrenadeIt works now. The plugin is loaded. But the second line is not understanded by SP : unknown command : @all
But in others files, I have 4 lines, or more...
Here there is the plugin I'm using for the weapon restriction and the differents files I used with an old plugin (which was working with eventscript). I would like to use the same.
It seems to me that you are missing the command before @all.
Posted: Sat Oct 31, 2015 3:10 pm
by Ayuto
satoon101 wrote:It seems to me that you are missing the command before @all.
The plugin he linked reads the restricted weapons from a restriction.txt.
Jerome69 wrote:When I use this, it blocks the "command" and the menu doesn't appears. I just want to block "IVG : !menu" in the chat. Is it possible? It's not very important, just a finition for me
Put your code in the SayCommand callback instead of the player_say event.
Posted: Mon Nov 02, 2015 5:06 pm
by Jerome69
Ok. When I put the code in the SayCommand callback, it works fine.
But I have a little problem : I added an admin list in a dictionary.
I know how to collect a steamid when I'm in an Event, but not in this case. How can I do please?
Thanks
Posted: Mon Nov 02, 2015 5:20 pm
by Ayuto
Syntax: Select all
@SayCommand('!menu')
def open_menu(command, index, teamonly):
player = PlayerEntity(index)
print('Steamid', player.steamid)
return CommandReturn.BLOCK
I should also mention that we have a permission system that can be used with command decorators. Though, it's planned to be rewritten to be much simpler.
Posted: Mon Nov 02, 2015 5:32 pm
by Jerome69
Yes it works

Thanks