AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] Is it set_task problem? (https://forums.alliedmods.net/showthread.php?t=25925)

kclteam 03-23-2006 19:10

[SOLVED] Is it set_task problem?
 
Hi!
My concept of set_task was quite immature...finally got them straight...thanx to all the people who helped me

I am using set_task to call a function which gets the data from a field in my MySQL database and acts accordingly. This is done to all users who connect to our server. However, set_task seems to miss out on some players. I dont seem to get the logical/coding flaw that i might have.

Code:

#include <amxmodx>
#include <amxmisc>
#include <dbi>

#define PLUGINNAME "MyDBPlugin"
#define VERSION "1.0"
#define AUTHOR "KCLTeam"

new Sql:sql
public plugin_init() {
        register_plugin(PLUGINNAME, VERSION, AUTHOR)
        new sqlcfgpath[128]
        get_configsdir(sqlcfgpath, 127)
        format(sqlcfgpath, 127, "%s/sql.cfg", sqlcfgpath)
        server_cmd("exec %s", sqlcfgpath)
        server_exec()
       
        if (!connect(sql)) {
                log_amx("Couldn't connect to SQL database at plugin_init! Pausing plugin.")
                pause("a")
                return
        }
        else
                server_print("[%s] Connected successfully to SQL database.", PLUGINNAME)
        dbi_close(sql)
}

public plugin_modules() {
        require_module("dbi")
}

public client_putinserver(id) {
        if (is_user_bot(id))
                return PLUGIN_HANDLED
        if (!connect(sql)) {
                log_amx("Error - Couldn't connect to SQL db")
                return PLUGIN_HANDLED
        }
        new idd[2]
        idd[0] = id
        new flags[3]
        flags = "b"
        set_task(60.0, "kac_exists", 0, idd, 1)
        return PLUGIN_CONTINUE
       
}

public kac_exists(idd[]) {
        new ip[32]
        get_user_ip(idd[0], ip, 32, 0)
        const LONGER = 128
        new query[LONGER + 1]
        format(query, LONGER, "SELECT `ip2` FROM `amxx_register` WHERE `ip` = ^"%s^" AND `kac_exists` = '0' LIMIT 1", ip)
        new Result:result = dbi_query(sql, query)
                if (result <= RESULT_FAILED) {
                        new error[256]
                        dbi_error(sql, error, 255)
                        log_amx("Error while quering SQL server for %s, Error: %s", ip, error)
                        dbi_close(sql)
                        return PLUGIN_CONTINUE
                }
                else if (result == RESULT_NONE) {
                        server_print("[%s] %s has valid token.", PLUGINNAME, ip)
                        return PLUGIN_CONTINUE
                }

                if (!dbi_nextrow(result)) {
                        server_print("[%s] %s has valid token.", PLUGINNAME, ip)
                        return        PLUGIN_CONTINUE       
                }
                server_print("[%s] %s has invalid token.", PLUGINNAME, ip)
                server_cmd("kick #%d You must have valid token to play on this server", get_user_userid(idd[0]))
        }
        dbi_close(sql)
        return PLUGIN_CONTINUE       
}


bool:connect(&Sql:sql) {
        const LEN = 128
        new error_msg[LEN]

        get_cvar_string("amx_sql_host",mhost,64)
        get_cvar_string("amx_sql_user",muser,32)
        get_cvar_string("amx_sql_pass",mpass,32)
        get_cvar_string("amx_sql_db",mdb,32)

        sql = dbi_connect(mhost, muser, mpass, mdb, error_msg, LEN - 1)

        if (!sql) {
                log_amx("ERROR - Can't connect to SQL db: %s", error_msg)
                return false
        }

        return true
}

Some people get kicked for not having valid token, while some are not kicked. But people having valid token are never kicked.

Thanx in advance.

Jordan 03-23-2006 19:46

Try setting it to:

Code:
set_task(60.0, "kac_exists", 0, id, 1)

kclteam 03-24-2006 03:31

argument type mismatch..
 
Sorry but your suggestion doesn't seem to help...:(

I get the following error:
Code:

argument type mismatch (argument 4)
Ne other idea?

v3x 03-24-2006 04:23

Well .. what's the line?

kclteam 03-24-2006 04:56

Set_task
 
the line where error pops out is the line where I changed the argument for set_task on Satan's suggestion.

When I pass idd (an array) to kac_exists function thru set_task, I don't get any errors while compilation but only first person to connect is checked for valid token and rest are simply ignored.

I want my plugin to wait for 60 seconds after a client has connected and then check if the token is valid or not in DB. This task should be set for all people who connect but doesnt happen so.

Ne suggestions?

akysiev 03-24-2006 07:03

I know I didn't change much but see if it works:

Code:
public client_putinserver(id) {     if (is_user_bot(id))         return PLUGIN_HANDLED     if (!connect(sql))     {         log_amx("Error - Couldn't connect to SQL db")         return PLUGIN_HANDLED     }     new idd[1]     idd[0] = id     set_task(60.0, "kac_exists", 0, idd, 1)     return PLUGIN_CONTINUE }

Don't know if the array length would have any effect on it but its worth a shot.

kclteam 03-24-2006 08:34

thnx
 
thnx mate...

I got it working! I guess by just changing the array size it mattered. Why did it? Neway...now I hav one more doubt.

Whenever a client joins the server, this task is set for him. But assuming a client disconnects before the time for execution is reached for the task...wat happens then?

If i use remove_task in client_disconnect(id), will it remove the task set for all players or for the particualr player who disconnected?

akysiev 03-24-2006 08:39

It would remove the task for all players since all of them are grouped under task id 0. To solve this, use a unique task id as follows:

Code:
public client_putinserver(id) {     if (is_user_bot(id))         return PLUGIN_HANDLED     if (!connect(sql))     {         log_amx("Error - Couldn't connect to SQL db")         return PLUGIN_HANDLED     }     new idd[1]     idd[0] = id     set_task(60.0, "kac_exists", 50 + id, idd, 1)     return PLUGIN_CONTINUE } public client_disconnect(id) {     remove_task(50 + id); }

Make sure that you don't set any other tasks with an id between 50, or whatever arbitrary number you want to start with, and 82, or 32 plus your number.

kclteam 03-24-2006 09:25

yoohoo
 
thank you very much...

this idea rocked...now its working fine
:)

thank you akysiev, v3x and satan for all the help.


All times are GMT -4. The time now is 16:41.

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