SA-MP Forums Archive
/hits - 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)
+--- Thread: /hits (/showthread.php?tid=516948)



/hits - AnonScripter - 02.06.2014

why is this showing "Error: Unmatched Tilde"
instead of the players whom have a hit contract on them.

pawn Code:
CMD:hits(playerid, params[])
{
    new string[256];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && HasHit[i] == 1)
        {

            format(string, sizeof(string), "%s(%d)~n~%s(%d)~n~%s(%d)~n~%s(%d)~n~%s(%d)", GetName(i), i,GetName(i), i,GetName(i), i,GetName(i), i,GetName(i), i);
            TextDrawSetString(List[playerid], string);
            TextDrawShowForPlayer(playerid, List[playerid]);
        }
    }
    return 1;
}



Re: /hits - DavidBilla - 02.06.2014

Well the problem is in your format,check out if this works.

Code:
format(string, sizeof(string), "%s(%d)",GetName(i),i);



Re: /hits - alanhutch - 02.06.2014

<removed>


Re: /hits - Rittik - 02.06.2014

Code:
CMD:hits(playerid, params[])
{
    new string[256];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && HasHit[i] == 1)
        {

            format(string, sizeof(string), "%s(%i)~n~%s(%i)~n~%s(%i)~n~%s(%i)~n~%s(%i)", GetName(i), i,GetName(i), i,GetName(i), i,GetName(i), i,GetName(i), i);
            TextDrawSetString(List[playerid], string);
            TextDrawShowForPlayer(playerid, List[playerid]);
        }
    }
    return 1;
}



Re: /hits - AnonScripter - 02.06.2014

Quote:
Originally Posted by DavidBilla
View Post
Well the problem is in your format,check out if this works.

Code:
format(string, sizeof(string), "%s(%d)",GetName(i),i);
i tried this before, it worked but it only show 1 player name.
what if more than 1 player have a hit contract ? it only shows 1 player's name


Re: /hits - AnonScripter - 02.06.2014

Quote:
Originally Posted by Rittik
View Post
Code:
CMD:hits(playerid, params[])
{
    new string[256];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && HasHit[i] == 1)
        {

            format(string, sizeof(string), "%s(%i)~n~%s(%i)~n~%s(%i)~n~%s(%i)~n~%s(%i)", GetName(i), i,GetName(i), i,GetName(i), i,GetName(i), i,GetName(i), i);
            TextDrawSetString(List[playerid], string);
            TextDrawShowForPlayer(playerid, List[playerid]);
        }
    }
    return 1;
}
worked but there is another problem now.
"Error: unmatched tilde" is solved now, but here is the problem:

if more than 1 player has a hit contract, it chooses the last player that has been contracted and shows it like:

Code:
Player(0)
Player(0)
Player(0)
Player(0)
Player(0)
it also happens if there is just 1 player that has a hit contract.


Re: /hits - Rittik - 02.06.2014

Try this.
Code:
CMD:hits(playerid, params[])
{
    new string[256];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && HasHit[i] == 1)
        {

            format(string, sizeof(string), "%s(%i)~n~", GetName(i), i);
            TextDrawSetString(List[playerid], string);
            TextDrawShowForPlayer(playerid, List[playerid]);
        }
    }
    return 1;
}



Re: /hits - AnonScripter - 02.06.2014

didn't work


Re: /hits - Kyance - 02.06.2014

pawn Code:
CMD:hits(playerid, params[])
{
    new string[256];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && HasHit[i] == 1)
        {

            format(string, sizeof(string), "%s~n~%s(%d)~n~", string, GetName(i), i);
            TextDrawSetString(List[playerid], string);
            TextDrawShowForPlayer(playerid, List[playerid]);
        }
    }
    return 1;
}
Haven't tested, should work though.
EDIT: You can use "HasHit[i]" instead of "HasHit[i] == 1".
+, if that doesn't still work, try using the "TextDrawShowForPlayer" OUTSIDE THE LOOP.
Example:
pawn Code:
CMD:hits(playerid, params[])
{
    new string[256];
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && HasHit[i] == 1)
        {

            format(string, sizeof(string), "%s~n~%s(%d)~n~", string, GetName(i), i);
            TextDrawSetString(List[playerid], string);
        }
    }
   TextDrawShowForPlayer(playerid, List[playerid]); //outside loop!
    return 1;
}



Re: /hits - AnonScripter - 02.06.2014

it worked thank you, rep+