loop - 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: loop (
/showthread.php?tid=410324)
loop -
BlackRaven - 25.01.2013
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?
Re: loop -
Da_Noob - 25.01.2013
My guess is that you have 500 housepickups. Everytime the server detects a housepickup it will send a message (the message you formatted).
Re: loop -
EpicNinja - 25.01.2013
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.
Re: loop -
coakiddo - 25.01.2013
Use break; to stop the loop.
Re: loop -
BlackRaven - 25.01.2013
now it doesnt print the owner of house
Re: loop -
Babul - 25.01.2013
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;
}
Re: loop -
BlackRaven - 25.01.2013
Thanks Babul. But now it doesnt display the name of the house owner.