Addon Details

Watch - Add Favorite


Does this version work for you?
5
w00ts
w00t!2

mani - Version 0.1.1

posted on 2009-03-10 12:39:05
by pitbull0993


Tags: css library

Description

[size=18][color=red][b]MANILIB IS CURRENTLY ALPHA STATUS! IT'S ALMOST UNTESTED! I NEED YOUR FEEDBACK![/b][/color][/size] The idea with the manilib came up when I read a post like this in the Mattie Forums: [quote]How do I get only the admins that have the ability to slay?[/quote] Or as I wanted to code a respawn-script, but only a specific group of admins should be allowed to respawn. And there are a lot more people out there, who want to be able to use the Mani-Admin-Plugin, and get full access to the clients (flags, groups and so on). All of these facts, and a lot more, made me coding the manilib. [b]1. Full Client access[/b] Almost everybody knows the client-handling of Mani. It's very extensive and has a lot of possibilities like the flagging option, group feature and much more. With manlib, you now can access (read and write) the whole clients.txt through EventScripts. [b]2. Checking for flags[/b] Ever wanted to check if the user who joined is an admin for sending a message to other players? I think some of you did. Your solution would have looked like this (Mani clients.txt reader by XE_ManUp): [syntax="python"]import es clientsPath = str(es.ServerVar('eventscripts_gamedir')) + '/cfg/mani_admin_plugin/clients.txt' list_admins = [] def load(): getAdmins() def player_activate(event_var): if event_var['es_steamid'] not in list_admins: return es.msg('#multi', 'Admin #green%s#default has joined the game.' % event_var['es_username']) def getAdmins(): # Read the clients.txt and append steamids to the list clientsFile = open(clientsPath, 'r') for line in clientsFile: list_line = line.split('"') if len(list_line) > 3: if list_line[3].startswith('STEAM_'): list_admins.append(list_line[3]) clientsFile.flush() clientsFile.close()[/syntax] That would be a well working script. But what if you wanted to disable the message for users who maybe are only members and don't have the RCON menu level 1 flag (q)? You would need to check if the user has the flag, and then send the message. But how to do? Very simple: [syntax="python"]import es import manilb as ma def player_activate(event_var): if not ma.getClient(event_var['es_steamid']).hasAFlag('q'): return es.msg('#multi', 'Admin #green%s#default has joined the game.' % event_var['es_username'])[/syntax] Now, how is this working? Firstly, we check if the player who activated is an admin. Secondly, we want to know if he got the admin flag [i]q[/i]. If yes, we send the message. Otherwise not. [b]3. Checking for groups[/b] This thing can also be done by adding all clients to a group called "joinMessage". This would not need a Mani-specific flag. For this, we would replace [i]hasAFlag('q')[/i] by [i]inAGroup('joinMessage')[/i]: [syntax="python"]import es import manilib as ma def player_activate(event_var): if not ma.getClient(event_var['es_steamid']).inAGroup('joinMessage'): return es.msg('#multi', 'Admin #green%s#default has joined the game.' % event_var['es_username'])[/syntax] [b]4. Checking for custom flags[/b] A more specific method would be using a custom flag. The custom flag feature allows you to set a flag (like an admin flag of Mani) to a client. The differences between admin and custom flags are, that you can choose a name you want and that this flag is not used by Mani itself in any way. Lets stay at our example with the join message. You neither want to use the Mani-flag nor a group, so you decide to use a custom flag: [syntax="python"]import es import manlib as ma def player_activate(event_var): if not ma.getClient(event_var['es_steamid']).hasCFlag('joinMessage'): return es.msg('#multi', 'Admin #green%s#default has joined the game.' % event_var['es_username'])[/syntax] The script is just slightly different to the one of point 2: we use [i]hasCFlag[/i] instead of [i]hasAFlag[/i]. Now, this script will check if we have the joinMessage-flag. But how does the client get it? [b]5. Adding custom flags[/b] Adding a custom flag is a very easy thing. All you need is either rcon-access or the "Set clients flags"-flag by Mani. If you got the rcon-access, you would need to type the following into the console: [code]ma_addCFlag <id> <flagname>[/code] If you have the "Set clients flags"-flag, you need to type the following in chat: [code]!ma_addCFlag <id> <flagname>[/code] The first argument (id) could either be the user-id, the Steam-ID, or the Mani Unique-ID. Whatever you choose, all will work. The second argument (flagname) has to be the name of the custom flag. You can type anything you like, but there must be no spaces! Now you would be ready to write your first script, but there is a next feature you should now about. [b]6. Custom Addons[/b] Some of you maybe know the custom-addon management of GunGame5. I really liked this from the first moment on, so I had to add this to manilib too. First of all, it's not so extensive like the one of the GunGame-team, but it has some little helpers. Now, what can you actually do with help of custom-addon management? First step is registering the custom addon with the manilib: [syntax="python"]import es import manilib as ma def load(): ma_testscript = ma.registerCustomAddon("ma_testscript")[/syntax] In the second step, you set a display title. [syntax="python"] ma_testscript.setDisplayTitle("Test-Script")[/syntax] If you have done this, we can get to the first little helper: msg. [b]7. ma.msg[/b] With ma.msg, you automatically add the display-title to the message, and if you want to, also the main-prefix "MANI". [syntax="python"]def player_activate(event_var): if not ma.getClient(event_var['es_steamid']): return ma.msg("ma_testscript", "Admin %s has joined the game." % event_var['es_username'])[/syntax] This line would output the following: [code][MANI - Test-Script] Admin PitBull has joined the game.[/code] If you now wanted to hide the main-prefix ("MANI"), the line would look like this: [syntax="python"] ma.msg("ma_testscript", "Admin %s has joined the game." % event_var['es_username'], 0)[/syntax] If you want to hide the display title ("Test-Script") only, the line would look like this: [syntax="python"] ma.msg("ma_testscript", "Admin %s has joined the game." % event_var['es_username'], 1, 0)[/syntax] If you want to hide the mani-prefix ("MANI") and the display title ("Test-Script"), the line would look like this: [syntax="python"] ma.msg("ma_testscript", "Admin %s has joined the game." % event_var['es_username'], 0, 0)[/syntax] The syntax of ma.msg is the following: [syntax="python"]ma.msg("<addonname>", "<msg>", <0/1 mainprefix>, <0/1 addonprefix>)[/syntax] As default, main- and addonprefix are 1. Another helper is: tell. [b]8. ma.tell[/b] ma.tell is working like ma.msg, with the difference that you send it to a single user (like es.tell). So you need a userid. [syntax="python"]ma.tell(<userid>, "<addonname>", "<msg>", <0/1 mainprefix>, <0/1 addonprefix>)[/syntax] [b]9. Mani commands[/b] Every Mani command (version 1.2R) is included into the manilib. Every command which can't be run by the server (like ma_rates), will raise an error. Example of how to use a command like slay: [syntax="python"]import es import manilib as ma def player_spawn(event_var): ma.getPlayer(event_var['userid']).slay()[/syntax] This script would slay a player when he spawns. Another example: [syntax="python"]import es import manilib as ma tk = {} def player_death(event_var): if not es.exists('userid', event_var['userid']): return if not event_var['es_attackerteam'] == event_var['es_userteam']: return if not tk.has_key(event_var['userid']): tk[event_var['userid'] = 0 tk[event_var['userid'] += 1 if tk[event_var['userid']] >= 5: ma.getPlayer(event_var['userid']).ban(60)[/syntax] This script bans a player for 60 minutes if he got 5 teamkills (based on userid, not a good method at all because the id changes on retry). You can get a full list of commands by downloading the Mani Library Reference which is attached to this post. [b]10. Example custom addons[/b] In this package are already 3 example addons included: [b]ma_adminjoinmsg[/b], [b]ma_resetrank[/b] and [b]ma_respawn[/b] (which needs ES_Tools/GG-Utils/es_respawn or others).

Installation

1. Unpack it 2. Upload to your server 3. Add [i]es_load mani[/i] to your autoexec.cfg 4. (optional) Add [i]es_load ma_adminjoinmsg[/i] to your autoexec.cfg 5. (optional) Add [i]es_load ma_respawn[/i] to your autoexec.cfg 6. (optional) Add [i]es_load ma_resetrank[/i] to your autoexec.cfg

Version Notes For 0.1.1

Updated on: 2009-03-10 14:34:25 EST by pitbull0993 (View Zip Contents)
+Added publicvar

( Previous Versions )

Request a new feature