MoveObject
#1

I have a problem with my script.


pawn Код:
#include <a_samp>

forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
forward SharkDetect();

new Shark;

public OnFilterScriptInit()
{
    Shark = CreateObject(1608, 757.7714, -1996.8455, -0.3859, 0, 0, 0, 300);
    SetTimer("SharkDetect", 1001, true);
   
    return 1;
}

public OnFilterScriptExit()
{
    DestroyObject(Shark);
    return 1;
}

public SharkDetect()
{

    for(new playerid=0; playerid<MAX_PLAYERS; playerid++)
    {
           if(PlayerToPoint(40.0, playerid, 757.7714, -1996.8455, -0.3859))
           {
                 new Float:angle;
                 new Float:X,Y,Z;
                 GetPlayerFacingAngle(playerid, Float:angle);
                 GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
                 MoveObject(Shark, Float:X, Float:Y, Float:Z, 4.0, -1000.0, -1000.0, Float:angle);
           }
           
    }
    return 1;
}

public OnObjectMoved(objectid)
{
    for(new playerid=0; playerid<MAX_PLAYERS; playerid++)
    {
          if(PlayerToPoint(5.0, playerid, 757.7714, -1996.8455, -0.3859))
          {
                 StopObject(Shark);
          }
    }
    MoveObject(Shark, 757.7714, -1996.8455, -0.3859, 4.0);
    return 1;
}

public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
    if(IsPlayerInRangeOfPoint(playerid, radi, x, y, z)) {
        return 1;
    }
    return 0;
}
Basicly that's the whole script. The problem can be seen in video. When the shark reaches the player, he wants to move back to the old position even if the player is not out of the 40.0 range. What I'm trying to do here is to make the shark stop near the player if the player is in the 40.0 range, and return to its original position if the player is not in the 40.0 range

[ame]http://www.youtube.com/watch?v=puJpAnKNf7E[/ame]

Also, when the shark reached the player, remove 20 hp from him.
Reply
#2

pawn Код:
#include <a_samp>

forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
forward SharkDetect();

new Shark;
new IsMoving;

public OnFilterScriptInit()
{
    Shark = CreateObject(1608, 757.7714, -1996.8455, -0.3859, 0, 0, 0, 300);
    SetTimer("SharkDetect", 1001, true);
   
    return 1;
}

public OnFilterScriptExit()
{
    DestroyObject(Shark);
    return 1;
}

public SharkDetect()
{
    for(new playerid=0; playerid<MAX_PLAYERS; playerid++)
    {
           if(IsMoving == 0)
           {
               if(PlayerToPoint(40.0, playerid, 757.7714, -1996.8455, -0.3859))
               {
                     new Float:angle;
                     new Float:X,Y,Z;
                     GetPlayerFacingAngle(playerid, Float:angle);
                     GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
                     MoveObject(Shark, Float:X, Float:Y, Float:Z, 4.0, -1000.0, -1000.0, Float:angle);
                     IsMoving = 1;
               }
           }
           if(IsMoving == 2)
           {
               if(!PlayerToPoint(40.0, playerid, 757.7714, -1996.8455, -0.3859))
               {
                   MoveObject(Shark,757.7714, -1996.8455, -0.3859,4);
                   IsMoving = 0;
               }
           }
    }
    return 1;
}

public OnObjectMoved(objectid)
{
    if(objectid == Shark && IsMoving == 1)
    {
        for(new i=0;i<MAX_PLAYERS;i++)
        {
            new Float:X,Float:Y,Float:Z;
            GetObjectPos(Shark,X,Y,Z);
            if(IsPlayerInRangeOfPoint(playerid,5,X,Y,Z);
            {
                new Float:health;
                GetPlayerHealth(i,health);
                SetPlayerHealth(i,health-20);
                IsMoving = 2;
                return 1;
            }
        }
    }
    return 1;
}

public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
    if(IsPlayerInRangeOfPoint(playerid, radi, x, y, z)) {
        return 1;
    }
    return 0;
}
I don't know if this works.
Reply
#3

Quote:
Originally Posted by AeroBlast
Посмотреть сообщение
pawn Код:
#include <a_samp>

forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
forward SharkDetect();

new Shark;
new IsMoving;

public OnFilterScriptInit()
{
    Shark = CreateObject(1608, 757.7714, -1996.8455, -0.3859, 0, 0, 0, 300);
    SetTimer("SharkDetect", 1001, true);
   
    return 1;
}

public OnFilterScriptExit()
{
    DestroyObject(Shark);
    return 1;
}

public SharkDetect()
{
    for(new playerid=0; playerid<MAX_PLAYERS; playerid++)
    {
           if(IsMoving == 0)
           {
               if(PlayerToPoint(40.0, playerid, 757.7714, -1996.8455, -0.3859))
               {
                     new Float:angle;
                     new Float:X,Y,Z;
                     GetPlayerFacingAngle(playerid, Float:angle);
                     GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
                     MoveObject(Shark, Float:X, Float:Y, Float:Z, 4.0, -1000.0, -1000.0, Float:angle);
                     IsMoving = 1;
               }
           }
           if(IsMoving == 2)
           {
               if(!PlayerToPoint(40.0, playerid, 757.7714, -1996.8455, -0.3859))
               {
                   MoveObject(Shark,757.7714, -1996.8455, -0.3859,4);
                   IsMoving = 0;
               }
           }
    }
    return 1;
}

public OnObjectMoved(objectid)
{
    if(objectid == Shark && IsMoving == 1)
    {
        for(new i=0;i<MAX_PLAYERS;i++)
        {
            new Float:X,Float:Y,Float:Z;
            GetObjectPos(Shark,X,Y,Z);
            if(IsPlayerInRangeOfPoint(playerid,5,X,Y,Z);
            {
                new Float:health;
                GetPlayerHealth(i,health);
                SetPlayerHealth(i,health-20);
                IsMoving = 2;
                return 1;
            }
        }
    }
    return 1;
}

public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
    if(IsPlayerInRangeOfPoint(playerid, radi, x, y, z)) {
        return 1;
    }
    return 0;
}
I don't know if this works.
It works but now how it's supposed to do. Here's a video to show you what's not working.

[ame]http://www.youtube.com/watch?v=ERY0OaXhtuo[/ame]

The shark is going to the place where the command was called. (In that case, where the player enters the 40 range) The shark is not following the player anymore and that's the problem. Besides that, the "bite" thing works just fine. If there is any way to make a timer or something so the shark would "bite" every 2 seconds would be even more awesome! Please don't mind the music in the video, I forgot to stop it when I recorded and I didn't know it'll record the music too.
Reply
#4

pawn Код:
#include <a_samp>

forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
forward SharkDetect();
forward BiteDetect();

new Shark;
new IsMoving;

public OnFilterScriptInit()
{
    Shark = CreateObject(1608, 757.7714, -1996.8455, -0.3859, 0, 0, 0, 300);
    SetTimer("SharkDetect", 1001, true);
    SetTimer("BiteDetect",2000,true);
    return 1;
}

public OnFilterScriptExit()
{
    DestroyObject(Shark);
    return 1;
}

public BiteDetect()
{
    for(new playerid=0; playerid<MAX_PLAYERS; playerid++)
    {
        new Float:x,Float:y,Float:z,Float:health;
        GetObjectPos(Shark,x,y,z);
        if(IsPlayerInRangeOfPoint(playerid,5,x,y,z))
        {
            GetPlayerHealth(i,health);
            SetPlayerHealth(i,health-20);
        }
    }
    return 1;
}

public SharkDetect()
{
    for(new playerid=0; playerid<MAX_PLAYERS; playerid++)
    {
           if(IsMoving == 0 || IsMoving == 1)
           {
               if(PlayerToPoint(40.0, playerid, 757.7714, -1996.8455, -0.3859))
               {
                     new Float:angle;
                     new Float:X,Y,Z;
                     GetPlayerFacingAngle(playerid, Float:angle);
                     GetPlayerPos(playerid, Float:X, Float:Y, Float:Z);
                     MoveObject(Shark, Float:X, Float:Y, Float:Z, 4.0, -1000.0, -1000.0, Float:angle);
                     IsMoving = 1;
               }
           }
           if(IsMoving == 2)
           {
               if(!PlayerToPoint(40.0, playerid, 757.7714, -1996.8455, -0.3859))
               {
                   MoveObject(Shark,757.7714, -1996.8455, -0.3859,4);
                   IsMoving = 0;
               }
           }
    }
    return 1;
}

public OnObjectMoved(objectid)
{
    if(objectid == Shark && IsMoving == 1)
    {
        for(new i=0;i<MAX_PLAYERS;i++)
        {
            new Float:X,Float:Y,Float:Z;
            GetObjectPos(Shark,X,Y,Z);
            if(IsPlayerInRangeOfPoint(playerid,5,X,Y,Z);
            {
                IsMoving = 2;
                return 1;
            }
        }
    }
    return 1;
}

public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
    if(IsPlayerInRangeOfPoint(playerid, radi, x, y, z)) {
        return 1;
    }
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)