Not moving object
#1

Im making an auto gate but whenever i walk up to the gate it doesnt open..

timers/names
pawn Код:
forward lvpdGatesOpen();
forward lvpdGatesClose();
forward lspdGatesOpen();
forward lspdGatesClose();

new lvpdgate;
new lspdgate;
new lvpdGateOpen = 0;
new lspdGateOpen = 0;
pawn Код:
public OnGameModeInit()
{  
    SetTimer("lvpdGatesOpen",1000,1);
    SetTimer("lspdGatesOpen",1000,1);
   
    lvpdgate = CreateDynamicObject(971, 2334.98, 2443.39, 7.50, 0.00, 0.00, 60.06);
    lspdgate = CreateDynamicObject(971, 1588.98, -1638.15, 14.36, 0.00, 0.00, 179.10);
   
    return 1;
}

LVPD gate
pawn Код:
public lvpdGatesOpen()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(PlayerToPoint(10.0, i, 2334.98, 2443.39, 7.50) && lvpdGateOpen == 0)
        {
            //if(gTeam[i] == TEAM_NOOBS)
            {
                MoveObject(lvpdgate, 2334.98, 2443.39, 1.00, 5);
                lvpdGateOpen =1;
                SetTimer("lvpdGatesClose",7000,0);
        }
        }
    }
}

public lvpdGatesClose()
{
     MoveObject(lvpdgate, 2334.98, 2443.39, 7.50, 5);
     lvpdGateOpen =0;
}
LSPD gate
pawn Код:
public lspdGatesOpen()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(PlayerToPoint(10.0, i, 1588.98, -1638.15, 14.36) && lspdGateOpen == 0)
        {
            //if(gTeam[i] == TEAM_NOOBS)
            {
                MoveObject(lspdgate, 1588.98, -1638.15, 8.36, 5);
                lspdGateOpen =1;
                SetTimer("lspdGatesClose",7000,0);
        }
        }
    }
}

public lspdGatesClose()
{
     MoveObject(lspdgate, 1588.98, -1638.15, 14.36, 5);
     lspdGateOpen =0;
}
pawn Код:
PlayerToPoint(Float:radius, playerid, Float:X, Float:Y, Float:Z)
{
    new Float:oldpos[3], Float:temppos[3];
    GetPlayerPos(playerid, oldpos[0], oldpos[1], oldpos[2]);
    temppos[0] = (oldpos[0] -X);
    temppos[1] = (oldpos[1] -Y);
    temppos[2] = (oldpos[2] -Z);
    if(((temppos[0] < radius) && (temppos[0] > -radius)) && ((temppos[1] < radius) && (temppos[1] > -radius)) && ((temppos[2] < radius) && (temppos[2] > -radius)))
    {
        return true;
    }
    return false;
}
Reply
#2

First of all use IsPlayerInRangeOfPoint instead of PlayerToPoint. It's a native (default) function and is a lot more efficient.

Secondly, you have brackets messed up after //if(gTeam[i] == TEAM_NOOBS). Un-comment that line.

Debug your code with print() to see what is getting called. Also, what is the point in the timers under OnGameModeInit? Just create them open?
Reply
#3

Why are you using so many timers for the same thing :/ Also, you aren't moving the objects anywhere.

Look:

Код:
PlayerToPoint(10.0, i, 1588.98, -1638.15, 14.36) //You check if the player is near here
MoveObject(lspdgate, 1588.98, -1638.15, 8.36, 5);//You move the object to the exact same x,y,z pos..
Edited code:

pawn Код:
forward GatesOpen();
forward MoveObjectEx(objectid, Float:xpos, Float:ypos, Float:zpos, Float:_Speed, Float:xRot=-1000.0, Float:yRot=-1000.0, Float:zRot=-1000.0);

new Gates[2];
new lvpdGateOpen = 0;
new lspdGateOpen = 0;

public OnGameModeInit()
{
    SetTimer("GatesOpen", 1000, true);
   
    Gates[0] = CreateDynamicObject(971, 2334.98, 2443.39, 7.50, 0.00, 0.00, 60.06);
    Gates[1] = CreateDynamicObject(971, 1588.98, -1638.15, 14.36, 0.00, 0.00, 179.10);
    return 1;
}

public GatesOpen()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerInRangeOfPoint(i, 10.0, 2334.98, 2443.39, 7.50) && lvpdGateOpen == 0)
        {
            MoveObject(lvpdgate, 2334.98 - 10, 2443.39, 1.00, 5);
            lvpdGateOpen = 1;
            SetTimerEx("MoveObjectEx", 7000, false, "iiffff", 0, Gates[0], 2334.98, 2443.39, 1.00);
        }
        else if(IsPlayerInRangeOfPoint(i, 10.0, 1588.98, -1638.15, 14.36) && lspdGateOpen == 0)
        {
            MoveObject(lspdgate, 1588.98 - 10, -1638.15, 8.36, 5);
            lspdGateOpen = 1;
            SetTimerEx("MoveObjectEx", 7000, false, "iiffff", 1, Gates[1], 1588.98, -1638.15, 8.36);
        }
    }
}

public MoveObjectEx(type, objectid, Float:xpos, Float:ypos, Float:zpos, Float:_Speed, Float:xRot=-1000.0, Float:yRot=-1000.0, Float:zRot=-1000.0)
{
     MoveObject(objectid, xpos, ypos, zpos, _Speed, xRot, yRot, zRot);
     if(type == 0) lvpdGateOpen = 0;
     else if(type == 1) lspdGateOpen = 0;
}
Obviously the move position is approximate.
Reply
#4

pawn Код:
(13) : error 059: function argument may not have a default value (variable "xRot")
(144) : error 025: function heading differs from prototype
pawn Код:
forward MoveObjectEx(objectid, Float:xpos, Float:ypos, Float:zpos, Float:_Speed, Float:xRot=-1000.0, Float:yRot=-1000.0, Float:zRot=-1000.0);

public MoveObjectEx(type, objectid, Float:xpos, Float:ypos, Float:zpos, Float:_Speed, Float:xRot=-1000.0, Float:yRot=-1000.0, Float:zRot=-1000.0)
Reply
#5

Just delete lvpdGatesOpen all together, it's completely un-necessary.
Reply
#6

Quote:
Originally Posted by MP2
Посмотреть сообщение
Just delete lvpdGatesOpen all together, it's completely un-necessary.
That was supposed to be for the gate closing auto but im not getting how to do that part.,
Reply
#7

No, you have two timers, one for opening and one for closing. You only need one for closing.
Reply
#8

Okay but i changed my code to coole210's. Any idea with errors?
Reply
#9

Show the updated code and errors (and comment on which lines the errors are on).
Reply
#10

Its up there but:

pawn Код:
(13) : error 059: function argument may not have a default value (variable "xRot")
(144) : error 025: function heading differs from prototype
pawn Код:
forward MoveObjectEx(objectid, Float:xpos, Float:ypos, Float:zpos, Float:_Speed, Float:xRot=-1000.0, Float:yRot=-1000.0, Float:zRot=-1000.0);

public MoveObjectEx(type, objectid, Float:xpos, Float:ypos, Float:zpos, Float:_Speed, Float:xRot=-1000.0, Float:yRot=-1000.0, Float:zRot=-1000.0)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)