10.09.2012, 09:16
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:
Good, now here comes the test code, made with a command:
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):
HELP is appreciated, thanks in advance.
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 );
}
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;
}
Код:
ERROR:There's nothing to end..