Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Support [Server] Loop skipping (Creating only odd numbers)

 
  • 0 Vote(s) - 0 Average
Server Loop skipping (Creating only odd numbers)
Cherry.
Offline

Burgershot Member
Posts: 4
Threads: 4
Joined: Mar 2021
Reputation: 0
#1
2021-10-06, 02:41 AM
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;
}
Radical
Offline

Burgershot Member
Posts: 148
Threads: 21
Joined: Dec 2020
Reputation: 16
#2
2021-10-11, 03:09 PM
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);
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#3
2021-10-11, 03:41 PM
(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.
Radical
Offline

Burgershot Member
Posts: 148
Threads: 21
Joined: Dec 2020
Reputation: 16
#4
2021-10-12, 09:28 AM
(2021-10-11, 03:41 PM)Pinch Wrote: lmao.

what's funny
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode