#1

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    for(new i; i < MAX_HOUSES; i++)
    {
        if(pickupid == housepickup[i])
        {
            new str[120];
            format(str, sizeof(str),"You are standing on %s house",houseinfo[i][owner]);
            printf("%s",houseinfo[i][owner]);
            SendClientMessage(playerid,COLOR_GREEN,str);
        }
    }
    return 1;
}
The loop prints 500 times the message , what is wrong?
Reply
#2

My guess is that you have 500 housepickups. Everytime the server detects a housepickup it will send a message (the message you formatted).
Reply
#3

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    for(new i; i < MAX_HOUSES; i++)
    {
        if(pickupid == housepickup[i])
        {
            new str[120];
            format(str, sizeof(str),"You are standing on %s house",houseinfo[i][owner]);
            printf("%s",houseinfo[i][owner]);
        }
    }
    SendClientMessage(playerid,COLOR_GREEN,str);
    return 1;
}
Sending message to playerid inside loop sends him the message about "MAX_HOUSES" times.
Reply
#4

Use break; to stop the loop.
Reply
#5

now it doesnt print the owner of house
Reply
#6

the reason is the SendClientMessage being outside of the loop. i assume there is only 1 house for a player, so if you break/return from the nested loop (good idea btw), it wont call the SCM. try this, slightly changed:
Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
	for(new i; i < MAX_HOUSES; i++)
	{
		if(pickupid == housepickup[i])
		{
			new str[120];
			format(str, sizeof(str),"You are standing on %s house",houseinfo[i][owner]);
			printf("%s",houseinfo[i][owner]);
			SendClientMessage(playerid,COLOR_GREEN,str);
			return 1;
		}
	}
	return 1;
}
Reply
#7

Thanks Babul. But now it doesnt display the name of the house owner.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)