Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OnSpawn = function( this, pDBField, bRespawn, sRespawnMode )
- local iTimer;
- if not bRespawn then
- iTimer = CPlayerManager.m_iSpawnTimer;
- else
- iTimer = CPlayerManager.m_iRespawnTimer;
- end
- CTimer(
- function( this, pDBField, bRespawn, sRespawnMode )
- if this:IsValid() then
- local DefaultSpawn = CPlayerManager.SpawnData;
- local vecPosition = NULL;
- local fRotation = NULL;
- local iInterior = NULL;
- local iDimension = NULL;
- local iMoney = NULL;
- local iDonate = NULL;
- local pWeapons = NULL;
- local iSkin = NULL;
- local fHealth = NULL;
- local fDrunk = NULL;
- local bCuffed = NULL;
- local pWantedData = NULL;
- local pJobsData = NULL;
- local sPhoneNumber = NULL;
- local pPhoneContacts = NULL;
- local iPhoneBalance = NULL;
- local pItems = NULL;
- local iPlayingTime = NULL;
- local sRegDate = NULL;
- local eFaction = NULL;
- local eFactionRank = NULL;
- local bFactionUniform = NULL;
- local iJailState = NULL;
- local iJailID = NULL;
- local iJailRoomID = NULL;
- local iJailTime = NULL;
- local pJailCustomData = NULL;
- local bJailed = false;
- local bFirstJoin = false;
- local bRequestRespawn = false;
- if pDBField then
- bFirstJoin = pDBField.first_join == "Yes";
- -- Допустим у игрока вылетел ПК во время попытки заспавниться, но запрос на first_join = "No", то делаем по умолчанию.
- if not bFirstJoin then
- -- Проверяем.
- if not pDBField.x or not pDBField.y or not pDBField.z then
- -- Спавним заного игрока, если у него не сохранена координата x, y, z.
- bRequestRespawn = true;
- end
- -- Если у игрока нулевые координаты, то респавним.
- if pDBField.x == 0 and pDBField.y == 0 and pDBField.z == 0 then
- bRequestRespawn = true;
- end
- -- Если игрок заспавнился под текстурами, то респавним.
- if pDBField.z < - 50 then
- bRequestRespawn = true;
- end
- end
- end
- -- Если мы не респавнимся.
- if not bRespawn then
- -- Если мы впервые зашли, то спавним по умолчанию.
- if bFirstJoin then
- vecPosition = Vector3( DefaultSpawn.m_vecPosition );
- fRotation = DefaultSpawn.m_fRotation;
- iInterior = DefaultSpawn.m_iInterior;
- iDimension = DefaultSpawn.m_iDimension;
- iMoney = DefaultSpawn.m_iMoney;
- iDonate = 0;
- iSkin = DefaultSpawn.m_aSkins[ math.random( #DefaultSpawn.m_aSkins ) ];
- fHealth = DefaultSpawn.m_fHealth;
- fDrunk = 0.0;
- pWeapons = {};
- bCuffed = false;
- pWantedData = {};
- pJobsData = {};
- else
- if not bRequestRespawn then
- -- Если мы нормально заспавнились.
- vecPosition = Vector3( pDBField.x, pDBField.y, pDBField.z );
- fRotation = pDBField.rotation;
- iInterior = pDBField.interior;
- iDimension = pDBField.dimension;
- else
- -- Если мы провалились куда-то, то респавнимся на нормальной позиции.
- vecPosition = Vector3( DefaultSpawn.m_vecPosition );
- fRotation = DefaultSpawn.m_fRotation;
- iInterior = DefaultSpawn.m_iInterior;
- iDimension = DefaultSpawn.m_iDimension;
- end
- iMoney = pDBField.money;
- iDonate = pDBField.donate;
- iSkin = pDBField.skin;
- fHealth = pDBField.health or 100.0;
- fDrunk = pDBField.drunk or 0.0;
- pWeapons = pDBField.weapons and fromJSON( pDBField.weapons );
- bCuffed = pDBField.cuffed == "Yes";
- pWantedData = pDBField.wanted_data and fromJSON( pDBField.wanted_data );
- pJobsData = pDBField.jobs_data and fromJSON( pDBField.jobs_data );
- sPhoneNumber = pDBField.phone;
- pPhoneContacts = pDBField.phone_contacts and fromJSON( pDBField.phone_contacts );
- iPhoneBalance = pDBField.phone_balance;
- pItems = pDBField.items and fromJSON( pDBField.items );
- iPlayingTime = pDBField.playing_time;
- sRegDate = pDBField.reg_date;
- eFaction = pDBField.faction_id;
- eFactionRank = pDBField.faction_rank;
- bFactionUniform = pDBField.faction_uniform == "Yes";
- iJailState = pDBField.jail_state;
- iJailID = pDBField.jail_id;
- iJailRoomID = pDBField.jail_room_id;
- iJailTime = pDBField.jail_time;
- pJailCustomData = pDBField.jail_data and fromJSON( pDBField.jail_data );
- -- Сохраняем тюрьму.
- this:SetJailData( iJailID, iJailRoomID, iJailState, iJailTime, pJailCustomData );
- end
- end
- -- Делаем респавн возле больницы.
- if bRespawn then
- iSkin = this:GetDefaultSkin();
- fHealth = 15.0;
- fDrunk = 0.0;
- -- Делаем сброс аттача.
- this:GetBones():ReleaseAll();
- -- Получаем данные о тюрьме.
- local pJailData = this:GetJailData();
- iJailState = pJailData.m_iState;
- iJailID = pJailData.m_iID;
- iJailRoomID = pJailData.m_iRoomID;
- end
- -- Если игрок появился впервые или у него был респавн.
- if bFirstJoin or bRequestRespawn then
- -- Респавн в рандоме.
- local fRandomize = DefaultSpawn.m_fRadius;
- vecPosition.X = vecPosition.X + math.random_real( - fRandomize, fRandomize );
- vecPosition.Y = vecPosition.Y + math.random_real( - fRandomize, fRandomize );
- end
- -- Если игрок сидит в КПЗ.
- if iJailState == 1 then
- -- Получаем ИД КПЗ.
- local pJail = g_pGame:GetJailManager():Get( iJailID );
- if pJail then
- -- Получаем камеру.
- local pJailRoom = pJail:GetRoom( iJailRoomID );
- if pJailRoom then
- -- Получаем позицию камеры и других данных.
- vecPosition = Vector3( pJailRoom:GetPosition() );
- fRotation = pJailRoom:GetRotation();
- iInterior = pJailRoom:GetInterior();
- iDimension = pJailRoom:GetDimension();
- -- Получаем данные о тюрьме.
- local pJailData = this:GetJailData();
- -- Получаем время.
- local iTime = pJailData.m_iTime;
- -- Сбрасываем оружие.
- pWeapons = {};
- -- Мы в тюрьме.
- bJailed = true;
- -- Создаем интерфейс.
- this:ShowUI( "CUIArrest", iTime, pWantedData, pJailCustomData );
- end
- end
- else
- -- Если у нас респавн.
- if bRespawn then
- -- Если игрок не сидит в тюрьме, то берем данные респавна, поиск по ближайщей больнице.
- local pHospital = g_pGame:GetHospitalManager():GetNearby( this:GetPosition() );
- if pHospital then
- -- Даем рандомный спавн игроку.
- local RespawnData = pHospital:GiveRandomSpawn( this );
- vecPosition = Vector3( RespawnData.m_vecPosition );
- fRotation = RespawnData.m_fRotation;
- iInterior = RespawnData.m_iInterior;
- iDimension = RespawnData.m_iDimension;
- end
- end
- end
- -- Если нам нужно респавнить на обычном спавне, то.
- if sRespawnMode == "default_respawn" then
- -- Если мы не в тюрьме.
- if iJailState ~= 1 then
- vecPosition = Vector3( DefaultSpawn.m_vecPosition );
- fRotation = DefaultSpawn.m_fRotation;
- iInterior = DefaultSpawn.m_iInterior;
- iDimension = DefaultSpawn.m_iDimension;
- fHealth = this:GetHealth();
- -- Респавн в рандоме.
- local fRandomize = DefaultSpawn.m_fRadius;
- vecPosition.X = vecPosition.X + math.random_real( - fRandomize, fRandomize );
- vecPosition.Y = vecPosition.Y + math.random_real( - fRandomize, fRandomize );
- end
- end
- -- Делаем оффсет спавна.
- local vecPosition = Vector3( vecPosition );
- -- Чтобы не застревал в текстурах.
- vecPosition.Z = vecPosition.Z + 0.3;
- -- Спавн.
- this:Spawn ( vecPosition, fRotation, iSkin, iInterior, iDimension, g_pTeamPlayers );
- this:SetDimension( iDimension );
- this:SetHealth ( fHealth );
- this:SetDrunk( fDrunk );
- -- Если мы зашли впервые на сервер (без респавна).
- if not bRespawn then
- -- Деньги.
- this:SetMoney ( iMoney );
- -- Донат.
- this:SetDonate ( iDonate );
- -- Фракция.
- this:SetFaction( eFaction, eFactionRank, bFactionUniform );
- -- Неймтег.
- this:SetNametag();
- -- Оружие.
- this:GiveAllWeapons( pWeapons );
- -- Даем игроку наручники.
- this:SetCuffed( bCuffed );
- -- Даем игроку статьи.
- this:SetWantedData( pWantedData );
- -- Даем игроку EXP за работы.
- this:SetJobsData( pJobsData );
- -- Даем номер телефона.
- this:SetPhoneNumber( sPhoneNumber );
- -- Даем контакты телефона.
- this:SetPhoneContacts( pPhoneContacts );
- -- Даем баланс телефона.
- this:SetPhoneBalance( iPhoneBalance );
- -- Сет предметы.
- this:SetInventoryData( pItems );
- -- Устанавливаем время игры.
- this:SetTotalPlayingTime( iPlayingTime );
- -- Задаем счетчик игры на сервере.
- this:SetPlayingTime();
- -- Записываем дату регистрации.
- this:SetRegistrationDate( sRegDate );
- -- Делаем по умолчанию голосовые каналы.
- this:SetVoiceChannel( NULL );
- -- И то что мы говорим.
- this:SetVoiceBroadcast( false );
- end
- this:SetDefaultSkin( iSkin );
- -- Делаем работу по умолчанию NULL.
- this:SetJob( NULL );
- -- Восстанавливаем кнопки.
- this:ToggleAllControls( true );
- -- Убираем альфу.
- this:SetAlpha( 255.0 );
- -- Если игрок в тюрьме.
- if bJailed then
- -- Одеваем игрока
- this:SetModel( 156 );
- end
- -- Делаем игрока в игре.
- this:SetInGame( true );
- -- Сообщаем всем, что игрок создан на клиенте.
- triggerEvent( "onPlayerCreated", this );
- triggerClientEvent( root, "onClientPlayerCreated", this );
- -- Вызываем событие входа на сервер.
- if ( not bRespawn ) then
- triggerEvent( "onPlayerFirstCreated", this );
- triggerClientEvent( root, "onClientPlayerFirstCreated", this );
- end
- -- Показываем команды при спавне.
- if ( not bRespawn ) then
- this:ShowChatHelp();
- end
- -- Обновляем входные данные.
- if ( not bRespawn ) then
- -- Обновляем статус.
- 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() );
- -- Делаем сброс камеры и т.д
- triggerClientEvent( this, "onClientPlayerSpawnedFirst", this );
- end
- end
- end,
- iTimer, 1, this, pDBField, bRespawn, sRespawnMode );
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement