Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.46 KB | None | 0 0
  1.     OnSpawn = function( this, pDBField, bRespawn, sRespawnMode )
  2.         local iTimer;
  3.        
  4.         if not bRespawn then
  5.             iTimer = CPlayerManager.m_iSpawnTimer;
  6.         else
  7.             iTimer = CPlayerManager.m_iRespawnTimer;
  8.         end
  9.        
  10.         CTimer(
  11.             function( this, pDBField, bRespawn, sRespawnMode )
  12.                 if this:IsValid() then
  13.                     local DefaultSpawn      = CPlayerManager.SpawnData;
  14.                    
  15.                     local vecPosition       = NULL;
  16.                     local fRotation         = NULL;
  17.                     local iInterior         = NULL;
  18.                     local iDimension        = NULL;
  19.                     local iMoney            = NULL;
  20.                     local iDonate           = NULL;
  21.                     local pWeapons          = NULL;
  22.                     local iSkin             = NULL;
  23.                     local fHealth           = NULL;
  24.                     local fDrunk            = NULL;
  25.                     local bCuffed           = NULL;
  26.                     local pWantedData       = NULL;
  27.                     local pJobsData         = NULL;
  28.                     local sPhoneNumber      = NULL;
  29.                     local pPhoneContacts    = NULL;
  30.                     local iPhoneBalance     = NULL;
  31.                     local pItems            = NULL;
  32.                     local iPlayingTime      = NULL;
  33.                     local sRegDate          = NULL;
  34.                    
  35.                     local eFaction          = NULL;
  36.                     local eFactionRank      = NULL;
  37.                     local bFactionUniform   = NULL;
  38.                    
  39.                     local iJailState        = NULL;
  40.                     local iJailID           = NULL;
  41.                     local iJailRoomID       = NULL;
  42.                     local iJailTime         = NULL;
  43.                     local pJailCustomData   = NULL;
  44.                    
  45.                     local bJailed           = false;
  46.                     local bFirstJoin        = false;
  47.                     local bRequestRespawn   = false;
  48.                    
  49.                     if pDBField then
  50.                         bFirstJoin  = pDBField.first_join == "Yes";
  51.                    
  52.                         -- Допустим у игрока вылетел ПК во время попытки заспавниться, но запрос на first_join = "No", то делаем по умолчанию.
  53.                         if not bFirstJoin then
  54.                             -- Проверяем.
  55.                             if not pDBField.x or not pDBField.y or not pDBField.z then
  56.                                 -- Спавним заного игрока, если у него не сохранена координата x, y, z.
  57.                                 bRequestRespawn = true;
  58.                             end
  59.                            
  60.                             -- Если у игрока нулевые координаты, то респавним.
  61.                             if pDBField.x == 0 and pDBField.y == 0 and pDBField.z == 0 then
  62.                                 bRequestRespawn = true;
  63.                             end
  64.                            
  65.                             -- Если игрок заспавнился под текстурами, то респавним.
  66.                             if pDBField.z < - 50 then
  67.                                 bRequestRespawn = true;
  68.                             end
  69.                         end
  70.                     end
  71.                    
  72.                     -- Если мы не респавнимся.
  73.                     if not bRespawn then
  74.                         -- Если мы впервые зашли, то спавним по умолчанию.
  75.                         if bFirstJoin then
  76.                             vecPosition     = Vector3( DefaultSpawn.m_vecPosition );
  77.                             fRotation       = DefaultSpawn.m_fRotation;
  78.                             iInterior       = DefaultSpawn.m_iInterior;
  79.                             iDimension      = DefaultSpawn.m_iDimension;
  80.                             iMoney          = DefaultSpawn.m_iMoney;
  81.                             iDonate         = 0;
  82.                             iSkin           = DefaultSpawn.m_aSkins[ math.random( #DefaultSpawn.m_aSkins ) ];
  83.                             fHealth         = DefaultSpawn.m_fHealth;
  84.                             fDrunk          = 0.0;
  85.                             pWeapons        = {};
  86.                             bCuffed         = false;
  87.                             pWantedData     = {};
  88.                             pJobsData       = {};
  89.                         else
  90.                             if not bRequestRespawn then
  91.                                 -- Если мы нормально заспавнились.
  92.                                 vecPosition     = Vector3( pDBField.x, pDBField.y, pDBField.z );
  93.                                 fRotation       = pDBField.rotation;
  94.                                 iInterior       = pDBField.interior;
  95.                                 iDimension      = pDBField.dimension;
  96.                             else
  97.                                 -- Если мы провалились куда-то, то респавнимся на нормальной позиции.
  98.                                 vecPosition     = Vector3( DefaultSpawn.m_vecPosition );
  99.                                 fRotation       = DefaultSpawn.m_fRotation;
  100.                                 iInterior       = DefaultSpawn.m_iInterior;
  101.                                 iDimension      = DefaultSpawn.m_iDimension;   
  102.                             end
  103.                            
  104.                             iMoney          = pDBField.money;
  105.                             iDonate         = pDBField.donate;
  106.                             iSkin           = pDBField.skin;
  107.                             fHealth         = pDBField.health or 100.0;
  108.                             fDrunk          = pDBField.drunk or 0.0;
  109.                             pWeapons        = pDBField.weapons and fromJSON( pDBField.weapons );
  110.                             bCuffed         = pDBField.cuffed == "Yes";
  111.                             pWantedData     = pDBField.wanted_data and fromJSON( pDBField.wanted_data );
  112.                             pJobsData       = pDBField.jobs_data and fromJSON( pDBField.jobs_data );
  113.                             sPhoneNumber    = pDBField.phone;
  114.                             pPhoneContacts  = pDBField.phone_contacts and fromJSON( pDBField.phone_contacts );
  115.                             iPhoneBalance   = pDBField.phone_balance;
  116.                             pItems          = pDBField.items and fromJSON( pDBField.items );
  117.                             iPlayingTime    = pDBField.playing_time;
  118.                             sRegDate        = pDBField.reg_date;
  119.                            
  120.                             eFaction        = pDBField.faction_id;
  121.                             eFactionRank    = pDBField.faction_rank;
  122.                             bFactionUniform = pDBField.faction_uniform == "Yes";
  123.                            
  124.                             iJailState      = pDBField.jail_state;
  125.                             iJailID         = pDBField.jail_id;
  126.                             iJailRoomID     = pDBField.jail_room_id;
  127.                             iJailTime       = pDBField.jail_time;
  128.                             pJailCustomData = pDBField.jail_data and fromJSON( pDBField.jail_data );
  129.                            
  130.                             -- Сохраняем тюрьму.
  131.                             this:SetJailData( iJailID, iJailRoomID, iJailState, iJailTime, pJailCustomData );
  132.                         end
  133.                     end
  134.                    
  135.                     -- Делаем респавн возле больницы.
  136.                     if bRespawn then
  137.                         iSkin       = this:GetDefaultSkin();
  138.                         fHealth     = 15.0;
  139.                         fDrunk      = 0.0;
  140.                            
  141.                         -- Делаем сброс аттача.
  142.                         this:GetBones():ReleaseAll();
  143.                            
  144.                         -- Получаем данные о тюрьме.
  145.                         local pJailData = this:GetJailData();
  146.                            
  147.                         iJailState      = pJailData.m_iState;
  148.                         iJailID         = pJailData.m_iID;
  149.                         iJailRoomID     = pJailData.m_iRoomID;
  150.                     end
  151.                    
  152.                     -- Если игрок появился впервые или у него был респавн.
  153.                     if bFirstJoin or bRequestRespawn then                      
  154.                         -- Респавн в рандоме.
  155.                         local fRandomize = DefaultSpawn.m_fRadius;
  156.                        
  157.                         vecPosition.X = vecPosition.X + math.random_real( - fRandomize, fRandomize );
  158.                         vecPosition.Y = vecPosition.Y + math.random_real( - fRandomize, fRandomize );
  159.                     end
  160.                    
  161.                     -- Если игрок сидит в КПЗ.
  162.                     if iJailState == 1 then
  163.                         -- Получаем ИД КПЗ.
  164.                         local pJail = g_pGame:GetJailManager():Get( iJailID );
  165.                                
  166.                         if pJail then
  167.                             -- Получаем камеру.
  168.                             local pJailRoom = pJail:GetRoom( iJailRoomID );
  169.                                    
  170.                             if pJailRoom then
  171.                                 -- Получаем позицию камеры и других данных.
  172.                                 vecPosition = Vector3( pJailRoom:GetPosition() );
  173.                                 fRotation   = pJailRoom:GetRotation();
  174.                                 iInterior   = pJailRoom:GetInterior();
  175.                                 iDimension  = pJailRoom:GetDimension();
  176.                                
  177.                                 -- Получаем данные о тюрьме.
  178.                                 local pJailData = this:GetJailData();
  179.                                
  180.                                 -- Получаем время.
  181.                                 local iTime = pJailData.m_iTime;
  182.                                
  183.                                 -- Сбрасываем оружие.
  184.                                 pWeapons    = {};
  185.                                
  186.                                 -- Мы в тюрьме.
  187.                                 bJailed     = true;
  188.                                
  189.                                 -- Создаем интерфейс.
  190.                                 this:ShowUI( "CUIArrest", iTime, pWantedData, pJailCustomData );
  191.                             end
  192.                         end
  193.                     else
  194.                         -- Если у нас респавн.
  195.                         if bRespawn then
  196.                             -- Если игрок не сидит в тюрьме, то берем данные респавна, поиск по ближайщей больнице.
  197.                             local pHospital = g_pGame:GetHospitalManager():GetNearby( this:GetPosition() );
  198.                            
  199.                             if pHospital then
  200.                                 -- Даем рандомный спавн игроку.
  201.                                 local RespawnData = pHospital:GiveRandomSpawn( this );
  202.                                
  203.                                 vecPosition = Vector3( RespawnData.m_vecPosition );
  204.                                 fRotation   = RespawnData.m_fRotation;
  205.                                 iInterior   = RespawnData.m_iInterior;
  206.                                 iDimension  = RespawnData.m_iDimension;
  207.                             end
  208.                         end
  209.                     end
  210.                    
  211.                     -- Если нам нужно респавнить на обычном спавне, то.
  212.                     if sRespawnMode == "default_respawn" then
  213.                         -- Если мы не в тюрьме.
  214.                         if iJailState ~= 1 then
  215.                             vecPosition     = Vector3( DefaultSpawn.m_vecPosition );
  216.                             fRotation       = DefaultSpawn.m_fRotation;
  217.                             iInterior       = DefaultSpawn.m_iInterior;
  218.                             iDimension      = DefaultSpawn.m_iDimension;
  219.                             fHealth         = this:GetHealth();
  220.                            
  221.                             -- Респавн в рандоме.
  222.                             local fRandomize = DefaultSpawn.m_fRadius;
  223.                            
  224.                             vecPosition.X = vecPosition.X + math.random_real( - fRandomize, fRandomize );
  225.                             vecPosition.Y = vecPosition.Y + math.random_real( - fRandomize, fRandomize );
  226.                         end
  227.                     end
  228.                    
  229.                     -- Делаем оффсет спавна.
  230.                     local vecPosition = Vector3( vecPosition );
  231.                    
  232.                     -- Чтобы не застревал в текстурах.
  233.                     vecPosition.Z = vecPosition.Z + 0.3;
  234.                    
  235.                     -- Спавн.
  236.                     this:Spawn  ( vecPosition, fRotation, iSkin, iInterior, iDimension, g_pTeamPlayers );
  237.                    
  238.                     this:SetDimension( iDimension );
  239.                     this:SetHealth ( fHealth );
  240.                     this:SetDrunk( fDrunk );
  241.                    
  242.                     -- Если мы зашли впервые на сервер (без респавна).
  243.                     if not bRespawn then
  244.                         -- Деньги.
  245.                         this:SetMoney ( iMoney );
  246.                        
  247.                         -- Донат.
  248.                         this:SetDonate ( iDonate );
  249.                        
  250.                         -- Фракция.
  251.                         this:SetFaction( eFaction, eFactionRank, bFactionUniform );
  252.                        
  253.                         -- Неймтег.
  254.                         this:SetNametag();
  255.                        
  256.                         -- Оружие.
  257.                         this:GiveAllWeapons( pWeapons );
  258.                        
  259.                         -- Даем игроку наручники.
  260.                         this:SetCuffed( bCuffed );
  261.                        
  262.                         -- Даем игроку статьи.
  263.                         this:SetWantedData( pWantedData );
  264.                        
  265.                         -- Даем игроку EXP за работы.
  266.                         this:SetJobsData( pJobsData );
  267.                        
  268.                         -- Даем номер телефона.
  269.                         this:SetPhoneNumber( sPhoneNumber );
  270.                        
  271.                         -- Даем контакты телефона.
  272.                         this:SetPhoneContacts( pPhoneContacts );
  273.                        
  274.                         -- Даем баланс телефона.
  275.                         this:SetPhoneBalance( iPhoneBalance );
  276.                        
  277.                         -- Сет предметы.
  278.                         this:SetInventoryData( pItems );
  279.                        
  280.                         -- Устанавливаем время игры.
  281.                         this:SetTotalPlayingTime( iPlayingTime );
  282.                        
  283.                         -- Задаем счетчик игры на сервере.
  284.                         this:SetPlayingTime();
  285.                        
  286.                         -- Записываем дату регистрации.
  287.                         this:SetRegistrationDate( sRegDate );
  288.                        
  289.                         -- Делаем по умолчанию голосовые каналы.
  290.                         this:SetVoiceChannel( NULL );
  291.                        
  292.                         -- И то что мы говорим.
  293.                         this:SetVoiceBroadcast( false );
  294.                     end
  295.                    
  296.                     this:SetDefaultSkin( iSkin );
  297.                    
  298.                     -- Делаем работу по умолчанию NULL.
  299.                     this:SetJob( NULL );
  300.                    
  301.                     -- Восстанавливаем кнопки.
  302.                     this:ToggleAllControls( true );
  303.                    
  304.                     -- Убираем альфу.
  305.                     this:SetAlpha( 255.0 );
  306.                    
  307.                     -- Если игрок в тюрьме.
  308.                     if bJailed then                    
  309.                         -- Одеваем игрока
  310.                         this:SetModel( 156 );
  311.                     end
  312.                    
  313.                     -- Делаем игрока в игре.
  314.                     this:SetInGame( true );
  315.                    
  316.                     -- Сообщаем всем, что игрок создан на клиенте.
  317.                     triggerEvent( "onPlayerCreated", this );
  318.                     triggerClientEvent( root, "onClientPlayerCreated", this );
  319.                    
  320.                     -- Вызываем событие входа на сервер.
  321.                     if ( not bRespawn ) then
  322.                         triggerEvent( "onPlayerFirstCreated", this );
  323.                         triggerClientEvent( root, "onClientPlayerFirstCreated", this );
  324.                     end
  325.                    
  326.                     -- Показываем команды при спавне.
  327.                     if ( not bRespawn ) then
  328.                         this:ShowChatHelp();
  329.                     end
  330.                    
  331.                     -- Обновляем входные данные.
  332.                     if ( not bRespawn ) then
  333.                         -- Обновляем статус.
  334.                         g_pDB:Query( "UPDATE " + g_sDbPrefix + "players SET now_serial = %q, now_ip = %q, now_date = NOW(), first_join = 'No', online = 'Yes' WHERE id = %d LIMIT 1", this:GetSerial(), this:GetIP(), this:GetUserID() );
  335.                        
  336.                         -- Делаем сброс камеры и т.д
  337.                         triggerClientEvent( this, "onClientPlayerSpawnedFirst", this );
  338.                     end
  339.                 end
  340.             end,
  341.         iTimer, 1, this, pDBField, bRespawn, sRespawnMode );
  342.     end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement