AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Player id return problem (https://forums.alliedmods.net/showthread.php?t=271142)

shirojew 09-06-2015 07:55

Player id return problem
 
Here is my /voteban plugin code:
Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <chatcolor>

#define PLUGIN "0"
#define VERSION "0"
#define AUTHOR "0"

new bool:votestatus
new Options[2]
new target

public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
   
    register_clcmd("say /voteban", "fwVoteMenu")
}

public fwVoteMenu(id){
   
    if(!votestatus){
       
        arrayset(Options, 0, charsmax(Options))
       
        new menu = menu_create("\rГолосование за бан\d:", "fwVotebanHandler")
        new plaid[32], planum
       
        get_players(plaid, planum ,"ch")
       
        for(new i; i<planum; i++){
           
            new info[32], planame[32]
           
            formatex(info, charsmax(info), "\y%d", get_user_userid(plaid[i]))
            get_user_name(plaid[i], planame, charsmax(planame))
            menu_additem(menu, planame, info, 0)
        }
       
        menu_setprop(menu, MPROP_EXITNAME, "\yВыход")
        menu_setprop(menu, MPROP_PERPAGE, 4)
        menu_display(id, menu)
    }
    else
    {
       
        client_print_color(id, RED, "^3[HGLTV] ^1Предыдущее ^4голосование ^1еще не закончилось!")
    }
   
    return PLUGIN_HANDLED
}

public fwVotebanHandler(id, menu, item){
   
    if(item == MENU_EXIT){
       
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }
   
    new access, callback
    new name[32], infostr[32]
   
    menu_item_getinfo(menu, item, access, infostr, charsmax(infostr), name, charsmax(name), callback)
   
    target = find_player("k", str_to_num(infostr))
   
    fwSubmenu(id)
    menu_destroy(menu)
    return PLUGIN_HANDLED
}

public fwSubmenu(id){
   
    new menuname[32], targetname[32]
    new players[32], planum
   
    votestatus = true
   
    get_user_name(target, targetname, charsmax(targetname))
    formatex(menuname, charsmax(menuname), "\rХотите ли забанить игрока^n%s на 30 минут?", targetname)
   
    new submenu = menu_create(menuname, "fwSubmenuHandler")
    menu_additem(submenu, "\yДа")
    menu_additem(submenu, "\yНет")
    menu_setprop(submenu, MPROP_EXIT, -1)
   
    get_players(players, planum ,"ch")
   
    for(new i; i<planum; i++){

        menu_display(players[i], submenu)
    }
   
    set_task(15.0, "fwVoteTask", submenu)
   
    return PLUGIN_HANDLED
}

public fwSubmenuHandler(item){
   
    Options[item]++
    return PLUGIN_HANDLED
}

public fwVoteTask(submenu){
   
    new name[32]
    votestatus = false
    get_user_name(target, name, charsmax(name))
   
    if(Options[0] > Options[1]){
       
        new ip[40]
       
        get_user_ip(target, ip, charsmax(ip), 1)
        server_cmd("addip 1 %s", ip)
       
        client_print_color(0, RED, "^3[HGLTV] ^1По результатам голосования игрок ^4%s ^1был забанен!", name)
    }
    else if(Options[0] < Options[1]){
       
        client_print_color(0, RED, "^3[HGLTV] ^1Недостаточно голосов для бана игрока ^4%s^1!", name)
    }
    else if(Options[0] == Options[1]){
       
        client_print_color(0, RED, "^3[HGLTV] ^1Голосование закончилось вничью! Игрок^4%s ^1не будет забанен!", name)
    }
   
    menu_destroy(submenu)
    return PLUGIN_HANDLED
}

The problem is "target" variable does not return chosen player's id. get_user_name function returns only my server's name and nothing else. That means plugin does not work correctly. Help me, lads! Please! sry for foreign language in plugin

fysiks 09-06-2015 14:01

Re: Player id return problem
 
The first thing that you need to add to your code is to validate the result of find_player() (i.e. make sure that it's not zero before calling any other functions).

Second, the issue is because your info is "\y%d". This is not a number. When you str_to_num() on this, it will always return zero (0). Also, the "info" part of a menu item is never shown and should not have any font formatting.


All times are GMT -4. The time now is 22:06.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.