[HELP]Objects problem[HELP]!!!
#1

Well, how can I say it, but in my whole SAMP history, I have never worked with objects :O(so fkin true and sad).And now, that I wanted to try work with objects, I badly failed, help is appreciated.What I want is to create 2 missiles(wich move), and when they encounter an object, they explode.So far so good...Here's a function made by me, IsObjectInRangeOfPoint, wich works exactly like IsPlayerInRangeOfPoint:
pawn Код:
stock IsObjectInRangeOfPoint(objectid, Float:radius, Float:X, Float:Y, Float:Z)
{
    new Float:px,Float:py,Float:pz;
    GetObjectPos(objectid,px,py,pz);
    return ( ( ((px-X)*(px-X))+((py-Y)*(py-Y))+((pz-Z)*(pz-Z)) ) >= radius*radius );
}
Good, now here comes the test code, made with a command:
pawn Код:
forward MoveMissile();
new MissileTimer;
new rMissile,lMissile;//the objects
COMMAND:testmissile(playerid,params[])
{
    new Float:vX,Float:vY,Float:vZ
    GetPlayerPos(playerid,vX,vY,vZ);
    rMissile=CreateObject(345,vX,vY+2,vZ,0,0,0,100.0);//creating the objects
    lMissile=CreateObject(345,vX,vY-2,vZ,0,0,0,100.0);
    MissileTimer=SetTimer("MoveMissile",1000,true);//setting a timer that will move the object
 return 1;
}
public MoveMissile()
{
   if(!IsValidObject(lMissile)&&!IsValidObject(rMissile)) KillTimer(MissileTimer);//if none of the missiles exist anymore we kill the timer
   else
   {
               //HERE i move the missiles forward
        new Float:lX,Float:lY,Float:lZ;
        new Float:rX,Float:rY,Float:rZ;
        GetObjectPos(lMissile,lX,lY,lZ);
        MoveObject(lMissile,lX+3,lY+3,lZ,3.0);
        GetObjectPos(rMissile,rX,rY,rZ);
        MoveObject(rMissile,rX+3,rY+3,rZ,3.0);
        for(new i=0;i<MAX_OBJECTS;i++)
        {
                        //i check if any of the missiles hit a buidling,etc.
            new Float:x,Float:y,Float:z;
            GetObjectPos(i,x,y,z);
            if(IsObjectInRangeOfPoint(lMissile,0.2,x,y,z))
            {
                GetObjectPos(lMissile,lX,lY,lZ);
                DestroyObject(lMissile);
                CreateExplosion(lX,lY,lZ,2,5.0);
            }
            if(IsObjectInRangeOfPoint(rMissile,0.2,x,y,z))
            {
                GetObjectPos(rMissile,rX,rY,rZ);
                DestroyObject(rMissile);
                CreateExplosion(rX,rY,rZ,2,5.0);
            }
                       //if yes, the missile is destroyed, and a huge explosion occures
       }
    }
    return 1;
}
The problem is, that even if the command works, and the object are created, and they are created correctly(on my sides), they don't move, but they explode near me, and the SAMP chat returns me this message(red colored):
Код:
ERROR:There's nothing to end..
HELP is appreciated, thanks in advance.
Reply
#2

I think the problem is in your stock function. IsObjectInRangeOfPoint should be returning either true or false (1 or 0), probably why you're receiving the 'nothing to end...' error, because you're returning something with no proper value.
Reply
#3

Okay, I remade the function, following the slower example of "PlayerToPoint", and here's the new function:
pawn Код:
stock IsObjectInRangeOfPoint(objectid, Float:radi, Float:x, Float:y, Float:z)
{
    new Float:oldposx, Float:oldposy, Float:oldposz;
    new Float:tempposx, Float:tempposy, Float:tempposz;
    GetObjectPos(objectid, oldposx, oldposy, oldposz);
    tempposx = (oldposx -x); tempposy = (oldposy -y); tempposz = (oldposz -z);
    if(((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
    { return true; }
    return false;
}
And it gives me the same in-game error, even if the missiles are created correctly(on my right side, and my left side), they won't move forward, but they will explode near me...And the SAMP chat reutnrs me the client message(YES, not a warning, BUT client message):"ERROR:There's nothing to end.."(red colored).BTW, I have remade the timer also:
pawn Код:
public MoveMissile()
{
   if(!IsValidObject(lMissile)&&!IsValidObject(rMissile)) KillTimer(MissileTimer);
   else
   {
       if(IsValidObject(lMissile))
       {
        new Float:lX,Float:lY,Float:lZ;
        GetObjectPos(lMissile,lX,lY,lZ);
        MoveObject(lMissile,lX+3,lY+3,lZ,3.0);
        for(new i=0;i<MAX_OBJECTS;i++)
        {
            new Float:x,Float:y,Float:z;
            GetObjectPos(i,x,y,z);
            if(IsObjectInRangeOfPoint(lMissile,0.2,x,y,z))
            {
                GetObjectPos(lMissile,lX,lY,lZ);
                DestroyObject(lMissile);
                CreateExplosion(lX,lY,lZ,2,5.0);
                break;
            }
         }
       }
       if(IsValidObject(rMissile))
       {
        new Float:rX,Float:rY,Float:rZ;
        GetObjectPos(rMissile,rX,rY,rZ);
        MoveObject(rMissile,rX+3,rY+3,rZ,3.0);
        for(new i=0;i<MAX_OBJECTS;i++)
        {
            new Float:x,Float:y,Float:z;
            GetObjectPos(i,x,y,z);
            if(IsObjectInRangeOfPoint(rMissile,0.2,x,y,z))
            {
                GetObjectPos(rMissile,rX,rY,rZ);
                DestroyObject(rMissile);
                CreateExplosion(rX,rY,rZ,2,5.0);
                break;
            }
       }
     }
    }
    return 1;
}
And, it won't work, the missiles won't move, but explode near-by me...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)