Little string problem
#1

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


Forum Jump:


Users browsing this thread: 1 Guest(s)