View Single Post
JocAnis
Veteran Member
Join Date: Jun 2010
Old 09-13-2021 , 10:59   Re: Answer correctly or kick
Reply With Quote #3

hello, you can try using this code, add your questions (with answers of course) into: g_szRandomStuff, also it will activate black screenfade on the client (if he is admin) to write message, it looks like this, he has only one chance:


Code:
#include <amxmodx>
#include <amxmisc>

#define TASK_CONNECT 321
new g_iHisQuestion[ 33 ]
new msgScreenFade

enum _:AdminStuff
{
    Question[ 100 ],
    Answer[ 50 ]
}
new const g_szRandomStuff[][ AdminStuff ] =
{
    { "Who is president of USA?",       "biden" },
    { "Are you admin here?",            "yes" },
    { "On what key do you jump?",       "space" },
    { "Do you love our community?",     "yes" }
}

public plugin_init()
{
    register_plugin( "Admin Question/asnwer", "1.0", "JocA" )
    register_clcmd( "say", "said" )

    msgScreenFade = get_user_msgid("ScreenFade")
}
public said( id )
{
    if( is_user_admin( id ) )
    {
        new text[ 100 ]
        read_argv( 1, text, charsmax( text ) )
        if( g_iHisQuestion[ id ] >= 0 )
        {
            if( equal( text, g_szRandomStuff[ g_iHisQuestion[ id ] ][ Answer ] ) )
                g_iHisQuestion[ id ] = -1
            else
                server_cmd( "kick #%d ^"You didnt answer the question correctly", get_user_userid( id ) )

            return PLUGIN_HANDLED
        }
    }
    return PLUGIN_CONTINUE
}
public client_putinserver( id )
{
    g_iHisQuestion[ id ] = -1
    set_task( 3.0, "ask_him", TASK_CONNECT + id )
}
public client_disconnected( id )
{
    g_iHisQuestion[ id ] = -1
    remove_task( id + TASK_CONNECT )
}
public ask_him( task )
{
    new id = task - TASK_CONNECT
    new size = sizeof( g_szRandomStuff )
    g_iHisQuestion[ id ] = random( size )
    fade_screen( id )
    set_dhudmessage( 255, 255, 255, -1.0, -1.0, 0, 0.0, 7.0, 0.0, 0.0 )
    show_dhudmessage( id, fmt( "You must answer correct this question in chat^n(otherwise you will be kicked):^n^n%s", g_szRandomStuff[ g_iHisQuestion[ id ] ][ 0 ] ) )
}
stock fade_screen( id )
{
    message_begin( MSG_ONE_UNRELIABLE, msgScreenFade, { 0, 0, 0 }, id )
    write_short( 4096 * 5 )
    write_short( 4096 * 5 )
    write_short( 0 )
    write_byte( 0 )
    write_byte( 0 )
    write_byte( 0 )
    write_byte( 255 )
    message_end()
}
Please change my questions, they are random on purpose for the testing (question will be 3.0 seconds after he connects on the server)

PS: you need 1.8.3+ amxmodx to compile it
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...)

Last edited by JocAnis; 09-13-2021 at 11:06.
JocAnis is offline