SA-MP Forums Archive
Float positive and negative calculation isn't working - 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: Float positive and negative calculation isn't working (/showthread.php?tid=642710)



Float positive and negative calculation isn't working - Meller - 05.10.2017

So basically, I'm trying to create a random generation of "tiles", but I can't calculate out the X and Y position from 0.0, 0.0 by using negative numbers but I can succeed with doing it with positive numbers.

As seen here; tile 4 is supposed to be on the corner of tile 1, west-south, not north-east.


Here's how their deployment is;
PHP код:
    public OnGameModeInit() {
        
CreateTile(TILE_TYPE_GRASS, 0, 0);
        
CreateTile(TILE_TYPE_GRASS, 1, 0);
        
CreateTile(TILE_TYPE_GRASS, 0, 1);
        
CreateTile(TILE_TYPE_GRASS, -1, -1);
        return 
1;
    } 
And the function is as following;
PHP код:
stock CreateTile(type, x, y) {
    new 
id = CreateObject(TILE_MODEL_ID, (x >= 0)?(x*125):(x*(-125)), (y >= 0)?(y*125):(y*(-125)), 30.0, 0, 0, 0);
    new 
string[144];
    
format(string, sizeof string, "Tile: %i\nPosition: %i - %i", id, (x >= 0)?(x*125):(x*(-125)), (y >= 0)?(y*125):(y*(-125)));
    
Create3DTextLabel(string, 0x1CC4FCFF, (x >= 0)?(x*125):(x*(-125)), (y >= 0)?(y*125):(y*(-125)), 30.0, 1000.0, 0, 0);
    switch(
type) {
        case 
TILE_TYPE_GRASS: {
            
SetObjectMaterial(id, 0, 9495, "vict_sfw", "Grass", 0);
            for(new 
Float:gYY = -62.5; gYY < 62.5; gYY += (float(random(50)+1)*0.1)+1)
                for(new 
Float:gX = -62.5, Float:gY = float(random(50)+1)*0.1; gX < 62.5; gX += (float(random(50)+1)*0.1)+1, gY = float(random(50)+1)*0.1)
                    
CreateDynamicObject(TILE_OBJECT_GRASS, ((x >= 0)?(x*125):(x*(-125)))+gX, (((y >= 0)?(y*125):(y*(-125)))+gY)-gYY, 30, 0, 0, 0);
        }
    }
    
staticTiles[id][staticTile_ID] =     id;
    
staticTiles[id][staticTile_Type] =     type;
} 
Any ideas of what I'm doing wrong?


https://*********/j-81qEOxk6E


Re: Float positive and negative calculation isn't working - jlalt - 05.10.2017

-1Ч(-1)=+1
-1Ч1=-1

So your above calculations are always positive. You don't need to check if value of x and y is negative or positive.
Just keep them as they are with Ч125.


Re: Float positive and negative calculation isn't working - Meller - 05.10.2017

Quote:
Originally Posted by jlalt
Посмотреть сообщение
-1Ч(-1)=+1
-1Ч1=-1

So your above calculations are always positive. You don't need to check if value of x and y is negative or positive.
Just keep them as they are with Ч125.
Ahh yes! I should've paid more attention to school I guess, meh, thanks, pal.