[Ajuda] Bug Elevador!
#1

Bom o video abaixo mostra o bug do Elevador.

https://www.youtube.com/watch?v=hu61_4iR4Jk

O Codigo espero que me ajudem !
PHP Code:
#include <a_samp>
#define ELEVATOR_SPEED      (5.0)   // Movement speed of the elevator.
#define DOORS_SPEED         (4.0)   // Movement speed of the doors.
#define ELEVATOR_WAIT_TIME  (5000)  // Time in ms that the elevator will wait in each floor before continuing with the queue.
                                    // Be sure to give enough time for doors to open.
#define DIALOG_ID           (874)
// Private:
#define X_DOOR_CLOSED       (1786.627685)
#define X_DOOR_R_OPENED     (1785.027685)
#define X_DOOR_L_OPENED     (1788.227685)
#define GROUND_Z_COORD      (14.511476)
#define ELEVATOR_OFFSET     (0.059523)
/* ------------------
// Constants:
-------------------*/
static FloorNames[21][] =
{
    
"Entrada",
    
"Primeiro Andar",
    
"Segundo Andar",
    
"Terceiro Andar",
    
"Quarto Andar",
    
"Quinto Andar",
    
"Sexto Andar",
    
"Setimo Andar",
    
"Andar 8",
    
"Andar 9",
    
"Andar 10",
    
"Andar 11",
    
"Andar 12",
    
"Andar 13",
    
"Andar 14",
    
"Andar 15",
    
"Andar 16",
    
"Andar 17",
    
"Andar 18",
    
"Andar 19",
    
"Ultimo"
};
static 
Float:FloorZOffsets[21] =
{
    
0.0,        // 0.0,
    
8.5479,     // 8.5479,
    
13.99945,   // 8.5479 + (5.45155 * 1.0),
    
19.45100,   // 8.5479 + (5.45155 * 2.0),
    
24.90255,   // 8.5479 + (5.45155 * 3.0),
    
30.35410,   // 8.5479 + (5.45155 * 4.0),
    
35.80565,   // 8.5479 + (5.45155 * 5.0),
    
41.25720,   // 8.5479 + (5.45155 * 6.0),
    
46.70875,   // 8.5479 + (5.45155 * 7.0),
    
52.16030,   // 8.5479 + (5.45155 * 8.0),
    
57.61185,   // 8.5479 + (5.45155 * 9.0),
    
63.06340,   // 8.5479 + (5.45155 * 10.0),
    
68.51495,   // 8.5479 + (5.45155 * 11.0),
    
73.96650,   // 8.5479 + (5.45155 * 12.0),
    
79.41805,   // 8.5479 + (5.45155 * 13.0),
    
84.86960,   // 8.5479 + (5.45155 * 14.0),
    
90.32115,   // 8.5479 + (5.45155 * 15.0),
    
95.77270,   // 8.5479 + (5.45155 * 16.0),
    
101.22425,  // 8.5479 + (5.45155 * 17.0),
    
106.67580,  // 8.5479 + (5.45155 * 18.0),
    
112.12735   // 8.5479 + (5.45155 * 19.0)
};
/* ------------------
// Variables:
-------------------*/
new Obj_ElevatorObj_ElevatorDoors[2],
    
Obj_FloorDoors[21][2];
new 
Text3D:Label_ElevatorText3D:Label_Floors[21];
#define ELEVATOR_STATE_IDLE     (0)
#define ELEVATOR_STATE_WAITING  (1)
#define ELEVATOR_STATE_MOVING   (2)
new ElevatorState,
    
ElevatorFloor;  // If Idle or Waiting, this is the current floor. If Moving, the floor it's moving to.
#define INVALID_FLOOR           (-1)
new ElevatorQueue[21],      // Floors in queue.
    
FloorRequestedBy[21];   // FloorRequestedBy[floor_id] = playerid; - Points out who requested which floor.
new ElevatorBoostTimer;     // Timer that makes the elevator move faster after players start surfing the object.
/* ------------------
*  Function forwards:
-------------------*/
// Public:
forward CallElevator(playeridfloorid);    // You can use INVALID_PLAYER_ID too.
forward ShowElevatorDialog(playerid);
// Private:
forward Elevator_Initialize();
forward Elevator_Destroy();
forward Elevator_OpenDoors();
forward Elevator_CloseDoors();
forward Floor_OpenDoors(floorid);
forward Floor_CloseDoors(floorid);
forward Elevator_MoveToFloor(floorid);
forward Elevator_Boost(floorid);            // Increases the elevator speed until it reaches 'floorid'.
forward Elevator_TurnToIdle();
forward ReadNextFloorInQueue();
forward RemoveFirstQueueFloor();
forward AddFloorToQueue(floorid);
forward IsFloorInQueue(floorid);
forward ResetElevatorQueue();
forward DidPlayerRequestElevator(playerid);
forward Float:GetElevatorZCoordForFloor(floorid);
forward Float:GetDoorsZCoordForFloor(floorid);
// ------------------------ Callbacks ------------------------
public OnFilterScriptInit()
{
    
ResetElevatorQueue();
    
Elevator_Initialize();
    return 
1;
}
public 
OnFilterScriptExit()
{
    
Elevator_Destroy();
    return 
1;
}
public 
OnObjectMoved(objectid)
{
    new 
Float:xFloat:yFloat:z;
    for(new 
isizeof(Obj_FloorDoors); ++)
    {
        if(
objectid == Obj_FloorDoors[i][0])
        {
            
GetObjectPos(Obj_FloorDoors[i][0], xyz);
            if(
X_DOOR_L_OPENED 0.5)   // Some floor doors have shut, move the elevator to next floor in queue:
            
{
                
Elevator_MoveToFloor(ElevatorQueue[0]);
                
RemoveFirstQueueFloor();
            }
        }
    }
    if(
objectid == Obj_Elevator)   // The elevator reached the specified floor.
    
{
        
KillTimer(ElevatorBoostTimer);  // Kills the timer, in case the elevator reached the floor before boost.
        
FloorRequestedBy[ElevatorFloor] = INVALID_PLAYER_ID;
        
Elevator_OpenDoors();
        
Floor_OpenDoors(ElevatorFloor);
        
GetObjectPos(Obj_Elevatorxyz);
        
Label_Elevator  Create3DTextLabel("Aperte 'F' para ver o dialog"0xFFFFDD1784.9822, -1302.04260.94.001);
        
ElevatorState   ELEVATOR_STATE_WAITING;
        
SetTimer("Elevator_TurnToIdle"ELEVATOR_WAIT_TIME0);
    }
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == DIALOG_ID)
    {
        if(!
response)
            return 
0;
        if(
FloorRequestedBy[listitem] != INVALID_PLAYER_ID || IsFloorInQueue(listitem))
            
GameTextForPlayer(playerid"~r~O piso jб estб na fila"35004);
        else if(
DidPlayerRequestElevator(playerid))
            
GameTextForPlayer(playerid"~r~Vocк jб pediu o elevador"35004);
        else
            
CallElevator(playeridlistitem);
        return 
1;
    }
    return 
0;
}
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(!
IsPlayerInAnyVehicle(playerid) && newkeys KEY_SECONDARY_ATTACK)
    {
        new 
Float:pos[3];
        
GetPlayerPos(playeridpos[0], pos[1], pos[2]);
        if(
pos[1] < -1301.4 && pos[1] > -1303.2417 && pos[0] < 1786.2131 && pos[0] > 1784.1555)    // He is using the elevator button
            
ShowElevatorDialog(playerid);
        else    
// Is he in a floor button?
        
{
            if(
pos[1] > -1301.4 && pos[1] < -1299.1447 && pos[0] < 1785.6147 && pos[0] > 1781.9902)
            {
                
// He is most likely using it, check floor:
                
new i=20;
                while(
pos[2] < GetDoorsZCoordForFloor(i) + 3.5 && 0)
                    
--;
                if(
== && pos[2] < GetDoorsZCoordForFloor(0) + 2.0)
                    
= -1;
                if(
<= 19)
                {
                    
CallElevator(playerid1);
                    
GameTextForPlayer(playerid"~r~Elevador Chamado"35004);
                }
            }
        }
    }
    return 
1;
}
// ------------------------ Functions ------------------------
stock Elevator_Initialize()
{
    
// Initializes the elevator.
    
Obj_Elevator            CreateObject(187551786.678100, -1303.459472GROUND_Z_COORD ELEVATOR_OFFSET0.0000000.000000270.000000);
    
Obj_ElevatorDoors[0]    = CreateObject(18757X_DOOR_CLOSED, -1303.459472GROUND_Z_COORD0.0000000.000000270.000000);
    
Obj_ElevatorDoors[1]    = CreateObject(18756X_DOOR_CLOSED, -1303.459472GROUND_Z_COORD0.0000000.000000270.000000);
    
Label_Elevator          Create3DTextLabel("Aperte 'F' para ver o dialog"0xFFFFDD1784.9822, -1302.042613.64914.001);
    new 
string[128],
        
Float:z;
    for(new 
isizeof(Obj_FloorDoors); ++)
    {
        
Obj_FloorDoors[i][0]    = CreateObject(18757X_DOOR_CLOSED, -1303.171142GetDoorsZCoordForFloor(i), 0.0000000.000000270.000000);
        
Obj_FloorDoors[i][1]    = CreateObject(18756X_DOOR_CLOSED, -1303.171142GetDoorsZCoordForFloor(i), 0.0000000.000000270.000000);
        
format(stringsizeof(string), "%s\nAperte 'F' para Chamar o Elevador"FloorNames[i]);
        if(
== 0)
            
13.4713;
        else
            
13.4713 8.7396 + ((i-1) * 5.45155);
        
Label_Floors[i]         = Create3DTextLabel(string0xFFFFDD1783.9799, -1300.7660z10.501);
        
// Label_Elevator, Text3D:Label_Floors[21];
    
}
    
// Open ground floor doors:
    
Floor_OpenDoors(0);
    
Elevator_OpenDoors();
    return 
1;
}
stock Elevator_Destroy()
{
    
// Destroys the elevator.
    
DestroyObject(Obj_Elevator);
    
DestroyObject(Obj_ElevatorDoors[0]);
    
DestroyObject(Obj_ElevatorDoors[1]);
    
Delete3DTextLabel(Label_Elevator);
    for(new 
isizeof(Obj_FloorDoors); ++)
    {
        
DestroyObject(Obj_FloorDoors[i][0]);
        
DestroyObject(Obj_FloorDoors[i][1]);
        
Delete3DTextLabel(Label_Floors[i]);
    }
    return 
1;
}
stock Elevator_OpenDoors()
{
    
// Opens the elevator's doors.
    
new Float:xFloat:yFloat:z;
    
GetObjectPos(Obj_ElevatorDoors[0], xyz);
    
MoveObject(Obj_ElevatorDoors[0], X_DOOR_L_OPENEDyzDOORS_SPEED);
    
MoveObject(Obj_ElevatorDoors[1], X_DOOR_R_OPENEDyzDOORS_SPEED);
    return 
1;
}
stock Elevator_CloseDoors()
{
    
// Closes the elevator's doors.
    
if(ElevatorState == ELEVATOR_STATE_MOVING)
        return 
0;
    new 
Float:xFloat:yFloat:z;
    
GetObjectPos(Obj_ElevatorDoors[0], xyz);
    
MoveObject(Obj_ElevatorDoors[0], X_DOOR_CLOSEDyzDOORS_SPEED);
    
MoveObject(Obj_ElevatorDoors[1], X_DOOR_CLOSEDyzDOORS_SPEED);
    return 
1;
}
stock Floor_OpenDoors(floorid)
{
    
// Opens the doors at the specified floor.
    
MoveObject(Obj_FloorDoors[floorid][0], X_DOOR_L_OPENED, -1303.171142GetDoorsZCoordForFloor(floorid), DOORS_SPEED);
    
MoveObject(Obj_FloorDoors[floorid][1], X_DOOR_R_OPENED, -1303.171142GetDoorsZCoordForFloor(floorid), DOORS_SPEED);
    return 
1;
}
stock Floor_CloseDoors(floorid)
{
    
// Closes the doors at the specified floor.
    
MoveObject(Obj_FloorDoors[floorid][0], X_DOOR_CLOSED, -1303.171142GetDoorsZCoordForFloor(floorid), DOORS_SPEED);
    
MoveObject(Obj_FloorDoors[floorid][1], X_DOOR_CLOSED, -1303.171142GetDoorsZCoordForFloor(floorid), DOORS_SPEED);
    return 
1;
}
stock Elevator_MoveToFloor(floorid)
{
    
// Moves the elevator to specified floor (doors are meant to be already closed).
    
ElevatorState ELEVATOR_STATE_MOVING;
    
ElevatorFloor floorid;
    
// Move the elevator slowly, to give time to clients to sync the object surfing. Then, boost it up:
    
MoveObject(Obj_Elevator1786.678100, -1303.459472GetElevatorZCoordForFloor(floorid), 0.5);
    
MoveObject(Obj_ElevatorDoors[0], X_DOOR_CLOSED, -1303.459472GetDoorsZCoordForFloor(floorid), 0.5);
    
MoveObject(Obj_ElevatorDoors[1], X_DOOR_CLOSED, -1303.459472GetDoorsZCoordForFloor(floorid), 0.5);
    
Delete3DTextLabel(Label_Elevator);
    
ElevatorBoostTimer SetTimerEx("Elevator_Boost"20000"i"floorid);
    return 
1;
}
public 
Elevator_Boost(floorid)
{
    
// Increases the elevator's speed until it reaches 'floorid'
    
MoveObject(Obj_Elevator1786.678100, -1303.459472GetElevatorZCoordForFloor(floorid), ELEVATOR_SPEED);
    
MoveObject(Obj_ElevatorDoors[0], X_DOOR_CLOSED, -1303.459472GetDoorsZCoordForFloor(floorid), ELEVATOR_SPEED);
    
MoveObject(Obj_ElevatorDoors[1], X_DOOR_CLOSED, -1303.459472GetDoorsZCoordForFloor(floorid), ELEVATOR_SPEED);
    return 
1;
}
public 
Elevator_TurnToIdle()
{
    
ElevatorState ELEVATOR_STATE_IDLE;
    
ReadNextFloorInQueue();
    return 
1;
}
stock RemoveFirstQueueFloor()
{
    
// Removes the data in ElevatorQueue[0], and reorders the queue accordingly.
    
for(new isizeof(ElevatorQueue) - 1++)
        
ElevatorQueue[i] = ElevatorQueue[1];
    
ElevatorQueue[sizeof(ElevatorQueue) - 1] = INVALID_FLOOR;
    return 
1;
}
stock AddFloorToQueue(floorid)
{
    
// Adds 'floorid' at the end of the queue.
    // Scan for the first empty space:
    
new slot = -1;
    for(new 
isizeof(ElevatorQueue); ++)
    {
        if(
ElevatorQueue[i] == INVALID_FLOOR)
        {
            
slot i;
            break;
        }
    }
    if(
slot != -1)
    {
        
ElevatorQueue[slot] = floorid;
        
// If needed, move the elevator.
        
if(ElevatorState == ELEVATOR_STATE_IDLE)
            
ReadNextFloorInQueue();
        return 
1;
    }
    return 
0;
}
stock ResetElevatorQueue()
{
    
// Resets the queue.
    
for(new isizeof(ElevatorQueue); ++)
    {
        
ElevatorQueue[i]    = INVALID_FLOOR;
        
FloorRequestedBy[i] = INVALID_PLAYER_ID;
    }
    return 
1;
}
stock IsFloorInQueue(floorid)
{
    
// Checks if the specified floor is currently part of the queue.
    
for(new isizeof(ElevatorQueue); ++)
        if(
ElevatorQueue[i] == floorid)
            return 
1;
    return 
0;
}
stock ReadNextFloorInQueue()
{
    
// Reads the next floor in the queue, closes doors, and goes to it.
    
if(ElevatorState != ELEVATOR_STATE_IDLE || ElevatorQueue[0] == INVALID_FLOOR)
        return 
0;
    
Elevator_CloseDoors();
    
Floor_CloseDoors(ElevatorFloor);
    return 
1;
}
stock DidPlayerRequestElevator(playerid)
{
    for(new 
isizeof(FloorRequestedBy); ++)
        if(
FloorRequestedBy[i] == playerid)
            return 
1;
    return 
0;
}
stock ShowElevatorDialog(playerid)
{
    new 
string[512];
    for(new 
isizeof(ElevatorQueue); ++)
    {
        if(
FloorRequestedBy[i] != INVALID_PLAYER_ID)
            
strcat(string"{FF0000}");
        
strcat(stringFloorNames[i]);
        
strcat(string"\n");
    }
    
ShowPlayerDialog(playeridDIALOG_IDDIALOG_STYLE_LIST"Elevador"string"Aceitar""Cancelar");
    return 
1;
}
stock CallElevator(playeridfloorid)
{
    
// Calls the elevator (also used with the elevator dialog).
    
if(FloorRequestedBy[floorid] != INVALID_PLAYER_ID || IsFloorInQueue(floorid))
        return 
0;
    
FloorRequestedBy[floorid] = playerid;
    
AddFloorToQueue(floorid);
    return 
1;
}
stock Float:GetElevatorZCoordForFloor(floorid)
    return (
GROUND_Z_COORD FloorZOffsets[floorid] + ELEVATOR_OFFSET); // A small offset for the elevator object itself.
stock Float:GetDoorsZCoordForFloor(floorid)
    return (
GROUND_Z_COORD FloorZOffsets[floorid]); 
Reply


Messages In This Thread
Bug Elevador! - by victorlus - 26.05.2014, 12:53
Re: Bug Elevador! - by MatheusDalZot - 26.05.2014, 12:59
Re: Bug Elevador! - by victorlus - 26.05.2014, 13:02
Re: Bug Elevador! - by MatheusDalZot - 26.05.2014, 13:30
Re: Bug Elevador! - by MatheusDalZot - 26.05.2014, 14:34
Re: Bug Elevador! - by victorlus - 26.05.2014, 15:05
Re: Bug Elevador! - by MatheusDalZot - 26.05.2014, 15:19
Re: Bug Elevador! - by victorlus - 26.05.2014, 16:20
Re: Bug Elevador! - by MatheusDalZot - 26.05.2014, 16:35
Re: Bug Elevador! - by victorlus - 26.05.2014, 16:37
Re: Bug Elevador! - by MatheusDalZot - 26.05.2014, 16:46
Re: Bug Elevador! - by victorlus - 26.05.2014, 18:41
Re: Bug Elevador! - by victorlus - 26.05.2014, 18:49
Re: Bug Elevador! - by MatheusDalZot - 26.05.2014, 19:05
Re: Bug Elevador! - by victorlus - 26.05.2014, 19:27
Re: Bug Elevador! - by victorlus - 26.05.2014, 20:58
Re: Bug Elevador! - by MatheusDalZot - 26.05.2014, 21:05
Re: Bug Elevador! - by Schocc - 26.05.2014, 21:26
Re: Bug Elevador! - by MatheusDalZot - 26.05.2014, 22:18
Re: Bug Elevador! - by victorlus - 26.05.2014, 22:56
Re: Bug Elevador! - by MatheusDalZot - 26.05.2014, 23:00
Re: Bug Elevador! - by victorlus - 26.05.2014, 23:03
Re: Bug Elevador! - by MatheusDalZot - 26.05.2014, 23:45
Re: Bug Elevador! - by victorlus - 27.05.2014, 00:08
Re: Bug Elevador! - by MatheusDalZot - 27.05.2014, 00:43
Re: Bug Elevador! - by victorlus - 27.05.2014, 01:04
Re: Bug Elevador! - by victorlus - 27.05.2014, 09:43
Re: Bug Elevador! - by MatheusDalZot - 27.05.2014, 14:49
Re: Bug Elevador! - by victorlus - 27.05.2014, 14:54
Re: Bug Elevador! - by victorlus - 28.05.2014, 12:17
Re: Bug Elevador! - by Locky_ - 28.05.2014, 13:30
Re: Bug Elevador! - by victorlus - 28.05.2014, 19:17

Forum Jump:


Users browsing this thread: 3 Guest(s)