AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Problems Passing Variable (https://forums.alliedmods.net/showthread.php?t=199048)

Pythong 10-23-2012 16:00

Problems Passing Variable
 
What am i doing wrong here? I want it so when a player connects it will query a database to grab a value and then check if that value is larger than a preset cvar. If it is it i will build a "admin flag" used to give perks. eg if i have 1000pts and it does a greater than check, if it passes it will build a sql string to give me that flag which is defined as eorflag (end of round flag)


There are two bold sections im stuck on. The first is the building of the admin flag. The second is passing that admin flag over to GiveReward() to use in the sql query/update string.


Code:

public Action:Command_JoinTeam(client, const String:command[], argc)
{
        new lp = GetLP(client);
        PrintToChat(client, "Points: %i.", lp);
        if (lp >= price_eor)
        {
                new String:setflags[256];
                Format(setflags, sizeof(setflags), "%s", eorflag);
                //PrintToChat = (client, "You have flag: %s", eorflag);
                GiveReward(client, setflags);

        }
        else if (lp >= price_ab)
                {
                        /*new setflags = "";
                        setflags = (%s%s, cv_eorflag, cv_abflag);
                        PrintToChat = (client, "You have flag: %", eorflag, abflag);
                        GiveReward(client, setflags);
                        */
                }
                else if (lp >= price_rs)
                        {
                                /*new setflags = "";
                                setflags = (%s%s, cv_eorflag, cv_abflag, cv_rsflag);
                                PrintToChat = (client, "You have flag: %", eorflag, abflag, rsflag);
                                GiveReward(client, setflags);
                        */
                        }
                        else
                        {
                                PrintToChat(client, "\x01[\x07FF0000RP\x01] Points: \x07FFA500%i\x01. No benefits added.", lp);
                        }       


GetLP(client)
{
        new String:sqlstring[255];
        Format(sqlstring, sizeof(sqlstring), "SELECT points FROM rp WHERE id = %i", sql_id[client]);
       
        SQL_LockDatabase(dbcon);
       
        new Handle:sql = SQL_Query(dbcon, sqlstring);
        SQL_FetchRow(sql);
        new lp = SQL_FetchInt(sql, 0);
        CloseHandle(sql);
       
        SQL_UnlockDatabase(dbcon);
       
        return lp;
}

GiveLP(amount)
{
        new String:sqlstring[256];
        Format(sqlstring, sizeof(sqlstring), "UPDATE rp SET points = points + %i WHERE ingame = 1 AND ingameid = %i", amount, serverid);
        SQL_TQuery(dbcon, EmptyResultSet, sqlstring);
        //PrintToChat("\x01[\x07FF0000RP\x01] New Balance: +\x07FFA500%i\x01.", amount);
}

GiveReward(client, args)
{
        if (IsClientInGame(client))
        {
                // In die lp-Datenbank eintragen (Step 1)
                new String:steamid[50];
                GetClientAuthString(client, steamid, sizeof(steamid))
                new String:sqlstring[256];
                Format(sqlstring, sizeof(sqlstring), "UPDATE rp SET rs = 1, serverid = %i WHERE steamid = '%s'", serverid, steamid);
                SQL_TQuery(dbcon, EmptyResultSet, sqlstring);
               
                // In die sm-Admin Datenbank eintragen (Step 2)
                new String:sqlstring2[256];
                Format(sqlstring2, sizeof(sqlstring2), "INSERT INTO sm_admins(authtype, identity, flags, name, immunity) VALUES ('steam' ,'%s', '%s', '%N', %i)", steamid, rewardflag, client, rsimmunity);
                SQL_TQuery(dbcon, EmptyResultSet, sqlstring2);
               
                ServerCommand("sm_reloadadmins");
        }
}


Powerlord 10-23-2012 16:26

Re: Problems Passing Variable
 
PHP Code:

GiveReward(clientargs

Two things:
  1. Why is the second argument named args? This function isn't a ConCmd as far as I can tell.
  2. args needs to be declared as a String if you're passing a string into it, such as String:args[]

FaTony 10-24-2012 03:10

Re: Problems Passing Variable
 
Why all the stuff is inside jointeam? What's up with your indentation? You shouldn't edit SQL admins, use admin API instead.


All times are GMT -4. The time now is 11:43.

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