plugin conversion

Please post any questions about developing your plugin here. Please use the search function before posting!
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

plugin conversion

Postby Jerome69 » Wed Oct 28, 2015 7:51 am

Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Thu Oct 29, 2015 1:38 pm

User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Oct 29, 2015 2:08 pm

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.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Oct 29, 2015 5:35 pm

Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Fri Oct 30, 2015 9:24 pm

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
Attachments
Menu.jpg
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Oct 31, 2015 8:42 am

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/73b4f0ec852822a4c8a8ecd330b163ded0e1189e

A new download is available (or you just apply the fix manually).
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sat Oct 31, 2015 10:28 am

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?
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Oct 31, 2015 10:51 am

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
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sat Oct 31, 2015 12:50 pm

User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Oct 31, 2015 1:36 pm

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

Postby satoon101 » Sat Oct 31, 2015 2:23 pm

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.
Image
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sat Oct 31, 2015 2:35 pm

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 :smile:


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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Oct 31, 2015 2:39 pm

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?
Image
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Sat Oct 31, 2015 2:41 pm

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Oct 31, 2015 2:50 pm

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.
Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sat Oct 31, 2015 2:55 pm

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_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.


It seems to me that you are missing the command before @all.
Image
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Oct 31, 2015 3:10 pm

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.
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Mon Nov 02, 2015 5:06 pm

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
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Mon Nov 02, 2015 5:20 pm

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.
Jerome69
Member
Posts: 82
Joined: Wed Sep 23, 2015 3:20 pm

Postby Jerome69 » Mon Nov 02, 2015 5:32 pm

Yes it works :) Thanks

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 119 guests