SA-MP Forums Archive
Is this possible - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Is this possible (/showthread.php?tid=363711)



Is this possible - Rudy_ - 28.07.2012

Hi Guys.
I have a Working script when you press LMB an object get's created - then moves and then get's destroyed.
What i need is how can i detect if "The object is moving and there's a vehicle/player near him?


Re: Is this possible - Dolby - 28.07.2012

You can get the Object/Vehicle position and check with IsPlayerInRangeOfPoint + Loop if have a player near the object.


Re: Is this possible - Rudy_ - 28.07.2012

Hm..
Can you give me example?
Код:
IsPlayerInRangeOfPoint
on a timer
checking missile positions and player positions
and vehicle positiosn



Re: Is this possible - Rudy_ - 28.07.2012

This is what i tried so far
pawn Код:
new targetid,
                Float:x,
                Float:y,
                Float:z
                                                   Float:tx,
                                                   Float:ty
                                                   Float:tz;

            GetObjectPos(gRocketObj[i], x, y, z);// Get the position of the object
            if(IsPlayerInRangeOfPoint(playerid, tx, ty, tz); //Pos of Target
            {  
                CreateExplosion(x, y, z, 11, 2.50);      // Create an explosion at this position
                DestroyObject(gRocketObj[i]); // Destroy the object
            }



Re: Is this possible - Baboon - 28.07.2012

xD, sounds like you want to do the same thing like me and twixx xD?
Well what you can do is, run a timer, get the object position in that timer and use IsPlayerInRangeOfPoint in a loop to detect who is near the object.
Unless there is a function IsVehicleInRangeOfPoint, it is pretty easily creatable by creating a stock (you will have to use some pythagoras then)


Re: Is this possible - Rudy_ - 28.07.2012

No no i'm not creating any ships canons etc..
It's some another, Oh and thanks i'll try your method.
PS: updated my code.


Re: Is this possible - Baboon - 28.07.2012

Well I wasn't actually talking about the cannons, but certain attacks :P, but about that piece of code.
You are doing IsPlayerInRangeOfPoint and use the coordinates or tx, ty and tz. I suppose those are the targetcoordinats. But you are making a mistake over here. You are checking whether a player is near the objectcoordinates. So you should use x, y and z instead.

Edit: this if statement shouldn't be closed like: if(..........; like you did.
the right way: if(IsPlayerInRangeOfPoint(playerid, range, x, y, z))

Edit 2: I also see you forgot to add the range.


Re: Is this possible - Rudy_ - 28.07.2012

Oh Right
pawn Код:
public OnObjectMoved(objectid)
{
    for(new i;i<MAX_PLAYERS;i++)                    // Loop through players
    {
        if(objectid == gRocketObj[i])               // If this object is one of those player objects
        {
            new targetid,
                Float:x,
                Float:y,
                Float:z;

            GetObjectPos(gRocketObj[i], x, y, z);
            if(IsPlayerInRangeOfPoint(targetid,3.0, x, y, z)); // Get the position of the object
            {  
                CreateExplosion(x, y, z, 11, 2.50);      // Create an explosion at this position
                DestroyObject(gRocketObj[i]); // Destroy the object
            }          
        }
    }
}

Код:
C:\Users\Warkadang\Desktop\Scripting\Scripting\filterscripts\Test.pwn(54) : error 036: empty statement
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Can't seem to fix it
PS: will it work?


Re: Is this possible - Baboon - 28.07.2012

View mistakes. OnObjectMoved gets called when An object has finished with moving. USe a timer instead. Targetid is 0, because you juist created IT. Remove targetid, use i instead, cus you looped through the players (i). and that if statement, dont do ;.


Re: Is this possible - FireCat - 28.07.2012

IsObjectMoving and a loop