SA-MP Forums Archive
1 function - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: 1 function (/showthread.php?tid=268258)



1 function - BaubaS - 11.07.2011

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;
}



Re: 1 function - Cameltoe - 11.07.2011

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;
}



Re: 1 function - BaubaS - 12.07.2011

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

in line strmid


Re: 1 function - BaubaS - 13.07.2011

bump


Re: 1 function - Calgon - 13.07.2011

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;
}



Re: 1 function - BaubaS - 13.07.2011

Thanks, I will test it soon.


Re: 1 function - Cameltoe - 13.07.2011

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.


Re: 1 function - Gh0sT_ - 15.07.2011

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.