Летать камерой

Описание: Уроки по скриптингу
Модератор: SJplayer

Aleksandr M
Автор темы, Модератор
Модератор
Аватара
Aleksandr M
Автор темы, Модератор
Модератор
Сообщения: 55
Зарегистрирован: 4 июня 2013
С нами: 10 лет 10 месяцев

#1 Aleksandr » 23 октября 2013, 20:30

Летать камерой
Автор Prolific

Я решил написать этот урок по одной теме, а именно полет камерой, этот ФС есть в стандартной сборке самп, но если вы хотите залить вс в мод, то этот урок для вас. Есть конечно и клео скрипт, но я считаю, что в моде лучше иметь такую камеру.

После инклудов вставляем

Код: Выделить всё

#define MOVE_SPEED              100.0
#define ACCEL_RATE              0.03
#define CAMERA_MODE_NONE        0
#define CAMERA_MODE_FLY         1
#define MOVE_FORWARD            1
#define MOVE_BACK               2
#define MOVE_LEFT               3
#define MOVE_RIGHT              4
#define MOVE_FORWARD_LEFT       5
#define MOVE_FORWARD_RIGHT      6
#define MOVE_BACK_LEFT          7
#define MOVE_BACK_RIGHT         8  


Далее ко всем new добавляем:

Код: Выделить всё

enum noclipenum
{
    
cameramode,
    
flyobject,
    
mode,
    
lrold,
    
udold,
    
lastmove,
    
Float:accelmul
}
new 
noclipdata[MAX_PLAYERS][noclipenum];  


Далее в public OnGameModeExit вставляем:

Код: Выделить всё

for(new xx<MAX_PLAYERSx++)
    {
        if(
noclipdata[x][cameramode] == CAMERA_MODE_FLYCancelFlyMode(x);
    }  


Далее в public OnPlayerConnect вставляем:

Код: Выделить всё

    noclipdata[playerid][cameramode]     = CAMERA_MODE_NONE;
    
noclipdata[playerid][lrold]                = 0;
    
noclipdata[playerid][udold]           = 0;
    
noclipdata[playerid][mode]           = 0;
    
noclipdata[playerid][lastmove]       = 0;
    
noclipdata[playerid][accelmul]       = 0.0;  


Далее в public OnPlayerCommandText вставляем саму команду:

Код: Выделить всё

if(!strcmp(cmdtext"/flymode"true))// /flymode можете заменить на свою команду
    
{
                  if(
Player[playerid][pAdmin] >= 6)// если не хотите что бы проверяло на админку уберите
                  
{
        if(
GetPVarType(playerid"FlyMode")) CancelFlyMode(playerid);
        else 
FlyMode(playerid);
        return 
1;
                   }
    }  


Далее в public OnPlayerUpdate вставляем:

Код: Выделить всё

if(noclipdata[playerid][cameramode] == CAMERA_MODE_FLY)
    {
        new 
keyss,ud,lr;
        
GetPlayerKeys(playerid,keyss,ud,lr);

        if(
noclipdata[playerid][mode] && (GetTickCount() - noclipdata[playerid][lastmove] > 100))
        {
            
// If the last move was > 100ms ago, process moving the object the players camera is attached to
            
MoveCamera(playerid);
        }

        
// Is the players current key state different than their last keystate?
        
if(noclipdata[playerid][udold] != ud || noclipdata[playerid][lrold] != lr)
        {
            if((
noclipdata[playerid][udold] != || noclipdata[playerid][lrold] != 0) && ud == && lr == 0)
            {   
// All keys have been released, stop the object the camera is attached to and reset the acceleration multiplier
                
StopPlayerObject(playeridnoclipdata[playerid][flyobject]);
                
noclipdata[playerid][mode]      = 0;
                
noclipdata[playerid][accelmul]  = 0.0;
            }
            else
            {   
// Indicates a new key has been pressed

                // Get the direction the player wants to move as indicated by the keys
                
noclipdata[playerid][mode] = GetMoveDirectionFromKeys(udlr);

                
// Process moving the object the players camera is attached to
                
MoveCamera(playerid);
            }
        }
        
noclipdata[playerid][udold] = udnoclipdata[playerid][lrold] = lr// Store current keys pressed for comparison next update
        
return 0;
    }  


Далее в конец мода вставляете:

Код: Выделить всё

stock GetMoveDirectionFromKeys(udlr)
{
    new 
direction 0;

    if(
lr 0)
    {
        if(
ud 0)         direction MOVE_FORWARD_LEFT;     // Up & Left key pressed
        
else if(ud 0direction MOVE_BACK_LEFT;     // Back & Left key pressed
        
else            direction MOVE_LEFT;          // Left key pressed
    
}
    else if(
lr 0)     // Right pressed
    
{
        if(
ud 0)      direction MOVE_FORWARD_RIGHT;  // Up & Right key pressed
        
else if(ud 0direction MOVE_BACK_RIGHT;     // Back & Right key pressed
        
else            direction MOVE_RIGHT;          // Right key pressed
    
}
    else if(
ud 0)     direction MOVE_FORWARD;     // Up key pressed
    
else if(ud 0)     direction MOVE_BACK;        // Down key pressed

    
return direction;
}
stock MoveCamera(playerid)
{
     new 
Float:FV[3], Float:CPP[3];
    
GetPlayerCameraPos(playeridCPP[0], CPP[1], CPP[2]);          //     Cameras position in space
    
GetPlayerCameraFrontVector(playeridFV[0], FV[1], FV[2]);  //  Where the camera is looking at

    // Increases the acceleration multiplier the longer the key is held
    
if(noclipdata[playerid][accelmul] <= 1noclipdata[playerid][accelmul] += ACCEL_RATE;

    
// Determine the speed to move the camera based on the acceleration multiplier
    
new Float:speed MOVE_SPEED noclipdata[playerid][accelmul];

    
// Calculate the cameras next position based on their current position and the direction their camera is facing
    
new Float:XFloat:YFloat:Z;
    
GetNextCameraPosition(noclipdata[playerid][mode], CPPFVXYZ);
    
MovePlayerObject(playeridnoclipdata[playerid][flyobject], XYZspeed);

    
// Store the last time the camera was moved as now
    
noclipdata[playerid][lastmove] = GetTickCount();
    return 
1;
}
stock GetNextCameraPosition(move_modeFloat:CPP[3], Float:FV[3], &Float:X, &Float:Y, &Float:Z)
{
    
// Calculate the cameras next position based on their current position and the direction their camera is facing
    #define OFFSET_X (FV[0]*6000.0)
    #define OFFSET_Y (FV[1]*6000.0)
    #define OFFSET_Z (FV[2]*6000.0)
    
switch(move_mode)
    {
        case 
MOVE_FORWARD:
        {
            
CPP[0]+OFFSET_X;
            
CPP[1]+OFFSET_Y;
            
CPP[2]+OFFSET_Z;
        }
        case 
MOVE_BACK:
        {
            
CPP[0]-OFFSET_X;
            
CPP[1]-OFFSET_Y;
            
CPP[2]-OFFSET_Z;
        }
        case 
MOVE_LEFT:
        {
            
CPP[0]-OFFSET_Y;
            
CPP[1]+OFFSET_X;
            
CPP[2];
        }
        case 
MOVE_RIGHT:
        {
            
CPP[0]+OFFSET_Y;
            
CPP[1]-OFFSET_X;
            
CPP[2];
        }
        case 
MOVE_BACK_LEFT:
        {
            
CPP[0]+(-OFFSET_X OFFSET_Y);
             
CPP[1]+(-OFFSET_Y OFFSET_X);
             
CPP[2]-OFFSET_Z;
        }
        case 
MOVE_BACK_RIGHT:
        {
            
CPP[0]+(-OFFSET_X OFFSET_Y);
             
CPP[1]+(-OFFSET_Y OFFSET_X);
             
CPP[2]-OFFSET_Z;
        }
        case 
MOVE_FORWARD_LEFT:
        {
            
CPP[0]+(OFFSET_X  OFFSET_Y);
            
CPP[1]+(OFFSET_Y  OFFSET_X);
            
CPP[2]+OFFSET_Z;
        }
        case 
MOVE_FORWARD_RIGHT:
        {
            
CPP[0]+(OFFSET_X  OFFSET_Y);
            
CPP[1]+(OFFSET_Y  OFFSET_X);
            
CPP[2]+OFFSET_Z;
        }
    }
}
stock CancelFlyMode(playerid)
{
    
DeletePVar(playerid"FlyMode");
    
CancelEdit(playerid);
    
TogglePlayerSpectating(playeridfalse);

    
DestroyPlayerObject(playeridnoclipdata[playerid][flyobject]);
    
noclipdata[playerid][cameramode] = CAMERA_MODE_NONE;
    return 
1;
}
stock FlyMode(playerid)
{
    
// Create an invisible object for the players camera to be attached to
    
new Float:XFloat:YFloat:Z;
    
GetPlayerPos(playeridXYZ);
    
noclipdata[playerid][flyobject] = CreatePlayerObject(playerid19300XYZ0.00.00.0);

    
// Place the player in spectating mode so objects will be streamed based on camera location
    
TogglePlayerSpectating(playeridtrue);
    
// Attach the players camera to the created object
    
AttachCameraToPlayerObject(playeridnoclipdata[playerid][flyobject]);

    
SetPVarInt(playerid"FlyMode"1);
    
noclipdata[playerid][cameramode] = CAMERA_MODE_FLY;
    return 
1;
}  


Вернуться в «Уроки»

Кто сейчас на форуме (по активности за 5 минут)

Сейчас этот раздел просматривают: 5 гостей