8874323 发表于 2009-1-8 22:13:37

公共服务器规则【直接发源码】

本帖最后由 8874323 于 2009-1-8 22:16 编辑

/*
PUBLIC SERVER RULES 1.20 ( 2005-08-18 )

Plugin by Priski

Usage :
Put rules in rules.txt file in cstrike folder
and set rules_speed and rules_interval whatever you like

Commands :
rules_show       - shows rules listed in rules.txt
rules_enable       - set this to 0 to disable automatic rules display
say /rules       - displays rules to normal user

CVARS :
rules_interval                - interval between automatic rules display
rules_admin_only        - disables say /rules command from regular users
rules_join                - if set 1 displays rules after player have joined server
rules_hudmessage_time        - time how long hudmessage is displayed
rules_join_timeout        - delay to show rules when joining to the server

Changelog :

1.20 / 2005-08-18
- removed client chat rules
- fixed major bugs

1.11 / 2005-08-15
- fixed some bugs

1.10 / 2005-08-14
- new CVARs : rules_hudmessage, rules_hudmessage_time
rules_join_timeout
- Rules in hudmessage mode also

1.03 / 2005-08-12
- rules_enable command fix.
- new CVAR "rules_join" set 1 to show rules
to players when they join server

1.02 / 2005-08-11
- optimized code
- rules_enable is now a command       
- default interval is now 10 minutes

1.01 / 2005-08-11
- added rules_admin_only & say /rules command
- variables are global now

1.0 / 2005-08-11
- first release

*/

#include <amxmodx>
#include <amxmisc>

new base[] = "rules.txt"

new i, num, text, hudmsg //max hudmessage length was 439 chars (?)

public plugin_init()
{
       
        register_plugin("AMXX Public server rules", "1.20", "Priski")
       
        // register command
       
        register_concmd("rules_show", "rules", ADMIN_KICK, "- show rules to everybody")
        register_concmd("rules_enable", "r_enable", ADMIN_KICK, "- <1|0> set automessagin on/off")
        register_cvar("rules_admin_only", "0")
        register_cvar("rules_join", "1")
        register_cvar("rules_join_timeout", "5")
        register_cvar("rules_hudmessage_time", "10")
        register_cvar("rules_interval", "600")
        register_clcmd("say /rules", "clientrules", ADMIN_ALL, "- show rules")
}

public plugin_cfg() {
       
        if (!file_exists(base)) {
                write_file(base, "; This is the public rules file, put your rules below")
                write_file(base, "; Remember, max amount of characters is 439")
                console_print(0, "%s file not found. creating new ...", base)
        }
       
}

public client_authorized ( id ) {
        // on join display rules
       
        if (get_cvar_num("rules_join")) {
                new tmp
                tmp = id
                set_task(1.0, "showrules",id,tmp,1)
                console_print(0, " client auth!", tmp)
        }
       
        return PLUGIN_HANDLED
}


public showrules (pid[]) {
        new id = pid
       
        if ( get_user_team(id) != 1 && get_user_team(id) != 2 ) {
                if (id) {
                        new tmp
                        tmp = id
                        set_task(2.0, "showrules",id,tmp,1)// not yet in server
                        console_print(0, " wait for joining team ...", id)
                }
                return PLUGIN_HANDLED
        }
       
        new tmp
        tmp = id
       
        console_print(0, " joined team : %d", id, get_user_team(id))
        console_print(0, " printing rules after %d seconds", id, get_cvar_num("rules_join_timeout"))
       
        set_task(get_cvar_float("rules_join_timeout"), "printrules", id, tmp, 1)// not yet in server
       
        return PLUGIN_HANDLED
}

public printrules(pid[])
{
        new id = pid
        if (file_exists(base))
                {
               
                console_print(0, " printing rules for user %d", id)
               
                set_hudmessage ( 200, 150, 0, 0.02, 0.25, 2, 0.1, get_cvar_float("rules_hudmessage_time"), 0.05, 1.0, 1)
                format(hudmsg, 439, "")
               
                // read all the rules
                for(i=0; read_file(base, i, text, 127, num); i++) {
                        if (num > 0 && text != ';') {
                                // display with predefined delay
                                add(hudmsg,439,text)
                                add(hudmsg,439,"^n")
                        }
                }
               
                // show hudmessages
                show_hudmessage(id, hudmsg)
               
        }
       
        return PLUGIN_HANDLED
}


public r_enable(id, level, cid)
{
        if (!cmd_access(id, level, cid, 0)) {// NOT ADMIN
                return PLUGIN_HANDLED
        }
       
        new arg
       
        read_argv(1, arg, 2)
        new value = str_to_num(arg)
       
        if (!isalnum(arg))
                value = -1
       
        if (value == 0) {
               
                if (task_exists(2)) // close task
                        remove_task(2)       
               
                console_print(id, "You have disabled automatic messages")
                return PLUGIN_HANDLED
               
        }
        if (value == 1) {
                // activate task, reload if already exist
                if (task_exists(2)) {
                        change_task(2, get_cvar_float("rules_interval"))
                        } else {
                        set_task(get_cvar_float("rules_interval"), "rules", 2, "", 0, "b")
                }       
                console_print(id, "You have enabled automatic messages")
                return PLUGIN_HANDLED               
        }
        if (task_exists(2)) {
                console_print(id, "automessages is ON.")
                } else {
                console_print(id, "automessages is OFF.")
        }
        console_print(id, "rules_enable <1|0> (1 = ON, 0 = OFF)")
        return PLUGIN_HANDLED               
       
}

public clientrules(id, level, cid) {
        new pID
        pID = id
       
        console_print(0,"Print rules for me only",pID)
        printrules(pID)
}

public rules(id, level, cid)
{
        new pID
        pID = id
                       
        if (!cmd_access(id, level, cid, 0)) {// NOT ADMIN
                return PLUGIN_HANDLED
        }
       
        // read file to all users
        pID = 0
        console_print(0,"Print rules for all",id)
        printrules(pID)
       
        // Reset scheduled task after display
        if (get_cvar_float("rules_interval") > 0) {
                if (task_exists(2)) {
                        change_task(2, get_cvar_float("rules_interval"))
                        } else {
                        set_task(get_cvar_float("rules_interval"), "rules", 200, "", 0, "b")
                }
        }
       
        return PLUGIN_HANDLED
}

8874323 发表于 2009-1-8 22:21:30

不会E文的我说下(玩E文也不太好、希望纠正错误)
用法:
rules.txt规则文件中cstrike文件夹
并设置
rules_show -显示规则中列出rules.txt
rules_enable - set this to 0 to disable automatic rules display rules_enable -设置为0禁用自动显示规则
rules_join -如果设置1显示规则在玩家加入时显示
rules_hudmessage_time -时间显示长度
rules_join_timeout -一直显示

Hoyc 发表于 2009-1-9 18:55:41

只是楼主,希望楼主能够发更多源码。

filly 发表于 2009-1-11 12:07:03

谢谢楼主了,虽然我还不用

ccoie 发表于 2009-1-12 05:10:02

呵呵,看不懂

kevin741 发表于 2009-1-12 09:45:43

希望版主會發更多插件的源碼吧!!

riee 发表于 2009-1-15 21:36:24

我也看不懂。。

filly 发表于 2009-1-15 22:26:44

顶顶枯。。

a246022 发表于 2009-1-15 22:57:17

thank you!

Desmond 发表于 2009-1-23 09:25:54

這個好,我找了這個sma很久了
页: [1] 2 3
查看完整版本: 公共服务器规则【直接发源码】