SA-MP Forums Archive
[AYUDA]Algo al conectarse y un cmd. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Non-English (https://sampforum.blast.hk/forumdisplay.php?fid=9)
+--- Forum: Languages (https://sampforum.blast.hk/forumdisplay.php?fid=33)
+---- Forum: Español/Spanish (https://sampforum.blast.hk/forumdisplay.php?fid=29)
+---- Thread: [AYUDA]Algo al conectarse y un cmd. (/showthread.php?tid=197453)



[AYUDA]Algo al conectarse y un cmd. - AnGeeeL - 09.12.2010

Hola a todos... Bueno quisiera saber como puedo hacer para que cuando alguien entre al servidor salga de donde es (pais) y el ID.

Otra cosa..

pawn Код:
new cmd[256], string[128], tmp[256], idx;
   cmd = strtok(cmdtext, idx);
   tmp = strtok(cmdtext, idx);
if(strcmp(cmd, "/gang", true) == 0)
    {
        new gangcmd, gangnum;
        new sendername[MAX_PLAYER_NAME];
        tmp = strtok(cmdtext, idx);

        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /gang [crear/entrar/invitar/salir] [name/number]");
            return 1;
        }
        new giveplayerid;
        giveplayerid = strval(tmp);

        if(strcmp(tmp, "crear", true)==0)
            gangcmd = 1;
        else if(strcmp(tmp, "invitar", true)==0)
            gangcmd = 2;
        else if(strcmp(tmp, "entrar", true)==0)
            gangcmd = 3;
        else if(strcmp(tmp, "salir", true)==0)
            gangcmd = 4;

        tmp = strtok(cmdtext, idx);
        if(gangcmd < 3 && !strlen(tmp))
        {
            if(gangcmd==0)
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /gang [crear/entrar/invitar/salir] [name/number]");
            else if(gangcmd==1)
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /gang [crear] [nombre]");
            else if(gangcmd==2)
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /gang [invitar] [playerID]");
            return 1;
        }

        //Create Gang//
        if(gangcmd==1) {
            if(playerGang[playerid]>0) {
                SendClientMessage(playerid, COLOR_RED, "ya estas en un gang!");
                return 1;
            }

            for(new i = 1; i < MAX_GANGS; i++)
            {
                if(gangInfo[i][0]==0)
                {
                    //name gang
                    format(gangNames[i], MAX_GANG_NAME, "%s", tmp);
                    //Gang exists
                    gangInfo[i][0]=1;
                    //There is one member
                    gangInfo[i][1]=1;
                    //Gang color is player's color
                    gangInfo[i][2]=GetPlayerColor(playerid);

                    //Player is the first gang member
                    gangMembers[i][0] = playerid;
                    format(string, sizeof(string),"acabas de crear un gang'%s' (id: %d)", gangNames[i], i);
                    SendClientMessage(playerid, COLOR_GREEN, string);

                    playerGang[playerid]=i;

                    return 1;
                }
            }

        //Join Gang//
        } else if (gangcmd==3)
        {
            gangnum = gangInvite[playerid];

            if(playerGang[playerid]>0)
            {
                SendClientMessage(playerid,COLOR_RED, "ya estas en un gang!");
                return 1;
            }
            if(gangInvite[playerid]==0)
            {
                SendClientMessage(playerid, COLOR_RED, "tu no puedes invitar a este user");
                return 1;
            }
            if(gangInfo[gangnum][0]==0)
            {
                SendClientMessage(playerid, COLOR_RED, "este gang no existe!");
                return 1;
            }

            if(gangInfo[gangnum][1] < MAX_GANG_MEMBERS)
            {
                new i = gangInfo[gangnum][1];

                gangInvite[playerid]=0;

                gangMembers[gangnum][i] = playerid;

                GetPlayerName(playerid, sendername, MAX_PLAYER_NAME);
                for(new j = 0; j < gangInfo[gangnum][1]; j++)
                {
                    format(string, sizeof(string),"%s ha entrado a tu gang.", sendername);
                    SendClientMessage(gangMembers[gangnum][j], COLOR_ORANGE, string);
                }

                gangInfo[gangnum][1]++;
                playerGang[playerid] = gangnum;

                SetPlayerColor(playerid,gangInfo[gangnum][2]);

                format(string, sizeof(string),"tu entraste al gang: '%s' (id: %d)", gangNames[gangnum], gangnum);
                SendClientMessage(playerid, COLOR_GREEN, string);

                return 1;
            }

            SendClientMessage(playerid, COLOR_RED, "este gang esta lleno.");
            return 1;

        //Invite to Gang//
        }
        else if (gangcmd==2)
        {
            giveplayerid = strval(tmp);

            if(playerGang[playerid]==0)
            {
                SendClientMessage(playerid, COLOR_RED, "no estas en un gang!");
                return 1;
            }
if(giveplayerid == playerid) return SendClientMessage(playerid,COLOR_RED,"ya estas en un gang!");
if(giveplayerid == playerGang[playerid]) return SendClientMessage(playerid,COLOR_RED,"este user ya esta en tu gang!");
//   if(gangMembers[playerGang[playerid]][0]!=playerid) {
//              SendClientMessage(playerid, COLOR_RED, " nesesitas tener un gang para invitar.");
//              return 1;
//          }

            if(IsPlayerConnected(giveplayerid))
            {
                new giveplayer[MAX_PLAYER_NAME];
                GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
                GetPlayerName(playerid, sendername, sizeof(sendername));

                format(string, sizeof(string),"has enviado una invitacion ha %s.", giveplayer);
                SendClientMessage(playerid, COLOR_GREEN, string);
                format(string, sizeof(string),"has recibido una invitacion %s to '%s' (id: %d)", sendername, gangNames[playerGang[playerid]],playerGang[playerid]);
                SendClientMessage(giveplayerid, COLOR_GREEN, string);

                gangInvite[giveplayerid]=playerGang[playerid];

            }
            else
            {
                SendClientMessage(playerid, COLOR_RED, "no existe este jugador!");
            }
        //Leave Gang//
        }
        else if (gangcmd==4)
        {
            PlayerLeaveGang(playerid);
        }
        return 1;
    }

    //------------------- /ganginfo

    if(strcmp(cmd, "/ganginfo", true) == 0) {
        new gangnum;
        new giveplayer[MAX_PLAYER_NAME];
        tmp = strtok(cmdtext, idx);

        if(!strlen(tmp) && playerGang[playerid]==0)
        {
            SendClientMessage(playerid, COLOR_WHITE, "USAGE: /ganginfo [numero]");
            return 1;
        }
        else if (!strlen(tmp))
            gangnum = playerGang[playerid];
        else
            gangnum = strval(tmp);

        if(gangInfo[gangnum][0]==0)
        {
            SendClientMessage(playerid,COLOR_RED, "No existe este gang");
            return 1;
        }

        format(string, sizeof(string),"'%s' Gang Members (id: %d)", gangNames[gangnum], gangnum);
        SendClientMessage(playerid, COLOR_GREEN, string);

        for(new i = 0; i < gangInfo[gangnum][1]; i++)
        {
            GetPlayerName(gangMembers[gangnum][i], giveplayer, sizeof(giveplayer));
            format(string, sizeof(string),"%s (%d)", giveplayer, gangMembers[gangnum][i]);
            SendClientMessage(playerid, COLOR_YELLOW, string);
        }
        return 1;
    }

    //------------------- /gangs

    if(strcmp(cmd, "/gangs", true) == 0)
    {
        new x;

        SendClientMessage(playerid, COLOR_GREEN, "Current Gangs:");
        for(new i=0; i < MAX_GANGS; i++)
        {
            if(gangInfo[i][0]==1)
            {
                format(string, sizeof(string), "%s%s(%d) - %d miembros", string,gangNames[i],i,gangInfo[i][1]);

                x++;
                if(x > 2)
                {
                    SendClientMessage(playerid, COLOR_YELLOW, string);
                    x = 0;
                    format(string, sizeof(string), "");
                }
                else
                {
                    format(string, sizeof(string), "%s, ", string);
                }
            }
        }

        if(x <= 2 && x > 0)
        {
            string[strlen(string)-2] = '.';
            SendClientMessage(playerid, COLOR_YELLOW, string);
        }
        return 1;
    }
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(10983) : error 017: undefined symbol "strtok"
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(10983) : error 033: array must be indexed (variable "cmd")
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(10984) : error 017: undefined symbol "strtok"
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(10984) : error 033: array must be indexed (variable "tmp")
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(10986) : warning 217: loose indentation
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(10990) : error 017: undefined symbol "strtok"
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(10990) : error 033: array must be indexed (variable "tmp")
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(11009) : error 017: undefined symbol "strtok"
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(11009) : error 033: array must be indexed (variable "tmp")
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(11043) : error 017: undefined symbol "string"
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(11043) : error 017: undefined symbol "string"
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(11043) : error 029: invalid expression, assumed zero
C:\Documents and Settings\user\Escritorio\Server\SA-MP 0.3c\gamemodes\TULS.pwn(11043) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


12 Errors.

Como podria arreglar eso?
espero que me puedan ayudar.


Re: [AYUDA]Algo al conectarse y un cmd. - MrDeath537 - 09.12.2010

1) Hay un plugin para eso, se llama GeoIP.
2) strtok no estб definido, definilo.


Respuesta: [AYUDA]Algo al conectarse y un cmd. - TheChaoz - 09.12.2010

lo mismo que te dijo MrDeath
y aca te dejo strtok.
pawn Код:
stock strtok(const string[], &index,seperator=' ')
{
    new length = strlen(string);
    new offset = index;
    new result[MAX_STRING];
    while ((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }

    result[index - offset] = EOS;
    if ((index < length) && (string[index] == seperator))
    {
        index++;
    }
    return result;
}



Respuesta: [AYUDA]Algo al conectarse y un cmd. - AnGeeeL - 09.12.2010

Defini el strtok de otra forma :

pawn Код:
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}

new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
Bueno ya solucione todo me faltaba hacer un public del PlayerLeaveGang(playerid);
Grasias a todos.
pueden cerrar el tema.