Loop isn't working?
#5

What you are trying to do, works with a global variable increment. As of now, everytime you execute that command, 'number' gets set to 1, and it is incremented AFTER the loop which is useless because you will still reset it the next you execute the command.

pawn Код:
static number = 0;

CMD:createhouse(playerid, params[])
{
    new string[128], Float:pos[3];
   
    if(!IsPlayerLoggedIn(playerid))
    {
        SendClientMessage(playerid, -1, "You are restricted from using commands until you log in.");
        return 1;
    }
    if(PlayerInfo[playerid][pAdminLevel] < 1)
    {
        SendClientMessage(playerid, -1, "You do not have the authority to use this command.");
        return 1;
    }
    if(!AdminDuty[playerid])
    {
        SendClientMessage(playerid, -1, "You are not on duty as an Administrator (/aduty).");
        return 1;
    }
       
    number++;
   
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    format(HouseInfo[number][hAddress], 32, "%d San Fierro Way", number);
    HouseInfo[number][hPrice] = 200000;
    HouseInfo[number][hEnterPos][0] = pos[0];
    HouseInfo[number][hEnterPos][1] = pos[1];
    HouseInfo[number][hEnterPos][2] = pos[2];
    HouseInfo[number][hPickup] = CreateDynamicPickup(1273, 1, pos[0], pos[1], pos[2], -1, -1, -1, 30.0);
    format(string, sizeof(string), "House ID: %d\nAddress: %s\nPrice: $%d", number, HouseInfo[number][hAddress], HouseInfo[number][hPrice]);
    HouseInfo[number][hText] = CreateDynamic3DTextLabel(string, COLOR_WHITE, pos[0], pos[1], pos[2]+0.3, 15);
    format(string, sizeof(string), "You have created House ID %d.", number);
    SendClientMessage(playerid, -1, string);
   
    return 1;
}
Note that this is really not good code, you should add a lot of checks and there are a lot of better ways of doing the same thing, but since you posted for this, this should work.
Reply


Messages In This Thread
Loop isn't working? - by AphexCCFC - 14.04.2014, 07:02
Re: Loop isn't working? - by Lidor124 - 14.04.2014, 07:09
Re: Loop isn't working? - by AphexCCFC - 14.04.2014, 07:21
Re: Loop isn't working? - by Lidor124 - 14.04.2014, 07:23
Re: Loop isn't working? - by RajatPawar - 14.04.2014, 07:25
Re: Loop isn't working? - by AphexCCFC - 14.04.2014, 07:35
Re: Loop isn't working? - by AphexCCFC - 14.04.2014, 07:37
Re: Loop isn't working? - by Dokins - 14.04.2014, 11:12

Forum Jump:


Users browsing this thread: 2 Guest(s)