SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 21/04/2012, 09:52 PM   #1
Luis-
High-roller
 
Luis-'s Avatar
 
Join Date: Jan 2010
Location: Wigan, England
Posts: 2,906
Reputation: 220
Default Wanted list wont work

I have made a wanted list for my server and it wont work as I want it to, it doesn't loop through all the wanted players and list them;
pawn Code:
CMD:wanted(playerid, params[])
{
    if(pTeam[playerid] == 7) {
        for(new i = 0; i < MAX_PLAYERS; i++) {
            if(GetPlayerWantedLevel(i) > 0) {
                new string[128];
                format(string, sizeof(string), "{E60000}%s {FFFFFF}(Wanted Level: {E60000}%d{FFFFFF})\n", Name(i), GetPlayerWantedLevel(i));
                ShowPlayerDialog(playerid, DIALOG_WANTED, DIALOG_STYLE_LIST, "SASP - Wanted List", string, "Done", "");
            }
        }
    }
    else {
        SendClientMessage(playerid, COLOR_VIOLET, "INFO: {FFFFFF}You're not in the SASP.");
    }
    return 1;
}
It only returns one player who is wanted.
__________________

SA-MP Server
Luis' Fun Box - Coming Soon (PM me for more information)
---------------------------------
YouTube
YouTube | Twitter
Videos uploaded daily

Luis- is offline   Reply With Quote
Old 21/04/2012, 10:14 PM   #2
[MG]Dimi
High-roller
 
[MG]Dimi's Avatar
 
Join Date: Mar 2011
Location: Serbia
Posts: 1,298
Reputation: 144
Default Re: Wanted list wont work

pawn Code:
CMD:wanted(playerid, params[])
{
    if(pTeam[playerid] == 7)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            new string[400];//we will create a little big string coz 128 is too small, also we will make it outside loop because we don't
            // wait it to new emprty string is created MAX_PLAYER times
            if(GetPlayerWantedLevel(i) > 0)
            {
                format(string, sizeof(string), "%s{E60000}%s {FFFFFF}(Wanted Level: {E60000}%d{FFFFFF})\n", string,Name(i), GetPlayerWantedLevel(i)); //we add old string into new string
            }
        }
        ShowPlayerDialog(playerid, DIALOG_WANTED, DIALOG_STYLE_LIST, "SASP - Wanted List", string, "Done", ""); //we also show him dialog after loop is done. Your code would show him around
        //15 dialogs at same same so he would see only last one.
    }
    else
    {
        SendClientMessage(playerid, COLOR_VIOLET, "INFO: {FFFFFF}You're not in the SASP.");
    }
    return 1;
}
Follow comments in script.
__________________
Scripting Admin/Account/VIP Systems for $$$ using ZCMD,dcmd, Dini, MySQL and sscanf.Scripting IRC Systems with all possible functions. (Echo channels, Chat channels, Admin channels...)Long time Experience with IRC Systems.For both offers PM me
Mini Games ServerServer IP:178.238.236.62:7777
[MG]Dimi is offline   Reply With Quote
Old 21/04/2012, 10:15 PM   #3
PrawkC
Gangsta
 
Join Date: May 2011
Posts: 498
Reputation: 52
Default Re: Wanted list wont work

The problem is you're showing the dialog in the for loop, so of course its just going to show one player.. you need to form the string (the list of wanted players) inside the loop, then show the dialog outside of it.
PrawkC is offline   Reply With Quote
Old 22/04/2012, 02:43 AM   #4
ReneG
High-roller
 
Join Date: Oct 2011
Location: Sublime Text 2
Posts: 2,005
Reputation: 333
Default Re: Wanted list wont work

Try using strcat with a large string, and then showing the dialog after the loop.
ReneG is offline   Reply With Quote
Old 22/04/2012, 02:47 AM   #5
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,316
Reputation: 908
Default Re: Wanted list wont work

If you indented with a style that was actually readable, you'd realise your mistake. Just a tip.

pawn Code:
CMD:wanted(playerid, params[])
{
    if(pTeam[playerid] != 7) return SendClientMessage(playerid, COLOR_VIOLET, "INFO: {FFFFFF}You're not in the SASP.");
    new dstring[500]; // Work out what size you need
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!GetPlayerWantedLevel(i)) continue;
        format(dstring, sizeof(dstring), "%s{E60000}%s {FFFFFF}(Wanted Level: {E60000}%d{FFFFFF})\n", dstring, Name(i), GetPlayerWantedLevel(i));
    }
    ShowPlayerDialog(playerid, DIALOG_WANTED, DIALOG_STYLE_LIST, "SASP - Wanted List", dstring, "Done", "");
    return 1;
}
__________________
>> Click here to see my releases.

Please do not PM me requesting help. Here you have a forum with 11,000+ active users - why are you limiting your help to one person?
MP2 is offline   Reply With Quote
Old 22/04/2012, 03:35 AM   #6
Marricio
Gangsta
 
Join Date: Dec 2010
Posts: 622
Reputation: 54
Default Respuesta: Wanted list wont work

Try using strcat, it works well.
__________________
Lawedan Roleplay
www.lawedan.com / server.lawedan.com:7777

Lawedan Roleplay is an heavy roleplay server hosted on SA:MP, with a focus on a realistic economy and high quality roleplay. We strive to deliver a seamless and quality product to our players, ensuring our staff team and our community communication is the best of the best. Our script is completely made from scratch, lovingly developed by our premium development team.
Marricio is offline   Reply With Quote
Old 22/04/2012, 03:42 AM   #7
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,316
Reputation: 908
Default Re: Wanted list wont work

Using strcat would be stupid, because he has to FORMAT the string. Why use format then strcat when only format is needed..?
__________________
>> Click here to see my releases.

Please do not PM me requesting help. Here you have a forum with 11,000+ active users - why are you limiting your help to one person?
MP2 is offline   Reply With Quote
Old 22/04/2012, 03:46 AM   #8
Marricio
Gangsta
 
Join Date: Dec 2010
Posts: 622
Reputation: 54
Default Respuesta: Wanted list wont work

Formating it will only return 1 player( if there is one or more wanted players ), since when you format it replaces the old string, as far i know.

EDIT: maybe this can work?
pawn Code:
CMD:wanted(playerid, params[])
{
    if(pTeam[playerid] == 7)
    {
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            new szString[128], szResult[512];
            if(GetPlayerWantedLevel(i) > 0)
            {
                format( szString, 128, "%s{E60000}%s {FFFFFF}(Wanted Level: {E60000}%d{FFFFFF})\n", string,Name(i), GetPlayerWantedLevel(i));
                strcat( szResult, szString, 512 );
            }
        }
       
        ShowPlayerDialog(playerid, DIALOG_WANTED, DIALOG_STYLE_LIST, "SASP - Wanted List", szResult, "Done", "");
    }
    else
        return SendClientMessage(playerid, COLOR_VIOLET, "INFO: {FFFFFF}You're not in the SASP.");
    return 1;
}
__________________
Lawedan Roleplay
www.lawedan.com / server.lawedan.com:7777

Lawedan Roleplay is an heavy roleplay server hosted on SA:MP, with a focus on a realistic economy and high quality roleplay. We strive to deliver a seamless and quality product to our players, ensuring our staff team and our community communication is the best of the best. Our script is completely made from scratch, lovingly developed by our premium development team.
Marricio is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wanted list zack3021 Help Archive 2 24/11/2010 01:01 AM
Server wont so on other servers list?? slowride326 Server Support 3 25/09/2010 03:24 AM
Server list wont load!!!!!!!! kevin___2k10 Client Support 7 28/02/2010 02:07 AM
Wanted list Hot Help Archive 0 30/07/2009 10:02 PM
/wanted list of persons with wanted [EDIT... problem solved] jesse237 Help Archive 8 24/02/2009 11:19 AM


All times are GMT. The time now is 06:18 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.