loop client message
#1



pawn Код:
CMD:buyspawn(playerid, params[])
{
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_RED, "You need to login before use command.");
    for(new i = 0; i < MAX_PICKUP; i++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 1, pPickInfo[i][dXe], pPickInfo[i][dYe], pPickInfo[i][dZe]))
        {
            if(PlayerInfo[playerid][pMoney] < 100) return SendClientMessage(playerid, COLOR_BLUE2, "You need $100 for this.");
            if(pPickInfo[i][dMi] == 1)
            {
                if(PlayerInfo[playerid][pTeamFaction] == 1 )
                {
                    PlayerInfo[playerid][pMoney] -= 100;
                    SetSpawnInfo(playerid, gTeam[playerid], gSkin[playerid], pPickInfo[i][dXe], pPickInfo[i][dYe], pPickInfo[i][dZe], pPickInfo[i][dAe], -1, -1, -1, -1, -1, -1);
                    new str[196];
                    format(str, sizeof(str), "UPDATE `playeraccounts` SET pSpawnPosX='%0.2f', pSpawnPosY='%0.2f', pSpawnPosZ='%0.2f', pSpawnPosFacing='%0.2f', pSpawnSaved='1', pMoney='%d' WHERE pID='%d'", pPickInfo[i][dXe], pPickInfo[i][dYe], pPickInfo[i][dZe], pPickInfo[i][dAe], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pID]);
                    mysql_query(Connection, str);
                    PlayerInfo[playerid][pSpawnPosX] = pPickInfo[i][dXe];
                    PlayerInfo[playerid][pSpawnPosY] = pPickInfo[i][dYe];
                    PlayerInfo[playerid][pSpawnPosZ] = pPickInfo[i][dZe];
                    PlayerInfo[playerid][pSpawnPosFacing] = pPickInfo[i][dAe];
                    PlayerInfo[playerid][pSpawnSaved] = 1;

                    new query[100];
                    mysql_format(Connection, query, sizeof(query), "SELECT * FROM `playeraccounts` WHERE `Username` = '%e' LIMIT 1", pName(playerid));
                    mysql_query(Connection, query);

                    PlayerInfo[playerid][pMoney] = cache_get_field_content_int(0, "pMoney");
                    a_SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
                }
                else
                {
                    SendClientMessage(playerid, COLOR_BLUE2, "You are in the wrong team for this spawn.");
                }
            }
            if(pPickInfo[i][dMi] == 2)
            {
                if(PlayerInfo[playerid][pTeamFaction] == 2)
                {
                    PlayerInfo[playerid][pMoney] -= 100;
                    SetSpawnInfo(playerid, gTeam[playerid], gSkin[playerid], pPickInfo[i][dXe], pPickInfo[i][dYe], pPickInfo[i][dZe], pPickInfo[i][dAe], -1, -1, -1, -1, -1, -1);
                    new str[196];
                    format(str, sizeof(str), "UPDATE `playeraccounts` SET pSpawnPosX='%0.2f', pSpawnPosY='%0.2f', pSpawnPosZ='%0.2f', pSpawnPosFacing='%0.2f', pSpawnSaved='1', pMoney='%d' WHERE pID='%d'", pPickInfo[i][dXe], pPickInfo[i][dYe], pPickInfo[i][dZe], pPickInfo[i][dAe], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pID]);
                    mysql_query(Connection, str);
                    PlayerInfo[playerid][pSpawnPosX] = pPickInfo[i][dXe];
                    PlayerInfo[playerid][pSpawnPosY] = pPickInfo[i][dYe];
                    PlayerInfo[playerid][pSpawnPosZ] = pPickInfo[i][dZe];
                    PlayerInfo[playerid][pSpawnPosFacing] = pPickInfo[i][dAe];
                    PlayerInfo[playerid][pSpawnSaved] = 1;

                    new query[100];
                    mysql_format(Connection, query, sizeof(query), "SELECT * FROM `playeraccounts` WHERE `Username` = '%e' LIMIT 1", pName(playerid));
                    mysql_query(Connection, query);

                    PlayerInfo[playerid][pMoney] = cache_get_field_content_int(0, "pMoney");
                    a_SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
                }
                else
                {
                    SendClientMessage(playerid, COLOR_BLUE2, "You are in the wrong team for this spawn.");
                }
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_BLUE2, "You are too far from spawn points.");
        }
    }
    return 1;
}
Reply
#2

what is the problem actually ? this is only a block of code
Reply
#3

That picture
Reply
#4

Because you're doing:
PHP код:
else
        {
            
SendClientMessage(playeridCOLOR_BLUE2"You are too far from spawn points.");
        } 
inside the loop.

You're looping through MAX_PICKUPS and everytime you aren't near the x, y, z of a pickup, it'll send that message for that pickup.
Reply
#5

Can you try like this ?
Код:
CMD:buyspawn(playerid, params[])
{
	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_RED, "You need to login before use command.");
        new successful;///////////added line//////////////
	for(new i = 0; i < MAX_PICKUP; i++)
	{
		if(IsPlayerInRangeOfPoint(playerid, 1, pPickInfo[i][dXe], pPickInfo[i][dYe], pPickInfo[i][dZe]))
		{
  			if(PlayerInfo[playerid][pMoney] < 100) return SendClientMessage(playerid, COLOR_BLUE2, "You need $100 for this.");
  			if(pPickInfo[i][dMi] == 1)
  			{
	  		    if(PlayerInfo[playerid][pTeamFaction] == 1 )
				{
				    PlayerInfo[playerid][pMoney] -= 100;
			   		SetSpawnInfo(playerid, gTeam[playerid], gSkin[playerid], pPickInfo[i][dXe], pPickInfo[i][dYe], pPickInfo[i][dZe], pPickInfo[i][dAe], -1, -1, -1, -1, -1, -1);
					new str[196];
					format(str, sizeof(str), "UPDATE `playeraccounts` SET pSpawnPosX='%0.2f', pSpawnPosY='%0.2f', pSpawnPosZ='%0.2f', pSpawnPosFacing='%0.2f', pSpawnSaved='1', pMoney='%d' WHERE pID='%d'", pPickInfo[i][dXe], pPickInfo[i][dYe], pPickInfo[i][dZe], pPickInfo[i][dAe], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pID]);
					mysql_query(Connection, str);
					PlayerInfo[playerid][pSpawnPosX] = pPickInfo[i][dXe];
					PlayerInfo[playerid][pSpawnPosY] = pPickInfo[i][dYe];
					PlayerInfo[playerid][pSpawnPosZ] = pPickInfo[i][dZe];
					PlayerInfo[playerid][pSpawnPosFacing] = pPickInfo[i][dAe];
                                        successful=1;/////////////////////added line///////////////////777
					PlayerInfo[playerid][pSpawnSaved] = 1;

					new query[100];
			        mysql_format(Connection, query, sizeof(query), "SELECT * FROM `playeraccounts` WHERE `Username` = '%e' LIMIT 1", pName(playerid));
			       	mysql_query(Connection, query);

			        PlayerInfo[playerid][pMoney] = cache_get_field_content_int(0, "pMoney");
			  		a_SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
			    }
 		    	else
				{
				    SendClientMessage(playerid, COLOR_BLUE2, "You are in the wrong team for this spawn.");
				}
		    }
  			if(pPickInfo[i][dMi] == 2)
  			{
			    if(PlayerInfo[playerid][pTeamFaction] == 2)
				{
				    PlayerInfo[playerid][pMoney] -= 100;
			   		SetSpawnInfo(playerid, gTeam[playerid], gSkin[playerid], pPickInfo[i][dXe], pPickInfo[i][dYe], pPickInfo[i][dZe], pPickInfo[i][dAe], -1, -1, -1, -1, -1, -1);
					new str[196];
					format(str, sizeof(str), "UPDATE `playeraccounts` SET pSpawnPosX='%0.2f', pSpawnPosY='%0.2f', pSpawnPosZ='%0.2f', pSpawnPosFacing='%0.2f', pSpawnSaved='1', pMoney='%d' WHERE pID='%d'", pPickInfo[i][dXe], pPickInfo[i][dYe], pPickInfo[i][dZe], pPickInfo[i][dAe], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pID]);
					mysql_query(Connection, str);
					PlayerInfo[playerid][pSpawnPosX] = pPickInfo[i][dXe];
					PlayerInfo[playerid][pSpawnPosY] = pPickInfo[i][dYe];
					PlayerInfo[playerid][pSpawnPosZ] = pPickInfo[i][dZe];
					PlayerInfo[playerid][pSpawnPosFacing] = pPickInfo[i][dAe];
                                        successful=1; ///////added line///////////////////////////////
					PlayerInfo[playerid][pSpawnSaved] = 1;

					new query[100];
			        mysql_format(Connection, query, sizeof(query), "SELECT * FROM `playeraccounts` WHERE `Username` = '%e' LIMIT 1", pName(playerid));
			       	mysql_query(Connection, query);

			        PlayerInfo[playerid][pMoney] = cache_get_field_content_int(0, "pMoney");
			  		a_SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
			    }
 		    	else
				{
				    SendClientMessage(playerid, COLOR_BLUE2, "You are in the wrong team for this spawn.");
				}
			}
		}
	}
        if(successful==0)//////////added if
        {
            SendClientMessage(playerid, COLOR_BLUE2, "You are too far from spawn points.");
        }
	return 1;
}
Yeah basically i moved the warning out of loop with successful variable.
Reply
#6

i will try
Reply
#7

Also i dont know why youre getting money out of mysql in midgame. You could just use a script money in playerinfo and do all your giveplayermoney's with a giveplayermoneyex function and just get the database working on logins and logouts. Wouldnt it be easier than just getting all the info from database every now and then?

EDIT:-----REMOVED BECAUSE IM BLIND-----
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)