Page 1 of 1

[ANY] Advertisement plugins

Posted: Sat May 27, 2017 5:08 pm
by existenz
Heya !

I have made a simple Advertisement plugin, normally working for any games. But i have tested only on Csgo.



Advert interval
Time in minutes between adverts. (Must be an integer)

Advert order
Define the appearance order of advert.
0 - Follow order of advert in json file.
1 - Get random advert.

Example :

Code: Select all

{
  "Adverts": [
    {
      "type": "say",
      "message": "Welcome on {hostname} !",
      "translation": "say:1"
    },
    {
      "type": "say",
      "message": "The current map is {currentmap}",
      "translation": "say:2"
    },
    {
      "type": "hint",
      "message": "Kill them all ! [Friendlyfire : {mp_friendlyfire}]",
      "translation": "hint:1"
    },
    {
      "type": "hud",
      "message": "The time is {time}",
      "translation": "hud:1"
    }
  ]
}


The translation attribute must contains the key of advert translation and must refer to a key in 'advertissement_server.ini'. If "translation" attribute is defined you are not oblige to write something in "message" key.

Code: Select all

{
  "Adverts": [
    {
      "type": "say",
      "message": "",
      "translation": "say:1"
    }
  ]
}



In the message of advert you can also add color. Use the default color available in your game for example in Csgo if i want green i can add \x04.

Define template variables :

- {currentmap} : Show current map name
- {date} : Show current date
- {time} : Show current time


Other variables :
You can also show all cvar of your server, like mp_friendlyfire, mp_roundtime ...

Sincerly Existenz.

Ps : Thanks to Satoon for his advert system (viewtopic.php?f=37&p=10430#p10426)

Re: [ANY] Advertisement plugins

Posted: Sat May 27, 2017 10:01 pm
by Kill
Can You make the interval compatible with seconds? Thanks!


Edit:

I tried to color the message, but it fails to load

Syntax: Select all

#Error: ValueError: Json file incorrect.
# Msgs:
{
"Adverts": [
{
"type": "say",
"message": "Welcome on our server !"
},
{
"type": "say",
"message": "\x02The current map is \x03{currentmap}"
},
{
"type": "hint",
"message": "Kill them all ! [Friendlyfire : {mp_friendlyfire}]"
},
{
"type": "hud",
"message": "\x02The time is \x03{time}"
}
]
}



Game: CSS

Re: [ANY] Advertisement plugins

Posted: Sat May 27, 2017 10:10 pm
by iPlayer
Kill, try replacing all \x with \\x

Re: [ANY] Advertisement plugins

Posted: Sat May 27, 2017 10:20 pm
by Kill
iPlayer wrote:Kill, try replacing all \x with \\x



Tried that, doesn't work, they show as plain-text

Re: [ANY] Advertisement plugins

Posted: Sat May 27, 2017 10:31 pm
by iPlayer
How about this

Syntax: Select all

{
"Adverts": [
{
"type": "say",
"message": "Welcome on our server !"
},
{
"type": "say",
"message": "\u0002The current map is\u0001 \u0003{currentmap}\u0001"
},
{
"type": "hint",
"message": "Kill them all ! [Friendlyfire : {mp_friendlyfire}]"
},
{
"type": "hud",
"message": "\u0002The time is\u0001 \u0003{time}\u0001"
}
]
}

Re: [ANY] Advertisement plugins

Posted: Sat May 27, 2017 10:44 pm
by Kill
It works now, thanks!

Re: [ANY] Advertisement plugins

Posted: Sat May 27, 2017 10:49 pm
by iPlayer
Existenz,

I think that the message field should define the translation key. That'd allow the server owners to support multiple languages and define the actual strings in resource/source-python/translations/advertisement.server.ini

Re: [ANY] Advertisement plugins

Posted: Sat May 27, 2017 11:06 pm
by satoon101
To add to that suggestion, maybe to help denote say vs hint (vs whatever else you might want to support), the strings in the advertisement_server.ini could utilize prefixes:

Syntax: Select all

[chat:1]
en = "Advert 1."

[chat:2]
en = "Advert 2."

[hint:1]
en = "Advert 3."

And maybe, instead of including the advertisement.ini itself, you could create it if it doesn't exist. So, something like the following:

Syntax: Select all

from configobj import ConfigObj

from paths import TRANSLATION_PATH

from .info import info

TRANSLATION_FILE = TRANSLATION_PATH / info.name + '.ini'


def _create_translation_file():
ini = ConfigObj(TRANSLATION_FILE)
ini['chat:1'] = {'en': 'Advert 1.'}
ini['chat:2'] = {'en': 'Advert 2.'}
ini['hint:1'] = {'en': 'Advert 3.'}

# The following creates a one line separation between items
for item in ini.items():
ini.comments[item] = ['']

ini.write()

if not TRANSLATION_FILE.isfile():
_create_translation_file()

Re: [ANY] Advertisement plugins

Posted: Sun May 28, 2017 8:21 am
by existenz
Heya ! Thanks for your answer.

@Kill : Yes i will modify minute to second.

@iPlayer : I think also it could be better to be multilingual.

@Satoon : I must have the advertisement.ini because i have one translation for my plugin (https://github.com/VenomzGaming/Sp-Adve ... ent.ini#L1).
But i will try something :)

Re: [ANY] Advertisement plugins

Posted: Sun May 28, 2017 12:06 pm
by existenz
Plugin reworked !

- Modify time to seconds
- Add translation system support