Created
January 1, 2024 18:30
-
-
Save ihyajb/74f38dd85f4113cf8e4155bf9a3152ae to your computer and use it in GitHub Desktop.
GTA:O Smoking Scenes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- I didnt fully finish this, I planned for it to be like configable with different locations and stuff but 🤷🏻♂️ | |
AddTextEntry('BLUNT_HELP_PC', '~INPUT_FRONTEND_X~ Smoke\n~INPUT_FRONTEND_CANCEL~ Exit') | |
AddTextEntry('BLUNT_ENTER_PC', 'Enter') | |
local sSmokingActivityData = { | |
eCurrentState = 'SMOKING_ACTIVITY_STATE_INIT' | |
} | |
local Debug = true | |
local serverBD = { --TODO: Sync this data? | |
objLighter = 0, | |
objSmoking = 0, | |
objAshtray = 0, | |
ptfxLighter = 0, | |
ptfxCigarette = 0, | |
} | |
local function DisplayNotify(string, looped, time) | |
looped = looped or true | |
time = time or -1 | |
-- print('Showing: '..sParam0) | |
BeginTextCommandDisplayHelp(string) | |
EndTextCommandDisplayHelp(0, looped, false, time) | |
end | |
local BitSet = { | |
['SMOKING_ACTIVITY_BS_SPARKS'] = false, | |
['SMOKING_ACTIVITY_BS_FLAME'] = false, | |
['SMOKING_ACTIVITY_BS_SMOKE'] = false, | |
['SMOKING_ACTIVITY_BS_EXHALE_MOUTH'] = false | |
} | |
local function GET_SMOKING_ACTIVITY_ANIM_DICT() | |
return "ANIM@AMB@NIGHTCLUB@SMOKING@" | |
end | |
-- VECTOR vLocateA, VECTOR vLocateB, VECTOR vScenePos, VECTOR vSceneRot, BOOL bMakePlayerHigh = FALSE | |
-- ADD_NEW_SMOKING_ACTIVITY(<<-1355.453613,137.843872,-96.109329>>, <<-1354.768555,137.826599,-95.109337>>, << -1355.569, 138.672, -95.870 >>, <<0.0, 0.0, 70.680>>) | |
local function GET_SMOKING_SCENE_POSITION() | |
return vector3(-1355.569, 138.672, -95.870) | |
end | |
local function GET_SMOKING_SCENE_ROTATION() | |
return vector3(0.0, 0.0, 70.680) | |
end | |
local function GET_SMOKING_PROP_NAME() | |
return `ng_proc_cigarette01a` | |
-- return `P_CS_Joint_01` | |
end | |
local function SET_SMOKING_ACTIVITY_STATE(s) | |
sSmokingActivityData.eCurrentState = s | |
if Debug then print('SET_SMOKING_ACTIVITY_STATE:', s) end | |
end | |
local function CREATE_SMOKING_ACTIVITY_PROPS() | |
local dict = GET_SMOKING_ACTIVITY_ANIM_DICT() | |
--? Lighter and main anim data ?-- | |
if not HasModelLoaded(`P_CS_LIGHTER_01`) then | |
repeat | |
Wait(50) | |
RequestModel(`P_CS_LIGHTER_01`) | |
until HasModelLoaded(`P_CS_LIGHTER_01`) | |
end | |
if not HasAnimDictLoaded(dict) then | |
repeat | |
Wait(50) | |
RequestAnimDict(dict) | |
until HasAnimDictLoaded(dict) | |
end | |
local vLighterPosition = GetAnimInitialOffsetPosition(dict, 'blunt_enter_lighter', GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION()) | |
local vLighterRotation = GetAnimInitialOffsetRotation(dict, 'blunt_enter_lighter', GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION()) | |
local objTempLighter = CreateObject(`P_CS_LIGHTER_01`, vLighterPosition, true, true, false) | |
SetModelAsNoLongerNeeded(`P_CS_LIGHTER_01`) | |
SetEntityCanBeDamaged(objTempLighter, false) | |
SetEntityCoordsNoOffset(objTempLighter, vLighterPosition) | |
SetEntityRotation(objTempLighter, vLighterRotation) | |
FreezeEntityPosition(objTempLighter, true) | |
serverBD.objLighter = ObjToNet(objTempLighter) | |
RemoveAnimDict(dict) | |
--? Cig / Joint ?-- | |
local eSmokingModel = GET_SMOKING_PROP_NAME() | |
if not HasModelLoaded(eSmokingModel) then | |
repeat | |
Wait(50) | |
RequestModel(eSmokingModel) | |
until HasModelLoaded(eSmokingModel) | |
end | |
local vSmokingPosition = GetAnimInitialOffsetPosition(dict, 'blunt_enter_joint', GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION()) | |
local vSmokingRotation = GetAnimInitialOffsetRotation(dict, 'blunt_enter_joint', GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION()) | |
local objTempCig = CreateObject(eSmokingModel, vSmokingPosition, true, true, false) | |
SetModelAsNoLongerNeeded(eSmokingModel) | |
SetEntityCanBeDamaged(objTempCig, false) | |
SetEntityCoordsNoOffset(objTempCig, vSmokingPosition) | |
SetEntityRotation(objTempCig, vSmokingRotation) | |
FreezeEntityPosition(objTempCig, true) | |
serverBD.objSmoking = ObjToNet(objTempCig) | |
--? Ash Tray ?-- | |
if not HasModelLoaded(`EX_PROP_EXEC_ASHTRAY_01`) then | |
repeat | |
Wait(50) | |
RequestModel(`EX_PROP_EXEC_ASHTRAY_01`) | |
until HasModelLoaded(`EX_PROP_EXEC_ASHTRAY_01`) | |
end | |
local vAshtrayPosition = GetAnimInitialOffsetPosition(dict, 'blunt_enter_ashtray', GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION()) | |
local vAshtrayRotation = GetAnimInitialOffsetRotation(dict, 'blunt_enter_ashtray', GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION()) | |
local objTempAshtray = CreateObject(`EX_PROP_EXEC_ASHTRAY_01`, vAshtrayPosition, true, true, false) | |
SetModelAsNoLongerNeeded(`EX_PROP_EXEC_ASHTRAY_01`) | |
SetEntityCanBeDamaged(objTempAshtray, false) | |
SetEntityCoordsNoOffset(objTempAshtray, vAshtrayPosition) | |
SetEntityRotation(objTempAshtray, vAshtrayRotation) | |
FreezeEntityPosition(objTempAshtray, true) | |
serverBD.objAshtray = ObjToNet(objTempAshtray) | |
end | |
local function IS_PLAYER_IN_SMOKING_AREA(ped) | |
local spot = GET_SMOKING_SCENE_POSITION() | |
local pc = GetEntityCoords(ped) | |
if #(spot - pc) < 1.0 then | |
return true | |
end | |
end | |
local function CleanUp() | |
BitSet = { | |
['SMOKING_ACTIVITY_BS_SPARKS'] = false, | |
['SMOKING_ACTIVITY_BS_FLAME'] = false, | |
['SMOKING_ACTIVITY_BS_SMOKE'] = false, | |
['SMOKING_ACTIVITY_BS_EXHALE_MOUTH'] = false | |
} | |
end | |
local function MAINTAIN_SMOKING_ACTIVITY() | |
local state = sSmokingActivityData.eCurrentState | |
if state == 'SMOKING_ACTIVITY_STATE_INIT' then | |
SET_SMOKING_ACTIVITY_STATE('SMOKING_ACTIVITY_STATE_PROMPT') | |
elseif state == 'SMOKING_ACTIVITY_STATE_PROMPT' then | |
if not IsEntityDead(PlayerPedId()) and IS_PLAYER_IN_SMOKING_AREA(PlayerPedId()) then | |
if NetworkDoesEntityExistWithNetworkId(serverBD.objLighter) and NetworkDoesEntityExistWithNetworkId(serverBD.objAshtray) and NetworkDoesEntityExistWithNetworkId(serverBD.objSmoking) then | |
-- DisplayNotify('BLUNT_ENTER_PC', false, 1000) | |
if IsControlJustReleased(0, 51) then | |
ClearAllHelpMessages() | |
SetPedConfigFlag(PlayerPedId(), 185, true) --PCF_UseKinematicModeWhenStationary | |
SET_SMOKING_ACTIVITY_STATE('SMOKING_ACTIVITY_STATE_WALK') | |
end | |
end | |
end | |
elseif state == 'SMOKING_ACTIVITY_STATE_WALK' then | |
local dict = GET_SMOKING_ACTIVITY_ANIM_DICT() | |
RequestNamedPtfxAsset('scr_safehouse') | |
RequestAnimDict(dict) | |
if RequestScriptAudioBank('SAFEHOUSE_FRANKLIN_SOFA') and HasNamedPtfxAssetLoaded('scr_safehouse') and HasAnimDictLoaded(dict) then | |
local vPlayerPosition = GetAnimInitialOffsetPosition(dict, 'enter', GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION()) | |
local vPlayerRotation = GetAnimInitialOffsetRotation(dict, 'enter', GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION()) | |
TaskGoStraightToCoord(PlayerPedId(), vPlayerPosition.x, vPlayerPosition.y, vPlayerPosition.z, 1.0, 4000, vPlayerRotation.z, 0.05) | |
SET_SMOKING_ACTIVITY_STATE('SMOKING_ACTIVITY_STATE_WALKING_TO_POSITION') | |
end | |
elseif state == 'SMOKING_ACTIVITY_STATE_WALKING_TO_POSITION' then | |
if not NetworkHasControlOfNetworkId(serverBD.objAshtray) then NetworkRequestControlOfNetworkId(serverBD.objAshtray) end | |
if not NetworkHasControlOfNetworkId(serverBD.objLighter) then NetworkRequestControlOfNetworkId(serverBD.objLighter) end | |
if not NetworkHasControlOfNetworkId(serverBD.objSmoking) then NetworkRequestControlOfNetworkId(serverBD.objSmoking) end | |
if GetScriptTaskStatus(PlayerPedId(), `SCRIPT_TASK_GO_STRAIGHT_TO_COORD`) == 7 then | |
sSmokingActivityData.iSyncSceneID = NetworkCreateSynchronisedScene(GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION(), 2, true, false, 1.0, 0.0, 1.0) | |
NetworkAddPedToSynchronisedScene(PlayerPedId(), sSmokingActivityData.iSyncSceneID, GET_SMOKING_ACTIVITY_ANIM_DICT(), 'enter', 2.0, -2.0, 0, 8, 0.0, 0) | |
NetworkStartSynchronisedScene(sSmokingActivityData.iSyncSceneID) | |
SET_SMOKING_ACTIVITY_STATE('SMOKING_ACTIVITY_STATE_WAIT_TO_SIT') | |
end | |
elseif state == 'SMOKING_ACTIVITY_STATE_WAIT_TO_SIT' then | |
--TODO: More network checks but whatever lmao | |
local iSmokingLocalScene = NetworkGetLocalSceneFromNetworkId(sSmokingActivityData.iSyncSceneID) | |
Wait(10) --! VERY IMPORTANT, DO NOT REMOVE !-- | |
if iSmokingLocalScene == -1 or GetSynchronizedScenePhase(iSmokingLocalScene) >= 0.99 then | |
sSmokingActivityData.iSyncSceneID = NetworkCreateSynchronisedScene(GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION(), 2, false, true, 1.0, 0.0, 1.0) | |
NetworkAddPedToSynchronisedScene(PlayerPedId(), sSmokingActivityData.iSyncSceneID, GET_SMOKING_ACTIVITY_ANIM_DICT(), 'base', 2.0, -2.0, 0, 8, 0.0, 0) | |
NetworkStartSynchronisedScene(sSmokingActivityData.iSyncSceneID) | |
SET_SMOKING_ACTIVITY_STATE('SMOKING_ACTIVITY_STATE_IDLE') | |
end | |
elseif state == 'SMOKING_ACTIVITY_STATE_IDLE' then | |
DisplayNotify('BLUNT_HELP_PC') | |
--TODO: More network checks but whatever lmao | |
if not IsEntityPlayingAnim(PlayerPedId(), GET_SMOKING_ACTIVITY_ANIM_DICT(), 'base', 2) then | |
if Debug then print('somehow you fucked up?!?!?!?') end | |
else | |
--? Exit | |
if IsControlJustPressed(0, 202) then | |
ClearAllHelpMessages() | |
sSmokingActivityData.iSyncSceneID = NetworkCreateSynchronisedScene(GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION(), 2, false, false, 1.0, 0.0, 1.0) | |
NetworkAddPedToSynchronisedScene(PlayerPedId(), sSmokingActivityData.iSyncSceneID, GET_SMOKING_ACTIVITY_ANIM_DICT(), 'exit', 2.0, -2.0, 0, 8, 0.0, 0) | |
NetworkStartSynchronisedScene(sSmokingActivityData.iSyncSceneID) | |
sSmokingActivityData.iSyncSceneID = nil | |
-- SET_SMOKING_ACTIVITY_STATE('SMOKING_ACTIVITY_STATE_EXITING') | |
SET_SMOKING_ACTIVITY_STATE('SMOKING_ACTIVITY_STATE_PROMPT') | |
CleanUp() | |
--? Smoke | |
elseif IsControlJustPressed(0, 203) then --? Space | |
ClearAllHelpMessages() | |
sSmokingActivityData.iSyncSceneID = NetworkCreateSynchronisedScene(GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION(), 2, true, false, 1.0, 0.0, 1.0) | |
NetworkAddPedToSynchronisedScene(PlayerPedId(), sSmokingActivityData.iSyncSceneID, GET_SMOKING_ACTIVITY_ANIM_DICT(), 'blunt_enter', 1000.0, -1000.0, 0, 8, 0.0, 0) | |
NetworkAddEntityToSynchronisedScene(NetToObj(serverBD.objAshtray), sSmokingActivityData.iSyncSceneID, GET_SMOKING_ACTIVITY_ANIM_DICT(), 'blunt_enter_ashtray', 1000.0, -1000.0, 8) | |
NetworkAddEntityToSynchronisedScene(NetToObj(serverBD.objSmoking), sSmokingActivityData.iSyncSceneID, GET_SMOKING_ACTIVITY_ANIM_DICT(), 'blunt_enter_joint', 1000.0, -1000.0, 8) | |
NetworkAddEntityToSynchronisedScene(NetToObj(serverBD.objLighter), sSmokingActivityData.iSyncSceneID, GET_SMOKING_ACTIVITY_ANIM_DICT(), 'blunt_enter_lighter', 1000.0, -1000.0, 8) | |
NetworkStartSynchronisedScene(sSmokingActivityData.iSyncSceneID) | |
SET_SMOKING_ACTIVITY_STATE('SMOKING_ACTIVITY_STATE_SMOKING') | |
end | |
end | |
elseif state == 'SMOKING_ACTIVITY_STATE_SMOKING' then | |
--TODO: More network checks but whatever lmao | |
iSmokingLocalScene = NetworkGetLocalSceneFromNetworkId(sSmokingActivityData.iSyncSceneID) | |
if not BitSet['SMOKING_ACTIVITY_BS_SPARKS'] and GetSynchronizedScenePhase(iSmokingLocalScene) > 0.25 then | |
UseParticleFxAsset('scr_safehouse') | |
StartNetworkedParticleFxNonLoopedOnEntity('scr_sh_lighter_sparks', NetToObj(serverBD.objLighter), 0.0, 0.0, 0.05, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0) | |
if Debug then print('Starting scr_sh_lighter_sparks') end | |
BitSet['SMOKING_ACTIVITY_BS_SPARKS'] = true | |
end | |
if not BitSet['SMOKING_ACTIVITY_BS_FLAME'] and GetSynchronizedScenePhase(iSmokingLocalScene) > 0.255 then | |
UseParticleFxAsset('scr_safehouse') | |
print(HasNamedPtfxAssetLoaded('scr_safehouse')) | |
if Debug then print('Starting scr_sh_lighter_flame') end | |
sSmokingActivityData.ptfxLighter = StartNetworkedParticleFxLoopedOnEntity('scr_sh_lighter_flame', NetToObj(serverBD.objLighter), 0.0, 0.0, 0.05, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0) | |
BitSet['SMOKING_ACTIVITY_BS_FLAME'] = true | |
end | |
if DoesParticleFxLoopedExist(sSmokingActivityData.ptfxLighter) and GetSynchronizedScenePhase(iSmokingLocalScene) > 0.45 then | |
StopParticleFxLooped(sSmokingActivityData.ptfxLighter) | |
end | |
if not BitSet['SMOKING_ACTIVITY_BS_SMOKE'] and GetSynchronizedScenePhase(iSmokingLocalScene) > 0.346 then | |
UseParticleFxAsset('scr_safehouse') | |
sSmokingActivityData.ptfxCigarette = StartNetworkedParticleFxLoopedOnEntity('scr_sh_cig_smoke', NetToObj(serverBD.objSmoking), -0.07, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0) | |
if Debug then print('starting scr_sh_cig_smoke', sSmokingActivityData.ptfxCigarette) end | |
BitSet['SMOKING_ACTIVITY_BS_SMOKE'] = true | |
end | |
if not BitSet['SMOKING_ACTIVITY_BS_EXHALE_MOUTH'] and GetSynchronizedScenePhase(iSmokingLocalScene) > 0.82 then | |
UseParticleFxAsset('scr_safehouse') | |
StartNetworkedParticleFxNonLoopedOnPedBone('scr_sh_cig_exhale_mouth', PlayerPedId(), 0.025, 0.13, 0.0, 0.0, 0.0, 0.0, 12844, 1.0, 0.0, 0.0, 0.0) | |
if Debug then print('starting scr_sh_cig_exhale_mouth') end | |
-- IF SHOULD_MAKE_PLAYER_HIGH(sSmokingActivityData.iSmokingActivityID) | |
-- Player_Takes_Weed_Hit(PLAYER_PED_ID()) | |
-- ENDIF | |
BitSet['SMOKING_ACTIVITY_BS_EXHALE_MOUTH'] = true | |
end | |
-- IF NOT IS_BIT_SET(sSmokingActivityData.iBS, SMOKING_ACTIVITY_BS_EXHALE_NOSE) | |
-- AND GET_SYNCHRONIZED_SCENE_PHASE(iSmokingLocalScene) > 0.876 | |
-- USE_PARTICLE_FX_ASSET("scr_safehouse") | |
-- START_NETWORKED_PARTICLE_FX_NON_LOOPED_ON_PED_BONE("scr_sh_cig_exhale_nose", PLAYER_PED_ID(), <<-0.025, 0.12, 0.0>>, << 0.0, 90.0, 0.0>>, BONETAG_HEAD) | |
-- SET_BIT(sSmokingActivityData.iBS, SMOKING_ACTIVITY_BS_EXHALE_NOSE) | |
-- ENDIF | |
if iSmokingLocalScene == -1 or GetSynchronizedScenePhase(iSmokingLocalScene) >= 0.99 then | |
sSmokingActivityData.iSyncSceneID = NetworkCreateSynchronisedScene(GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION(), 2, true, false, 1.0, 0.0, 1.0) | |
NetworkAddPedToSynchronisedScene(PlayerPedId(), sSmokingActivityData.iSyncSceneID, GET_SMOKING_ACTIVITY_ANIM_DICT(), 'blunt_exit', 1000.0, -1000.0, 0, 8, 0.0, 0) | |
NetworkAddEntityToSynchronisedScene(NetToObj(serverBD.objAshtray), sSmokingActivityData.iSyncSceneID, GET_SMOKING_ACTIVITY_ANIM_DICT(), 'blunt_exit_ashtray', 1000.0, -1000.0, 8) | |
NetworkAddEntityToSynchronisedScene(NetToObj(serverBD.objSmoking), sSmokingActivityData.iSyncSceneID, GET_SMOKING_ACTIVITY_ANIM_DICT(), 'blunt_exit_joint', 1000.0, -1000.0, 8) | |
NetworkAddEntityToSynchronisedScene(NetToObj(serverBD.objLighter), sSmokingActivityData.iSyncSceneID, GET_SMOKING_ACTIVITY_ANIM_DICT(), 'blunt_exit_lighter', 1000.0, -1000.0, 8) | |
NetworkStartSynchronisedScene(sSmokingActivityData.iSyncSceneID) | |
SET_SMOKING_ACTIVITY_STATE('SMOKING_ACTIVITY_STATE_EXIT_SMOKING') | |
end | |
elseif state == 'SMOKING_ACTIVITY_STATE_EXIT_SMOKING' then | |
local iSmokingLocalScene = NetworkGetLocalSceneFromNetworkId(sSmokingActivityData.iSyncSceneID) | |
if DoesParticleFxLoopedExist(sSmokingActivityData.ptfxCigarette) and GetSynchronizedScenePhase(iSmokingLocalScene) > 0.27 then | |
StopParticleFxLooped(sSmokingActivityData.ptfxCigarette) | |
end | |
if iSmokingLocalScene == -1 or GetSynchronizedScenePhase(iSmokingLocalScene) >= 0.99 then | |
sSmokingActivityData.iSyncSceneID = NetworkCreateSynchronisedScene(GET_SMOKING_SCENE_POSITION(), GET_SMOKING_SCENE_ROTATION(), 2, false, true, 1.0, 0.0, 1.0) | |
NetworkAddPedToSynchronisedScene(PlayerPedId(), sSmokingActivityData.iSyncSceneID, GET_SMOKING_ACTIVITY_ANIM_DICT(), 'base', 2.0, -2.0, 0, 8, 0.0, 0) | |
NetworkStartSynchronisedScene(sSmokingActivityData.iSyncSceneID) | |
SET_SMOKING_ACTIVITY_STATE('SMOKING_ACTIVITY_STATE_IDLE') | |
CleanUp() | |
end | |
end | |
end | |
CreateThread(function() | |
while true do | |
MAINTAIN_SMOKING_ACTIVITY() | |
Wait(1) | |
end | |
end) | |
RegisterCommand('smoke', function() | |
CREATE_SMOKING_ACTIVITY_PROPS() | |
end) | |
AddEventHandler('onResourceStop', function(resource) | |
if resource == GetCurrentResourceName() then | |
DeleteEntity(NetToObj(serverBD.objLighter)) | |
DeleteEntity(NetToObj(serverBD.objAshtray)) | |
DeleteEntity(NetToObj(serverBD.objSmoking)) | |
if sSmokingActivityData.iSyncSceneID then NetworkStopSynchronisedScene(sSmokingActivityData.iSyncSceneID) end | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment