SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 24/06/2019, 09:22 PM   #1
Gendy
Little Clucker
 
Join Date: May 2014
Posts: 2
Reputation: 0
Default [HELP]Problem with floating point arrays

So im doing this basic business system and im having a hard time with floating points.

Code:
new Float:bizlist[50][4]; // First cell for all businesses, second for (Biz type, x coordinate, y coordinate, z coordinate) //
CMD:createbiz(playerid, params[])
{
    new bizid;
    new message[128];
    new Float:xax, Float:yax, Float:zax;
    GetPlayerPos(playerid, xax, yax, zax);
    if(!sscanf(params, "f", bizid))
    {
        for(new i = 0; i < 50; i++)
        {
            if((bizlist[i][1] == 0) && (bizlist[i][2] == 0) && (bizlist[i][3] == 0))
            {
                bizlist[i][1] = xax;
                bizlist[i][2] = yax;
                bizlist[i][3] = zax;
                bizlist[i][0] = bizid;
                format(message,sizeof(message), "Business of type %f has been created succesfully at coordinates X:%f Y:%f Z:%f",bizid, xax, yax, zax);
                SendClientMessage(playerid, 0x07fc51FF, message);
                if(bizid == 0)
                {
                     SetPlayerMapIcon(playerid, i, xax, yax, zax, 6, -1, MAPICON_GLOBAL);
                }
                else if(bizid == 1)
                {
                    SetPlayerMapIcon(playerid, i, xax, yax, zax, 45, -1, MAPICON_GLOBAL);
                }
                else if(bizid == 2)
                {
                    SetPlayerMapIcon(playerid, i, xax, yax, zax, 48, -1, MAPICON_GLOBAL);
                }
                break;
            }

            if(i > 49)
            {
                SendClientMessage(playerid, 0xff0000FF, "All business slots are full");
            }
        }
    }
    else
    {
        SendClientMessage(playerid, 0x999999FF, "/createbiz <business id> (0-Ammu , 1-Clothes, 2-Stripclub)");
    }

    return 1;
}



This line, it doesn't store the entered bizid from the user to store it in the bizlist array, but instead it stores instead a weird floating point number. (I knew this since I made a /showallbiz command that displays business id and type.)

Code:
bizlist[i][0] = bizid;
Gendy is offline   Reply With Quote
Old 24/06/2019, 11:02 PM   #2
Plastikmensch
Huge Clucker
 
Join Date: Aug 2016
Posts: 240
Reputation: 13
Default Re: [HELP]Problem with floating point arrays

You are working with different types.
If you want to store different types inside an array use an enum.
Code:
enum e_bizlist {
   bType, //integer
   Float:bX, //Float
   Float:bY,
   Float:bZ
}
new bizlist[50][e_bizlist];
And use "d" as specifier in sscanf for bizid
Plastikmensch is offline   Reply With Quote
Old 25/06/2019, 04:05 PM   #3
Gendy
Little Clucker
 
Join Date: May 2014
Posts: 2
Reputation: 0
Default Re: [HELP]Problem with floating point arrays

Quote:
Originally Posted by Plastikmensch View Post
You are working with different types.
If you want to store different types inside an array use an enum.
Code:
enum e_bizlist {
   bType, //integer
   Float:bX, //Float
   Float:bY,
   Float:bZ
}
new bizlist[50][e_bizlist];
And use "d" as specifier in sscanf for bizid
Thanks, I used enum and now it works.
Gendy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
NPC floating problem ilijap Scripting Help 1 07/09/2017 07:45 PM
Arrays problem Equuuuin0X Scripting Help 17 01/03/2014 11:06 PM
Problem with Arrays Shoulen Scripting Help 3 14/04/2013 05:37 PM
Invalid Floating Point Operation (Please help! Desperate) Klid Client Support 2 22/11/2009 10:55 AM
sa:mp "invalid floating point operation" need help pls lucky32 Client Support 23 15/02/2009 07:52 PM


All times are GMT. The time now is 05:34 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.