• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Server] Loop skipping (Creating only odd numbers)
#1
Hey.



I have a command of creating houses.

The loop is creating houses just like 1,3,5,7,9,11..etc.



I tried to investigate the problem in the loop and I can't see anything wrong.

Somebody?knows? Here's the code..







Code:
COMMAND:housecreate(playerid, params[]) { new houseid, price, Float:X, Float:Y, Float:Z, UID, text[128]; if(sscanf(params,"ii",houseid, price)) return usage(playerid, "USAGE: /HouseCreate [Class] [Value]"); if(houseid < 1 || houseid > 4) return error(playerid, "Invalid house ID."); new found = 0; for(new i = 1; i < MAX_HOUSES; i) { if(HouseInfo[i][hID] == 0 && found == 0) { ? ? found; ? ? UID = i; format(text, sizeof(text), "House id is %d", UID); SendClientMessage(playerid, -1, text); } } new count = 0; for(new i = 0; i < sizeof(HouseCoordinates); i) { ? ? if(count == 0) ? ? { ? ? ? ? if(HouseCoordinates[i][Class] == houseid) ? ? ? ? { ? ? ? ? count; HouseInfo[UID][hXi] = HouseCoordinates[i][mbX]; HouseInfo[UID][hYi] = HouseCoordinates[i][mbY]; HouseInfo[UID][hZi] = HouseCoordinates[i][mbZ]; HouseInfo[UID][hIntIn] = HouseCoordinates[i][HouseInt]; } } } HouseInfo[UID][hID] = UID; HouseInfo[UID][hValue] = price; HouseInfo[UID][hClass] = houseid; HouseInfo[UID][hIntOut] = GetPlayerInterior(playerid); HouseInfo[UID][hVwOut] = GetPlayerVirtualWorld(playerid); HouseInfo[UID][hVwIn] = MAX_INTS UID; GetPlayerPos(playerid, X, Y, Z); HouseInfo[UID][hXo] = X; HouseInfo[UID][hYo] = Y; HouseInfo[UID][hZo] = Z; new query[516], owner[25]; format(owner, sizeof(owner), "None"); mysql_format(handlesql, query, sizeof(query),"INSERT INTO `houses`(`ID`, `Xo`, `Yo`, `Zo`, `Xi`, `Yi`, `Zi`, `IntOut`, `IntIn`, `VwOut`, `Owner`, `Value`) VALUES (%d, %f, %f, %f, %f, %f, %f, %d, %d, %d, '%e', %d)", UID, X, Y, Z, HouseInfo[UID][hXi], HouseInfo[UID][hYi], HouseInfo[UID][hZi], HouseInfo[UID][hIntOut], HouseInfo[UID][hIntIn], HouseInfo[UID][hVwOut], owner, price); mysql_pquery(handlesql, query); HouseInfo[UID][hIcon] = CreateDynamicCP(HouseInfo[UID][hXo], HouseInfo[UID][hYo], HouseInfo[UID][hZo], 1.5, HouseInfo[UID][hVwOut], -1, -1, 20.0); HouseInfo[UID][hIconi] = CreateDynamicCP(HouseInfo[UID][hXi], HouseInfo[UID][hYi], HouseInfo[UID][hZi], 1.5, HouseInfo[UID][hVwIn], -1, -1, 20.0); UpdateHouseText(UID); Iter_Add(HouseIterator, UID); return 1; }
  Reply
#2
Nothing wrong with loop but you can use Iter_Free().?That's better.



Replace this

Code:
new found = 0; for(new i = 1; i < MAX_HOUSES; i) { if(HouseInfo[i][hID] == 0 && found == 0) { ? ? found; ? ? UID = i; format(text, sizeof(text), "House id is %d", UID); SendClientMessage(playerid, -1, text); } }



With

Code:
UID = Iter_Free(HouseIterator); ? ? if(UID == -1) return error(playerid, "Cannot create more houses. "); ? ? format(text, sizeof(text), "House id is %d", UID); ? ? SendClientMessage(playerid, -1, text);
  Reply
#3
(2021-10-11, 03:09 PM)Radical Wrote: Nothing wrong with loop but you can use Iter_Free().?That's better.



Replace this

Code:
new found = 0; for(new i = 1; i < MAX_HOUSES; i) { if(HouseInfo[i][hID] == 0 && found == 0) { ? ? found; ? ? UID = i; format(text, sizeof(text), "House id is %d", UID); SendClientMessage(playerid, -1, text); } }



With

Code:
UID = Iter_Free(HouseIterator); ? ? if(UID == -1) return error(playerid, "Cannot create more houses. "); ? ? format(text, sizeof(text), "House id is %d", UID); ? ? SendClientMessage(playerid, -1, text);

lmao.
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#4
(2021-10-11, 03:41 PM)Pinch Wrote: lmao.



what's funny
  Reply