#1

Hello, I am trying to make something if a gang leader deletes his gang, it will loop through all online players with that gang id and then set their gang id to 0.

pawn Код:
COMMAND:deletee(playerid, params[])
{
    new pName[MAX_PLAYER_NAME], Query[100];
    if(!IsPlayerGangLeader(playerid)) return SendClientMessage(playerid, Red, "You have to be a gang leader of a gang to use this command");
    GetPlayerName(playerid, pName, sizeof(pName));
    for(new i; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][Gang] == PlayerInfo[playerid][Gang])
            {
                PlayerInfo[i][Gang] = 0;
            }
        }
    }
    format(Query, sizeof(Query), "DELETE FROM gangs WHERE owner = '%s'", pName);
    mysql_query(Query);
    format(Query, sizeof(Query), "UPDATE * FROM users SET gang = 0 WHERE gang = %d", PlayerInfo[playerid][Gang]); // heres an error with mysql debug
    mysql_query(Query);
    SendClientMessage(playerid, Green, "You have deleted your gang");
    return 1;
}
What I am trying to do is that it has to find all players with that gang id and then set it to 0, so if a member of that gang logins in, he wouldn't get acces to the gang cmds. What's wrong with that code? thanks
Reply
#2

pawn Код:
format(Query, sizeof(Query), "UPDATE users SET gang = 0 WHERE gang = %d", PlayerInfo[playerid][Gang]);
A simple grammar error :P
Reply
#3

You also should look at your loop again. Store the gang ID in a variable, if another player with a higher ID is in the same group as the player who uses /deletee, he will still be in that gang.

e.g.
pawn Код:
new
    iGangID = PlayerInfo[playerid][Gang];
for(new i; i < MAX_PLAYERS; i ++)
{
    if(IsPlayerConnected(i))
    {
        if(PlayerInfo[i][Gang] == iGangID)
            PlayerInfo[i][Gang] = 0;
    }
}
Reply
#4

@woot: thank you that fixed one of my problems.

There's still some mistake in that code. Let's say a player is offline and the gang leader deletes the gang and when a player login to chat with his gang with /g it will say ( SELECT name FROM gangs WHERE ID = 3) Cowboy: test
where it has to say "You have to be..."

This is my delete cmd

pawn Код:
COMMAND:deletee(playerid, params[])
{
    new pName[MAX_PLAYER_NAME], Query[100], string[128];
    if(!IsPlayerGangLeader(playerid)) return SendClientMessage(playerid, Red, "You have to be a gang leader of a gang to use this command");
    GetPlayerName(playerid, pName, sizeof(pName));
    new iGangID = PlayerInfo[playerid][Gang];
    for(new i; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][Gang] == iGangID)
            {
                format(string, sizeof(string), "Gang Leader %s has deleted the gang. You are now gang less", pName);
                SendClientMessage(i, Red, string);
                PlayerInfo[i][Gang] = 0;
            }
        }
    }
    format(Query, sizeof(Query), "DELETE FROM gangs WHERE owner = '%s'", pName);
    mysql_query(Query);
    format(Query, sizeof(Query), "UPDATE users SET gang = 0 WHERE gang = %d", PlayerInfo[playerid][Gang]);
    mysql_query(Query);
    SendClientMessage(playerid, Green, "You have deleted your gang");
// I believe there's something wrong with the mysql syntax
    return 1;
}

// here's the g command

COMMAND:g(playerid, params[])
{
    if(!PlayerInfo[playerid][Gang]) return SendClientMessage(playerid, Red, "You have to be a member of a gang to use this command");
    new string[128], pName[MAX_PLAYER_NAME];
    if(sscanf(params, "s[128]", params[0])) return SendClientMessage(playerid, Yellow, "Usage: /g <message>");
    GetPlayerName(playerid, pName, sizeof(pName));
    for(new i; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(PlayerInfo[i][Gang] == PlayerInfo[playerid][Gang])
            {
                format(string, sizeof(string), "( %s ) %s: %s", GetGangName(PlayerInfo[i][Gang]), pName, params[0]);
                SendClientMessage(i, Purple, string);
            }
        }
    }
    return 1;
}
Thank you

EDIT: Woot, do I also need to make your loop with /g command?
Reply
#5

Try this

pawn Код:
format(Query, sizeof(Query), "UPDATE users SET gang = '' WHERE gang = %d", PlayerInfo[playerid][Gang]);
mysql_query(Query);
Reply
#6

It still says ( SELECT name FROM gangs WHERE ID = 3) Cowboy: test

Thanks for helping



EDIT: A fast question

This is from my login dialog. Where should I free the result?

pawn Код:
case 2:
        {
            if(!response) return Kick(playerid);
            GetPlayerName(playerid, pName, sizeof(pName));
            mysql_real_escape_string(inputtext, escapepass);
            format(Query, sizeof(Query), "SELECT `name` FROM users WHERE name = '%s' AND password = '%s'", pName, escapepass);
            mysql_query(Query);
            mysql_store_result();
            if(!mysql_num_rows())
            {
                ShowPlayerDialog(playerid...)
            }
            else if(mysql_num_rows() == 1)
            {
                format(Query, sizeof(Query), "SELECT * FROM users WHERE name = '%s'", pName);
                mysql_query(Query);
                mysql_store_result();
                while(mysql_fetch_row_format(Query,"|"))
                {
                    mysql_fetch_field_row(field, "score");
                    SetPlayerScore(playerid, strval(field));
                    mysql_fetch_field_row(field, "money");
                    GivePlayerMoney(playerid, strval(field));
                    mysql_fetch_field_row(field, "adminlevel");
                    PlayerInfo[playerid][pAdminLevel] = strval(field);
                    mysql_fetch_field_row(field, "gang");
                    PlayerInfo[playerid][Gang] = strval(field);
                }
            //  mysql_free_result();
                PlayerInfo[playerid][pLogged] = 1;
            }
        //  mysql_free_result();
        }
Should I free it with the first one or the second, thanks again
Reply
#7

Never mind.

delete this post please.
Reply
#8

Hello,
still need help.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)