SA-MP Forums Archive
[+REP] "for" function problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [+REP] "for" function problem (/showthread.php?tid=600207)



[+REP] "for" function problem - E7mad - 05.02.2016

Hello, I've scripted a command to buy a house, I made it currently to send you a message contains the id of the house checkpoint that you are in, but if I use the command while not in a checkpoint, it spams sending me message"word_system"0.... tons of times.

Код:
CMD:h(playerid, params[])
{
	new selection[10];
	if(sscanf(params, "s[20]", selection)) return SendUsageMSG(playerid, "/h [BUY/SELL/CONFIG]");

	if(!strcmp(selection, "buy", true))
	{
	    for(new i = 0; i < MAX_HOUSES; i++)
	    {
	        if(IsPlayerInDynamicCP(playerid, hInfo[i][EntranceCP]))
	        {
	            if(hInfo[i][hOwned] == 0)
	            {
					new string[128];
					format(string, sizeof(string), ""WORD_SYSTEM"%d", hInfo[i][hID]);
					SCM(playerid, COLOR_WHITE, string);
					SetHouseOwner(i, PlayerName(playerid));
				}
			}
		}
	}
	return 1;
}
EDITED


Re: [+REP] "for" function problem - Riddick94 - 05.02.2016

It spams because checkpoints are having internal refresh/update in the game. That's why your chat box is getting loads of the same messages.


Re: [+REP] "for" function problem - E7mad - 05.02.2016

Quote:
Originally Posted by Riddick94
Посмотреть сообщение
It spams because checkpoints are having internal refresh/update in the game. That's why your chat box is getting loads of the same messages.
Edited the thread, and explain more.


Re: [+REP] "for" function problem - E7mad - 05.02.2016

BUMP


Re: [+REP] "for" function problem - Mencent - 05.02.2016

PHP код:
CMD:h(playerid,params[])
{
    new 
selection[10],string[145];
    if(
sscanf(params,"s[10]",selection))return SendUsageMSG(playerid,"/h [BUY/SELL/CONFIG]");
    if(!
strcmp(selection,"buy",true))
    {
        for(new 
i;i<MAX_HOUSES;i++)
        {
            if(
IsPlayerInDynamicCP(playerid,hInfo[i][EntranceCP]))
            {
                if(
hInfo[i][hOwned9 == 0)
                {
                    
format(string,sizeof(string),""WORD_SYSTEM"%d",hInfo[i][hID]);
                    
SCM(playerid,COLOR_WHITE,string);
                    
SetHouseOwner(i,PlayerName(playerid));
                    break;
                }
            }
        }
    }
    return 
1;




Re: [+REP] "for" function problem - E7mad - 05.02.2016

Quote:
Originally Posted by Mencent
Посмотреть сообщение
PHP код:
CMD:h(playerid,params[])
{
    new 
selection[10],string[145];
    if(
sscanf(params,"s[10]",selection))return SendUsageMSG(playerid,"/h [BUY/SELL/CONFIG]");
    if(!
strcmp(selection,"buy",true))
    {
        for(new 
i;i<MAX_HOUSES;i++)
        {
            if(
IsPlayerInDynamicCP(playerid,hInfo[i][EntranceCP]))
            {
                if(
hInfo[i][hOwned9 == 0)
                {
                    
format(string,sizeof(string),""WORD_SYSTEM"%d",hInfo[i][hID]);
                    
SCM(playerid,COLOR_WHITE,string);
                    
SetHouseOwner(i,PlayerName(playerid));
                    break;
                }
            }
        }
    }
    return 
1;

Thank you! +REP'd


Re: [+REP] "for" function problem - E7mad - 05.02.2016

There is still another problem, when I /h buy while not in any checkpoint, it says: 0, as scripted, it has to say: you must be in a house checkpoint..


Re: [+REP] "for" function problem - -CaRRoT - 05.02.2016

Код:
CMD:h(playerid,params[]) 
{ 
    new selection[10],string[145]; 
    if(sscanf(params,"s[10]",selection))return SendUsageMSG(playerid,"/h [BUY/SELL/CONFIG]"); 
    if(!strcmp(selection,"buy",true)) 
    { 
        for(new i;i<MAX_HOUSES;i++) 
        { 
            if(IsPlayerInDynamicCP(playerid,hInfo[i][EntranceCP])) 
            { 
                if(hInfo[i][hOwned9 == 0) 
                { 
                    format(string,sizeof(string),""WORD_SYSTEM"%d",hInfo[i][hID]); 
                    SCM(playerid,COLOR_WHITE,string); 
                    SetHouseOwner(i,PlayerName(playerid)); 
                    break; 
                } 
            }
            else
            {
                  SCM(playerid, COLOR_WHITE, "ERROR: You need to be in a house checkpoint!");
            }
        }
    } 
    return 1; 
}



Re: [+REP] "for" function problem - E7mad - 05.02.2016

Quote:
Originally Posted by -CaRRoT
Посмотреть сообщение
Код:
CMD:h(playerid,params[]) 
{ 
    new selection[10],string[145]; 
    if(sscanf(params,"s[10]",selection))return SendUsageMSG(playerid,"/h [BUY/SELL/CONFIG]"); 
    if(!strcmp(selection,"buy",true)) 
    { 
        for(new i;i<MAX_HOUSES;i++) 
        { 
            if(IsPlayerInDynamicCP(playerid,hInfo[i][EntranceCP])) 
            { 
                if(hInfo[i][hOwned9 == 0) 
                { 
                    format(string,sizeof(string),""WORD_SYSTEM"%d",hInfo[i][hID]); 
                    SCM(playerid,COLOR_WHITE,string); 
                    SetHouseOwner(i,PlayerName(playerid)); 
                    break; 
                } 
            }
            else
            {
                  SCM(playerid, COLOR_WHITE, "ERROR: You need to be in a house checkpoint!");
            }
        }
    } 
    return 1; 
}
Thank you! <3 rep


Re: [+REP] "for" function problem - E7mad - 05.02.2016

-CaRRoT, I've used your script, but when I do /h buy while not in a house checkpoints, it spams me "You must be in a house cp..." 5 or 6 times, then it says: 0