GetNearestDynObject - doing the opposite
#10

the initial currentobject=-1, then the distance to the first encountered object gets estimated. this triggers the first if-statement, and assigns the first distance. clever, if you ask me, but i prefer my solution, which assumes that all "close" objects should start at like 6000.0 units
ok, heres the real deal: i played around with mapicons, and created some 1337 objects (only 4 to 7), due to the mapicon limit. dont use it on more than 30 objects..
for me, walking around some trashcans, the checkpoints showed up like a snake on those, and the gametext told me the object id. since i started with 0 objects loaded, it was easy to check if the ids matched. they did.
oh, heres some additional code. i was too lazy to write a timer, and included your snippet into my object editor:
pawn Код:
forward OnPlayerUpdate(playerid);public OnPlayerUpdate(playerid){
    new no=GetNearestDynObject(playerid);
    new string1[64];
    format(string1,sizeof(string1),"no:%d",no);
    GameTextForPlayer(playerid,string1,100,5);
and heres your snippet, slightly modified again:
pawn Код:
stock GetNearestDynObject(playerid)
{
    new
        Float:px,
        Float:py,
        Float:pz,
        currentobject = -1,
        Float:distance = 10.0,
        Float:ox,
        Float:oy,
        Float:oz,
        Float:odist;
    GetPlayerPos( playerid, px, py, pz );
    for( new index = 0; index < CountDynamicObjects(); index++ )
    {
        //if ( !IsValidDynamicObject( index ) ) continue;
        GetDynamicObjectPos( index, ox, oy, oz );
        odist = floatsqroot(
        floatpower( floatsub( ox, px ), 2.0 ) +
        floatpower( floatsub( oy, py ), 2.0 ) +
        floatpower( floatsub( oz, pz ), 2.0 )
        );
        if ( odist < distance )
        {
            currentobject = index;
            distance = odist;
            SetPlayerMapIcon(playerid,index,ox,oy,oz,00,0xaa55ff55,3);
        }
    }
    return currentobject;
}
Reply


Messages In This Thread
GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 21:24
Re: GetNearestDynObject - doing the opposite - by Babul - 17.02.2013, 21:52
Re: GetNearestDynObject - doing the opposite - by Stylock - 17.02.2013, 22:01
Re: GetNearestDynObject - doing the opposite - by [MG]Dimi - 17.02.2013, 22:10
Re: GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 22:13
Re: GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 22:18
Re: GetNearestDynObject - doing the opposite - by [MG]Dimi - 17.02.2013, 22:19
Re: GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 22:20
Re: GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 22:32
Re: GetNearestDynObject - doing the opposite - by Babul - 17.02.2013, 22:43

Forum Jump:


Users browsing this thread: 3 Guest(s)