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=456975)
Loop -
[MG]Dimi - 08.08.2013
So I got one problem. I don't know why is it happening or I'm just stupid not to see cause but here it is.
Code:
pawn Код:
public AddPlayerRaceCount(playerid,place)
{
printf("AddplayerRaceCount: playerid: %d, place: %d",playerid,place);
//code
switch(place1) //place1 is defined don't worry
{
case 1:
{
print("1");
//code
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerConnected(i))
{
printf("player ID %d is here: bet id is %d and playerid(aka winner is %d)",i,Info[i][BetID],playerid);
if(Info[i][BetID] == playerid)
{
new amount = Info[i][BetAmount]*2;
format(msg,170,"BetSys: %s won $%d by betting on %s to win race!",PlayerName(i),amount,PlayerName(playerid));
SendClientMessageToAll(ORANGE,msg);
GivePlayerCash(i,amount);
print("Won bet");
}
print("restored vars");
}
}
print("2");
//rest of code
And here is debug
Код:
[16:40:36] AddplayerRaceCount: playerid: 1, place: 2
[16:40:36] 1
[16:40:36] player ID 0 is here: bet id is 1 and playerid(aka winner is 1)
[16:40:36] Won bet
[16:40:36] restored vars
[16:40:36] player ID 1 is here: bet id is 1 and playerid(aka winner is 105)
[16:40:36] restored vars
[16:40:36] player ID 2 is here: bet id is 1 and playerid(aka winner is 105)
[16:40:36] restored vars
[16:40:36] 2
[16:40:36] 3
[16:40:36] 4
[16:40:36] end
3,4, end are prints till callback end.
As you can see playerid is good for i=0 in loop. But for i=1 in loop playerid becomes 105. Same for i=2 and so on. Any solution?
Re: Loop - Nofear192 - 08.08.2013
is it IRC bots ;o if it is there is no !msg Sir D:
Re: Loop -
[MG]Dimi - 08.08.2013
msg is defined up //code before loop start.
Re: Loop - Nofear192 - 08.08.2013
//code
switch(place1) //place1 is defined don't worry
{
case 1:
{
print("1");
//code
it isn't there bro
Re: Loop -
[MG]Dimi - 08.08.2013
You see where it says //code? //code replaces actual code that exists there which isn't important for you to see.
Re: Loop -
Vrag - 08.08.2013
Define msg
Re: Loop -
[MG]Dimi - 08.08.2013
//code is
new msg[50];
new place1 = place - 1;
if(place1 > 3 || place1 < 1) return 1;
Which can't help you. Problem is in loop. Not with message.
Re: Loop -
Misiur - 08.08.2013
Buffer overflow. Msg is 50 cells long, and you are allowing packing of 170 cells into it. Increase the size, or reduce allowed characters in format (second argument)
Re: Loop -
[MG]Dimi - 08.08.2013
Okey I see that. You sure it will cause playerid to change value? I can't test atm.