Lil' help
#1

http://pastebin.com/QB8dDGBX
I know thats horribly scripted, but what I want to do his, when he uses that,
I want him to be teleported to the closest human "Team[playerid] = HUMAN", even tho he has zombies around him.
But with that code, if a zombie is near him, the var id just remains -1.
I know whats the problem ,but I don't know how to fix it.
if(Team[id2] == ZOMBIE) continue; <- Thats the problem, yet I don't know any other solution.
Reply
#2

I think this will work
pawn Код:
if(PInfo[playerid][ZPerk] == 14)
{
    //if(PInfo[playerid][GodDig] == 1) return SendClientMessage(playerid,red,"You are to tired to dig!");
    new id = -1,Distance,Float:VBPos[3],VBPos2[3];
    GetPlayerPos(playerid,VBPos[0],VBPos[1],VBPos[2]);
    for(new i; i < MAX_PLAYERS;i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(Team[i] == ZOMBIE) continue;

        if(IsPlayerInRangeOfPoint(i,2000,VBPos[0],VBPos[1],VBPos[2]))
        {
            GetPlayerPos(i,VBPos2[0],VBPos2[1],VBPos2[2]);
            if(floatsqroot(floatabs(floatadd(floatsub(VBPos[0],VBPos2[0]),floatsub(VBPos[1],VBPos2[1])))) <  Distance)
            {
                Distance = floatsqroot(floatabs(floatadd(floatsub(VBPos[0],VBPos2[0]),floatsub(VBPos[1],VBPos2[1]))));
                id = i;
            }
        }
    }
   
    if(id == -1) return SendClientMessage(playerid,red,"It seems like the server is empty o.o'");
    PInfo[playerid][GodDig] = 1;
    SetTimerEx("DigToPlayer",3000,false,"ii",playerid,id);
    ApplyAnimation(playerid,"RIFLE","RIFLE_crouchload",0.5,0,0,0,1,3000,1);
    static string[120];
    format(string,sizeof string,"%s(%i) has god digged. Keep an eye on him. || 1 GOD DIG PER ROUND!",GetPName(playerid),playerid);
    SendAdminMessage(red,string);
}
Reply
#3

This should work:
pawn Код:
if(PInfo[playerid][ZPerk] == 14) {
    if(PInfo[playerid][GodDig] == 1) {
        return SendClientMessage(playerid,red,"You are to tired to dig!");
    }
    new
        Float: afPos[3],
        iClosest = -1
    ;
    GetPlayerPos(playerid, afPos[0], afPos[1], afPos[2]);
   
    for(new i = 0, Float: fRange = Float: 0x7F800000, Float: fDist; i < MAX_PLAYERS; ++i) {
        if(!IsPlayerConnected(i) || Team[i] != HUMAN)
            continue;
       
        fDist = GetPlayerDistanceFromPoint(i, afPos[0], afPos[1], afPos[2]);
       
        if(fDist < fRange) {
            iClosest = i;
            fRange = fDist;
        }
    }
    if(iClosest == -1) {
        return SendClientMessage(playerid,red,"It seems like the server is empty o.o'");
    }
    PInfo[playerid][GodDig] = 1;
    SetTimerEx("DigToPlayer", 3000, false, "ii", playerid, iClosest);
    ApplyAnimation(playerid, "RIFLE", "RIFLE_crouchload", 0.5, 0, 0, 0, 1, 3000, 1);
   
    static
        string[120]
    ;
    format(string,sizeof string,"%s(%i) has god digged. Keep an eye on him. || 1 GOD DIG PER ROUND!",GetPName(playerid),playerid);
    SendAdminMessage(red,string);
}
Reply
#4

Quote:
Originally Posted by Viniborn
Посмотреть сообщение
I think this will work
pawn Код:
if(PInfo[playerid][ZPerk] == 14)
{
    //if(PInfo[playerid][GodDig] == 1) return SendClientMessage(playerid,red,"You are to tired to dig!");
    new id = -1,Distance,Float:VBPos[3],VBPos2[3];
    GetPlayerPos(playerid,VBPos[0],VBPos[1],VBPos[2]);
    for(new i; i < MAX_PLAYERS;i++)
    {
        if(!IsPlayerConnected(i)) continue;
        if(Team[i] == ZOMBIE) continue;

        if(IsPlayerInRangeOfPoint(i,2000,VBPos[0],VBPos[1],VBPos[2]))
        {
            GetPlayerPos(i,VBPos2[0],VBPos2[1],VBPos2[2]);
            if(floatsqroot(floatabs(floatadd(floatsub(VBPos[0],VBPos2[0]),floatsub(VBPos[1],VBPos2[1])))) <  Distance)
            {
                Distance = floatsqroot(floatabs(floatadd(floatsub(VBPos[0],VBPos2[0]),floatsub(VBPos[1],VBPos2[1]))));
                id = i;
            }
        }
    }
   
    if(id == -1) return SendClientMessage(playerid,red,"It seems like the server is empty o.o'");
    PInfo[playerid][GodDig] = 1;
    SetTimerEx("DigToPlayer",3000,false,"ii",playerid,id);
    ApplyAnimation(playerid,"RIFLE","RIFLE_crouchload",0.5,0,0,0,1,3000,1);
    static string[120];
    format(string,sizeof string,"%s(%i) has god digged. Keep an eye on him. || 1 GOD DIG PER ROUND!",GetPName(playerid),playerid);
    SendAdminMessage(red,string);
}
Nope, the variable "id" is -1.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)