MoveDynamicObject strange bug
#1

Hello SA-MPers

I recently discovered something strange happening with moving dynamic objects. When I try to move a dynamic object, it just floats away and dissapears after a few seconds. I cannot find anything wrong with my code, I even had someone else doublecheck it for me. Searching ****** and the forum had no results. My code is this. All the coordinates are correct.

Код:
if(sMap[id][MAP_OBJECT_DB][ide] == m_objid)
{
	if(sMoves[i][MOVE_CURPOS] == 0)
	{
		new Float:opos[3], m_debug[128];
	 	GetDynamicObjectPos(sMap[id][MAP_OBJECT_ID][ide],opos[0],opos[1],opos[2]);
		format(m_debug,sizeof(m_debug),"FROM %f, %f, %f",opos[0],opos[1],opos[2]);
      	SendClientMessageToAll(-1,m_debug);
       	format(m_debug,sizeof(m_debug),"TO %f, %f, %f",sMoves[i][MOVE_NEWPOS][0], sMoves[i][MOVE_NEWPOS][1], sMoves[i][MOVE_NEWPOS][2]);
    	SendClientMessageToAll(-1,m_debug);
		sMoves[i][MOVE_CURPOS] = 1;
		if(sMoves[i][MOVE_NEWPOS][3] == 0.0 && sMoves[i][MOVE_NEWPOS][4] == 0.0 && sMoves[i][MOVE_NEWPOS][5] == 0.0) SendClientMessageToAll(-1,"No rotation"), MoveDynamicObject(sMap[id][MAP_OBJECT_ID][ide], sMoves[i][MOVE_NEWPOS][0], sMoves[i][MOVE_NEWPOS][1], sMoves[i][MOVE_NEWPOS][2],sMoves[i][MOVESPEED]);
		else MoveDynamicObject(sMap[id][MAP_OBJECT_ID][ide], sMoves[i][MOVE_NEWPOS][0], sMoves[i][MOVE_NEWPOS][1], sMoves[i][MOVE_NEWPOS][2],sMoves[i][MOVESPEED],sMoves[i][MOVE_NEWPOS][3],sMoves[i][MOVE_NEWPOS][4],sMoves[i][MOVE_NEWPOS][5]);
	}
	else
	{
		sMoves[i][MOVE_CURPOS] = 0;

		if(sMoves[i][MOVE_OLDPOS][3] == 0.0 && sMoves[i][MOVE_OLDPOS][4] == 0.0 && sMoves[i][MOVE_OLDPOS][5] == 0.0) MoveDynamicObject(sMap[id][MAP_OBJECT_ID][ide], sMoves[i][MOVE_OLDPOS][0], sMoves[i][MOVE_OLDPOS][1], sMoves[i][MOVE_OLDPOS][2],sMoves[i][MOVESPEED]);
		else MoveDynamicObject(sMap[id][MAP_OBJECT_ID][ide], sMoves[i][MOVE_OLDPOS][0], sMoves[i][MOVE_OLDPOS][1], sMoves[i][MOVE_OLDPOS][2],sMoves[i][MOVESPEED],sMoves[i][MOVE_OLDPOS][3],sMoves[i][MOVE_OLDPOS][4],sMoves[i][MOVE_OLDPOS][5]);
	}
	return 1;
}
Notice the debug text shown in the picture. Some very strange coordinates show up.



Has anyone seen this before? How do I fix this? Helpful comments are rewarded with reps.
Reply
#2

Well the only thing I can really see is your 'if' 'else' statements.

pawn Код:
new var = 1; //Variable is set to 1
if(var == 1) //Variable is equal to 1, so this is called.
{
    var = 0; //Variable is set to 0
}
else //Variable is no longer set to 1, so this is called.
{
    var = 1; //Variable is set to 1
}
//Variable is now it's original value, 1.
This is a common mistake which can easily be fixed by using 'else if' rather than 'else'. Or another alternative is this:
pawn Код:
if(sMap[id][MAP_OBJECT_DB][ide] == m_objid)
{
    if(!sMoves[i][MOVE_CURPOS])
    {
        new Float:opos[3], m_debug[128];
        GetDynamicObjectPos(sMap[id][MAP_OBJECT_ID][ide], opos[0], opos[1], opos[2]);
        format(m_debug, sizeof(m_debug), "FROM %f, %f, %f", opos[0], opos[1], opos[2]);
        SendClientMessageToAll(-1, m_debug);
        format(m_debug, sizeof(m_debug), "TO %f, %f, %f", sMoves[i][MOVE_NEWPOS][0], sMoves[i][MOVE_NEWPOS][1], sMoves[i][MOVE_NEWPOS][2]);
        SendClientMessageToAll(-1, m_debug);
        if(sMoves[i][MOVE_NEWPOS][3] == 0.0 && sMoves[i][MOVE_NEWPOS][4] == 0.0 && sMoves[i][MOVE_NEWPOS][5] == 0.0) SendClientMessageToAll(-1, "No rotation");
        MoveDynamicObject(sMap[id][MAP_OBJECT_ID][ide], sMoves[i][MOVE_NEWPOS][0], sMoves[i][MOVE_NEWPOS][1], sMoves[i][MOVE_NEWPOS][2], sMoves[i][MOVESPEED], sMoves[i][MOVE_NEWPOS][3], sMoves[i][MOVE_NEWPOS][4], sMoves[i][MOVE_NEWPOS][5]);
    }
    else MoveDynamicObject(sMap[id][MAP_OBJECT_ID][ide], sMoves[i][MOVE_OLDPOS][0], sMoves[i][MOVE_OLDPOS][1], sMoves[i][MOVE_OLDPOS][2], sMoves[i][MOVESPEED], sMoves[i][MOVE_OLDPOS][3], sMoves[i][MOVE_OLDPOS][4], sMoves[i][MOVE_OLDPOS][5]);
    sMoves[i][MOVE_CURPOS] = (sMoves[i][MOVE_CURPOS]) ? (0) : (1);
    return 1;
}
See if this changes anything.
Reply
#3

It did not fix my issue unfortunately, however thanks for sharing this method, it looks a lot easier than what I used to do.

EDIT:
So I found what was causing it. I forgot to add the 'Float:' tag to the variable. :$
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)