SetTimerEx for objects
#1

hi..
I made a timer which is constantly checking if a player is in range of several points...
those points are points of gates which should auto-open and auto-close..
the opening is no problem though...

For the close I wanted to do some kind of "SetTimerEx" and use "objectid" instead of "playerid"...
it doesn't work -.-

Here is what I got, maybe you can fix it or can tell me how to

Код:
forward moveback(objectid);
forward gatecheck(objectid);

public gatecheck(objectid)
{
	for(new i=0; i<MAX_PLAYERS; i++){
	    if(IsPlayerConnected(i)){
	        if(IsPlayerInRangeOfPoint(i, 8.0,1550.27575684,-1698.06298828,27.36819077) ||                                    IsPlayerInRangeOfPoint(i, 8.0,1544.19995117,-1630.96655273,12.38281250)){
	            if(IsPlayerInRangeOfPoint(i, 8.0, 1550.27575684,-1698.06298828,27.36819077)){
	                if(PlayerFaction[i][police] == 1){
	                    if(ObjectData[lspdg1][down] == 0){
			                MoveObject(lspdg1, 1550.27539062,-1698.06250000,12.61819077, 1.00);
			                SetTimerEx("moveback", 5000, false, "i", objectid);
			                ObjectData[lspdg1][down] = 1;
						}
					}
				}
				if(IsPlayerInRangeOfPoint(i, 8.0, 1544.19995117,-1630.96655273,12.38281250)){
				    if(PlayerFaction[i][police] == 1){
				         if(ObjectData[lspdg2][down] == 0){
			                MoveObject(lspdg2,1544.17443848,-1623.71582031,12.38281250, 2.00);
			                SetTimerEx("moveback", 5000, false, "i", objectid);
			                ObjectData[lspdg2][down] = 1;
						}
					}
       			}
			}
		}
	}
	return 1;
}

public moveback(objectid)
{
	if(objectid == lspdg1){
	    ObjectData[lspdg1][down] = 0;
	    MoveObject(lspdg1,1550.27575684,-1698.06298828,27.36819077, 1.00);
	}else if(objectid == lspdg2){
	    ObjectData[lspdg2][down] = 0;
	    MoveObject(lspdg2,1544.19995117,-1630.96655273,12.38281250, 2.00);
	}
	return 1;
}
Reply
#2

The gate isn't closing because the old timer is still checking if the user is within range of the gate and re-opening it constantly.
Reply
#3

no... it doesn't close, too when I'm already out of the range... also you can see:
ObjectData[lspdg2][down].... if it is moved down it is set to 1 so it won't be moved until it is reopened...
Reply
#4

Maybe because the variable objectid is empty ?

and why does gatecheck even have a parameter?

Your problem was that you put objectid in SetTimerEx but in objectid was nothing saved
So you only need to put lspdg1 / lspdg2 instead of objectid in there

And here your code reworked since you checked for the area twice
pawn Код:
forward gatecheck();
public gatecheck()
{
    for(new i; i != MAX_PLAYERS; i++) {
        if(!IsPlayerConnected(i)) continue;
        else if(PlayerFaction[i][police] == 1) {
            if(ObjectData[lspdg1][down] == 0) {
                if(IsPlayerInRangeOfPoint(i, 8.0, 1550.27575684, -1698.06298828, 27.36819077)) {
                    ObjectData[lspdg1][down] = true;
                    SetTimerEx("moveback",
                        MoveObject(lspdg1, 1550.27539062, -1698.06250000, 12.61819077, 1.00) + 2000,
                        false, "i", lspdg1);
                    continue;
                }
            }
            if(ObjectData[lspdg2][down] == 0) {
                if(IsPlayerInRangeOfPoint(i, 8.0, 1544.19995117, -1630.96655273, 12.38281250)) {
                    ObjectData[lspdg2][down] = true;
                    SetTimerEx("moveback",
                        MoveObject(lspdg2, 1544.17443848, -1623.71582031, 12.38281250, 2.00) + 2000,
                        false, "i", lspdg2);
                    continue;
                }
            }
        }
    }
}
And to the question why MoveObject is in SetTimerEx, MoveObject returns the time it will take for the object to move in milliseconds plus 2 seconds to stay opend
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)