1 function
#1

Hi, I want to make function like "GetLeaderName(jobid)".

It should work something like this: If any player field "Direktorius" value is jobid in MySQL then it would return that player name. But, if there arent any player which field "Direktorius" value in MySQL isnt jobid - it will return {hex}Direktorius {hex}neiљrinktas

I tried to do something, but nah, it doesnt work :S:

pawn Код:
stock GetLeaderName(jobid)
{
    new Query[63];
    format(Query, 63, "SELECT Vardas FROM `zaidejudb` ORDER BY `Direktorius` = '%d'", jobid);
    mysql_query(Query);
    mysql_store_result();
    new Name[32];
    while(mysql_fetch_row(Name))
    {
        if(!mysql_num_rows()) Name = "Direktorius {FF0000}neiрrinktas";
    }
    return Name;
}
Reply
#2

Quote:
Originally Posted by BaubaS
Посмотреть сообщение
Hi, I want to make function like "GetLeaderName(jobid)".

It should work something like this: If any player field "Direktorius" value is jobid in MySQL then it would return that player name. But, if there arent any player which field "Direktorius" value in MySQL isnt jobid - it will return {hex}Direktorius {hex}neiљrinktas

I tried to do something, but nah, it doesnt work :S:

pawn Код:
stock GetLeaderName(jobid)
{
    new Query[63];
    format(Query, 63, "SELECT Vardas FROM `zaidejudb` ORDER BY `Direktorius` = '%d'", jobid);
    mysql_query(Query);
    mysql_store_result();
    new Name[32];
    while(mysql_fetch_row(Name))
    {
        if(!mysql_num_rows()) Name = "Direktorius {FF0000}neiрrinktas";
    }
    return Name;
}
pawn Код:
stock GetLeaderName(jobid)
{
    new Query[63];
    format(Query, 63, "SELECT Vardas FROM `zaidejudb` ORDER BY `Direktorius` = '%d'", jobid);
    mysql_query(Query);
    mysql_store_result();
    new Name[32];
    while(mysql_fetch_row(Name))
    {
        if(!mysql_num_rows()) strmid(Name, "Direktorius {FF0000}neiрrinktas")); // Strcat, i prefer strmid.
    }
    return Name;
}
Reply
#3

warning 202: number of arguments does not match definition
warning 202: number of arguments does not match definition

in line strmid
Reply
#4

bump
Reply
#5

pawn Код:
stock GetLeaderName(jobid)
{
    new Query[63];
    format(Query, 63, "SELECT `Vardas` FROM `zaidejudb` ORDER BY `Direktorius` = %d", jobid);
    mysql_query(Query);
    mysql_store_result();
    new Name[MAX_PLAYER_NAME];
    mysql_fetch_row(Name); // you're only retrieving one name
    if(!mysql_num_rows()) { Name = "Direktorius {FF0000}neiрrinktas"; return Name; }
    mysql_free_result();
    return Name;
}
Reply
#6

Thanks, I will test it soon.
Reply
#7

Quote:
Originally Posted by BaubaS
You tried to help me, but I get warnings:

http://forum.sa-mp.com/showthread.ph...=getleadername
Compiles fine here.
Reply
#8

Well, I tried to use Calg00ne one, and nah, it doesnt work at all. It return id 0 name, for example:

My playerid is 0, and my name is "test" and GetLeaderName always(in all job ids) return test. I dont know, maybe it return random ids, because I tested without any other players.

Also, a question: Its better to use sscanf in data loading or fetching rows and then use strval, floatstr and bla bla bla?


PS, this is my friend account.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)