SA-MP Forums Archive
Little string problem - 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: Little string problem (/showthread.php?tid=246778)



Little string problem - Donya - 05.04.2011

Hello.

Problem: this returns [BOT, when the real bot name is [BOT]TrainDriver

ok so the code i posted before, looks for $bot in a string, then deletes it and addes the name of the closest Bot, well, its not really working right, instead of adding [BOT]TrainDriver, its adding [BOT only

pawn Code:
pos = strfind(text, "$bot");
    if(pos != -1)
    {
        strdel(text, pos, pos+4);
        strins(text, Playername(GetClosestBot(playerid)), pos, 24);
    }
Playername and GetClosestBot

pawn Code:
Playername(playerid)
{
    new pName[24];
    if(playerid == INVALID_PLAYER_ID || playerid == -1) pName = " - ";
    else GetPlayerName(playerid, pName, 24);
    return pName;
}

public GetClosestBot(p1)
{
    new Float:dis,Float:dis2,player;
    player = -1;
    dis = 99999.99;
    foreach(Bot,x)
    {
        dis2 = GetDistanceBetweenPlayers(x,p1);
        if(dis2 < dis && dis2 != -1.00)
        {
            dis = dis2;
            player = x;
        }
    }
    return player;
}