FOnline Development > Share Your Work

Little sample of coding mistakes.

(1/1)

adumbperson:
Hello,

I wanted to show you galz and guyz, some error that I found while reading the many fonline sdk's that I've.

I wont say to which sdk the code belong... This post is done to help people write better code while implementing their dreams.


--- Code: ---    uint16 centerhexX = 0;
    uint16 centerhexY = 0;
    if( valid( chosen ) && valid( target ) && !target.IsDead() && !target.IsChosen() )
    {
        centerhexX = target.HexX;
        centerhexY = target.HexY;
    }
    for( int i = 0; i < 6; i++ )
    {
        targethexX = centerhexX;
        targethexY = centerhexY;
        MoveHexByDir( targethexX, targethexY, i, radius );
        if( !GetHexPos( targethexX, targethexY,  drawx,    drawy  ) )
            return;
        coordsX[ i ] = drawx;
        coordsY[ i ] = drawy;
    }
    uint j;
    for( uint i = 0; i < 6; i++ )
    {
        j = i + 1;
        if( j > 5 )
            j = 0;
        int[] coords = { coordsX[ i ], coordsY[ i ], int(COLOR_RED), coordsX[ j ], coordsY[ j ], int(COLOR_RED) };
        DrawPrimitive( DRAW_PRIMITIVE_LINESTRIP, coords );
    }
--- End code ---

This statement is wrong way to proceed...

--- Code: ---    uint16 centerhexX = 0;
    uint16 centerhexY = 0;
    if( valid( chosen ) && valid( target ) && !target.IsDead() && !target.IsChosen() )
    {
        centerhexX = target.HexX;
        centerhexY = target.HexY;
    }
--- End code ---

If there is an invalid pointer or/and that target is dead or/and target is chosen
centerhexX/Y wont be set to the right hexes... AND THE CODE STILL CONTINUE PROCESSING...

Hope this help.

Wipe:
What you skipped is probably important.

If that's the same server i'm looking at, this is DrawDmgRadius() which contains

--- Code: ---    if( !GetMonitorHex( __MouseX, __MouseY, centerhexX, centerhexY ) )
        return;

--- End code ---
called some lines before part you pasted.


--- Quote from: adumbperson on May 25, 2019, 03:52:35 am ---If there is an invalid pointer or/and that target is dead or/and target is chosen
centerhexX/Y wont be set to the right hexes... AND THE CODE STILL CONTINUE PROCESSING...

--- End quote ---
Isn't it exactly how it should be?

Take VC turret made as Critter as example:
If your cursor is over its "head", and you attack it, Client will change attack position to Critter's hex position, at turret's "feet", which is good few hexes below a cursor.
If your cursor is over its "head", but turret is dead already, nothing changes. You cannot attack dead Critters, so you attack hex under cursor instead - amount of care about rockets/nades/etc. in this function hints that it's connected to hexshooting.

This is a feedback function for players, so they know exactly where their attack, which might include splash damage, will end. It has to be consisted with Client/combat logic or it's worthless.

Just a wild guess, obviously. You didn't mention server name (i wonder why... :7), or any details after all. And it always could be copypaste from one server to another... which, in the end, does different things.

adumbperson:

--- Quote from: Wipe on May 25, 2019, 03:32:35 pm ---What you skipped is probably important.

If that's the same server i'm looking at, this is DrawDmgRadius() which contains

--- Code: ---    if( !GetMonitorHex( __MouseX, __MouseY, centerhexX, centerhexY ) )
        return;

--- End code ---
called some lines before part you pasted.
Isn't it exactly how it should be?

--- End quote ---

And... you are right.
I dunno how the hell i didn't see that call before posting this...
I must have been drunk or something while posting...
SHAME ON ME


--- Quote ---Just a wild guess, obviously. You didn't mention server name (i wonder why... :7), or any details after all. And it always could be copypaste from one server to another... which, in the end, does different things.

--- End quote ---

It is fo2 sdk

Navigation

[0] Message Index

Go to full version