搜索
查看: 1979|回复: 6

哪位看得懂代码的,看一下这个插件的SMA

[复制链接]
发表于 2006-7-30 12:31:10 | 显示全部楼层 |阅读模式 来自 中国–福建–福州
这个是服务器人满插件,刚好我需要从浩方房间转IP到公网的服务器,浩方那边可以显示人满,但不知能不能修改下面的参数来修改显示的人数上限。(上限是32人,因为插件是虚拟人数的,所以想调到76人,这样也好看一点,不知哪们兄弟会修改)

#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta_stocks>
#include <fun>

new const Plugin[] = "FakeFull Original"
new const Version[] = "1.7.4"
new const Author[] = "JTP10181/Freecode/AssKicR"

#define MAX_NAMES 256

new bool:is_user_ffbot[33]
new bool:checkingStatus = false
new bool:changingBots = false
new botCount = 0, namesread = 0
new namesToUse[MAX_NAMES][33]

public plugin_init()
{
        register_plugin(Plugin,Version,Author)
        register_cvar("ff_automode","0")
        register_cvar("ff_players","2")
        register_cvar("ff_delay","1")
        register_concmd("amx_addfake","botadd",ADMIN_BAN,"<# | @FILL> - add this many bots")
        register_concmd("amx_removefake","botremove",ADMIN_BAN,"<# | @ALL> - remove this many bots")
        set_task(10.0,"ServerStatus",0,_,_,"b")
        ReadNames()

        //Setup jtp10181 CVAR
        new cvarString[256], shortName[16]
        copy(shortName,15,"ff")

        register_cvar("jtp10181","",FCVAR_SERVER|FCVAR_SPONLY)
        get_cvar_string("jtp10181",cvarString,255)

        if (strlen(cvarString) == 0) {
                formatex(cvarString,255,shortName)
                set_cvar_string("jtp10181",cvarString)
        }
        else if (contain(cvarString,shortName) == -1) {
                format(cvarString,255,"%s,%s",cvarString, shortName)
                set_cvar_string("jtp10181",cvarString)
        }
}

public botadd(id,level,cid)
{
        if (!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED

        new arg[10], botNum

        if (read_argc() == 1) botNum = 1
        else {
                read_argv(1,arg,9)
                if (equali(arg,"@FILL")) botNum = get_maxplayers() - get_playersnum(1)
                else botNum = str_to_num(arg)
        }

        if (botNum <=0 || botNum > get_maxplayers() - get_playersnum(1)) {
                console_print(id,"[AMXX] Invalid number of bots to add")
                return PLUGIN_HANDLED
        }

        new Float:botDelay = get_cvar_float("ff_delay")
        console_print(id,"[AMXX] Adding %d bots with %.1f second delay for each",botNum,botDelay)
        set_task(botDelay,"createBot",0,_,_,"a",botNum)
        set_task(botDelay * (botNum + 1),"doneChanging")
        changingBots = true

        return PLUGIN_HANDLED
}

public botremove(id,level,cid)
{
        if (!cmd_access(id,level,cid,1)) return PLUGIN_HANDLED

        new arg[10], botNum

        if (read_argc() == 1) botNum = 1
        else {
                read_argv(1,arg,9)
                if (equali(arg,"@ALL")) botNum = botCount
                else botNum = str_to_num(arg)
        }

        if (botNum <=0 || botNum > botCount) {
                console_print(id,"[AMXX] Invalid number of bots to remove")
                return PLUGIN_HANDLED
        }

        new Float:botDelay = get_cvar_float("ff_delay")
        console_print(id,"[AMXX] Removing %d bots with %.1f second delay for each",botNum,botDelay)
        set_task(botDelay,"removeBot",0,_,_,"a",botNum)
        set_task(botDelay * (botNum + 1),"doneChanging")
        changingBots = true

        return PLUGIN_HANDLED
}

public client_putinserver(id)
{
        is_user_ffbot[id] = false
        ServerStatus()
}

public client_disconnect(id)
{
        is_user_ffbot[id] = false
        ServerStatus()
}

public createBot()
{
        new bool:UseAnotherName
        new BotName[33], UserNames[33][33]
        new name_rand = random_num(0,namesread - 1)
        new endLoop = name_rand - 1
        if (endLoop < 0) endLoop = namesread - 1

        //Save all the usernames so we dont have to keep getting them all
        for (new x = 1; x <= 32; x++) {
                if (!is_user_connected(x)) continue
                get_user_name(x,UserNames[x],32)
        }

        do {
                UseAnotherName = false
                copy(BotName,32,namesToUse[name_rand])

                for (new id = 1; id <= 32; id++) {

                        if (!is_user_connected(id)) continue

                        if (equali(BotName,UserNames[id])) {
                                UseAnotherName = true

                                if (name_rand == endLoop) {
                                        UseAnotherName = false
                                        log_amx("ERROR: Ran out of names to use, please add more to botnames.ini")
                                }

                                name_rand++
                                if (name_rand > namesread - 1) {
                                        name_rand = 0
                                }
                                break
                        }
                }
        } while(UseAnotherName)

        new Bot = EF_CreateFakeClient(BotName)

        if (Bot > 0) {
                DF_MetaFunc_CallGameEntity("player", Bot)
                entity_set_int(Bot, EV_INT_flags, FL_FAKECLIENT)
                is_user_ffbot[Bot] = true
                botCount++
        }
}

public removeBot()
{
        for(new id = 1; id <= 32; id++) {
                if (is_user_ffbot[id]) {
                        server_cmd("kick #%d",get_user_userid(id))
                        botCount--
                        return
                }
        }
}

public doneChanging()
{
        changingBots = false
}

public ServerStatus()
{
        if ( !get_cvar_num("ff_automode") ) return
        if ( checkingStatus || changingBots ) return

        checkingStatus = true

        if (botCount > 0) {
                for (new id = 1; id <= 32; id++) {

                        if (!is_user_connected(id)) continue
                        if (!is_user_ffbot[id]) continue
                        new rnd = random_num(1,100)
                        if (rnd <= 10) {
                                set_user_frags(id,get_user_frags(id) + 1)
                        }

                        if (get_user_team(id) > 0) {
                                server_cmd("kick #%d",get_user_userid(id))
                                botCount--
                        }
                }
        }

        new pnum = get_playersnum(1)
        new maxplayers = get_maxplayers()
        new ff_players = get_cvar_num("ff_players")
        new Float:botDelay = get_cvar_float("ff_delay")

        if (ff_players > maxplayers - 2) {
                ff_players = maxplayers - 2
                set_cvar_num("ff_players",ff_players)
        }

        if (botDelay <= 0.0 ) {
                log_amx("ERROR: Please set ff_delay to a number higher than 0")
        }

        else if (ff_players > pnum) {
                new addnum = ff_players - pnum
                set_task(botDelay,"createBot",0,_,_,"a",addnum)
                set_task(botDelay * (addnum + 1),"doneChanging")
                changingBots = true
        }

        else if (ff_players < pnum) {
                new removenum = pnum - ff_players
                removenum = min(removenum, botCount)

                if (removenum > 0) {
                        set_task(botDelay,"removeBot",0,_,_,"a",removenum)
                        set_task(botDelay * (removenum + 1),"doneChanging")
                        changingBots = true
                }
        }

        checkingStatus = false
}


public ReadNames() {

        new botnames_file[128]
        get_configsdir(botnames_file, 63)
        format(botnames_file,127,"%s/botnames.txt",botnames_file)

        new botnames = fopen(botnames_file,"r")

        if (botnames) {
                new data[35]

                while(!feof(botnames)) {

                        if (namesread >= MAX_NAMES) {
                                log_amx("MAX_NAMES exceeded, not all fake client names were able to load")
                                break
                        }

                        fgets(botnames, data, 34)
                        trim(data)

                        new len = strlen(data)
                        if (len <= 0) return
                        if (data[len]-1 == '^n') data[--len] = 0

                        if (equal(data,"") || equal(data,"#",1)) continue

                        copy(namesToUse[namesread],32,data)
                        namesread++
                }

                fclose(botnames)
        }
        else {
                new failmsg[128]
                formatex(failmsg,128,"Unable to read file ^"%s^", it is required to load bot names from", botnames_file)
                log_amx(failmsg)
                set_fail_state(failmsg)
        }
}
发表于 2006-7-31 12:23:41 | 显示全部楼层 来自 中国–江苏–常州

回复: 哪位看得懂代码的,看一下这个插件的SMA

不懂代码,只看到了有好几行
{
for(new id = 1; id <= 32; id++) {

不知道是不是
回复

使用道具 举报

 楼主| 发表于 2006-7-31 17:20:00 | 显示全部楼层 来自 中国–福建–福州

回复: 哪位看得懂代码的,看一下这个插件的SMA

楼上的那个参数我有改过,好像不太行。不知哪个兄弟能懂的,请指教!
回复

使用道具 举报

发表于 2006-7-31 17:42:05 | 显示全部楼层 来自 中国–广东–深圳

回复: 哪位看得懂代码的,看一下这个插件的SMA

Post by rofation
楼上的那个参数我有改过,好像不太行。不知哪个兄弟能懂的,请指教!


试试这个,把原来的adminslots.sma替代它。
[PHP]#include <amxmodx>
#include <amxmisc>

// Comment if you don't want to hide not used reserved slots
#define HIDE_RESERVED_SLOTS

new g_cmdLoopback[16]

public plugin_init() {
  register_plugin("Slots Reservation",AMXX_VERSION_STR,"AMXX Dev Team")
  register_dictionary("adminslots.txt")
  register_dictionary("common.txt")
  register_cvar("amx_reservation","1")

  format( g_cmdLoopback, 15, "amxres%c%c%c%c" ,
    random_num('A','Z') , random_num('A','Z') ,random_num('A','Z'),random_num('A','Z')  )

  register_clcmd( g_cmdLoopback, "ackSignal" )
  new maxplayers = get_maxplayers()
  new players = get_playersnum(1)
  new limit = maxplayers - get_cvar_num("amx_reservation")
  setVisibleSlots(players, maxplayers, limit)
}

public ackSignal(id) {
  new lReason[64]
  format(lReason,63,"%L",id,"DROPPED_RES")
  server_cmd("kick #%d ^"%s^"", get_user_userid(id), lReason )
}

public client_authorized(id) {
  new maxplayers = get_maxplayers()
  new players = get_playersnum( 1 )
  new limit = maxplayers - get_cvar_num("amx_reservation")
  
  if ( access(id,ADMIN_RESERVATION) || (players <= limit) )
  {
#if defined HIDE_RESERVED_SLOTS
    setVisibleSlots( players , maxplayers, limit )
#endif
    return PLUGIN_CONTINUE
  }

  client_cmd(id,g_cmdLoopback)

  return PLUGIN_HANDLED
}

#if defined HIDE_RESERVED_SLOTS
public client_disconnect(id)
{
  new maxplayers = get_maxplayers()
  setVisibleSlots( get_playersnum(1) - 1 , maxplayers ,
    maxplayers - get_cvar_num("amx_reservation")  )
  return PLUGIN_CONTINUE
}

setVisibleSlots( players , maxplayers , limit )
{
  new num = players + 1

  if ( players == maxplayers )
    num = maxplayers
  else if ( players < limit )
    num = limit
       
  set_cvar_num( "sv_visiblemaxplayers" , 76 )
}
#endif
[/PHP]
回复

使用道具 举报

 楼主| 发表于 2006-8-1 11:29:13 | 显示全部楼层 来自 中国–福建–福州

回复: 哪位看得懂代码的,看一下这个插件的SMA

楼上的想法不错,但编辑出错,NUM不能等于76人
回复

使用道具 举报

发表于 2006-8-1 21:06:50 | 显示全部楼层 来自 中国–广东–深圳

回复: 哪位看得懂代码的,看一下这个插件的SMA

只是个警告而已,不影响使用,那些服务器挂40、50、60的全都是这样改的。。
回复

使用道具 举报

 楼主| 发表于 2006-8-2 15:21:22 | 显示全部楼层 来自 中国–福建–福州

回复: 哪位看得懂代码的,看一下这个插件的SMA

测试过了,无效果。不知还有没有其它方法。或者是一楼的代码修改一下。
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表