• Source
    1.  
    2.  
    3. function tvRP.teleport(x,y,z)
    4. tvRP.unjail() -- force unjail before a teleportation
    5. SetEntityCoords(GetPlayerPed(-1), x+0.0001, y+0.0001, z+0.0001, 1,0,0,1)
    6. vRPserver.updatePos({x,y,z})
    7. end
    8.  
    9. -- return x,y,z
    10. function tvRP.getPosition()
    11. local x,y,z = table.unpack(GetEntityCoords(GetPlayerPed(-1),true))
    12. return x,y,z
    13. end
    14.  
    15. function tvRP.serStamina(value)
    16. local x,y,z = table.unpack(GetEntityCoords(GetPlayerPed(-1),true))
    17. return x,y,z
    18. end
    19.  
    20.  
    21. -- return false if in exterior, true if inside a building
    22. function tvRP.isInside()
    23. local x,y,z = tvRP.getPosition()
    24. return not (GetInteriorAtCoords(x,y,z) == 0)
    25. end
    26.  
    27. -- return vx,vy,vz
    28. function tvRP.getSpeed()
    29. local vx,vy,vz = table.unpack(GetEntityVelocity(GetPlayerPed(-1)))
    30. return math.sqrt(vx*vx+vy*vy+vz*vz)
    31. end
    32.  
    33. function tvRP.getCamDirection()
    34. local heading = GetGameplayCamRelativeHeading()+GetEntityHeading(GetPlayerPed(-1))
    35. local pitch = GetGameplayCamRelativePitch()
    36.  
    37. local x = -math.sin(heading*math.pi/180.0)
    38. local y = math.cos(heading*math.pi/180.0)
    39. local z = math.sin(pitch*math.pi/180.0)
    40.  
    41. -- normalize
    42. local len = math.sqrt(x*x+y*y+z*z)
    43. if len ~= 0 then
    44. x = x/len
    45. y = y/len
    46. z = z/len
    47. end
    48.  
    49. return x,y,z
    50. end
    51.  
    52. function tvRP.addPlayer(player)
    53. players[player] = true
    54. end
    55.  
    56. function tvRP.removePlayer(player)
    57. players[player] = nil
    58. end
    59.  
    60. function tvRP.getNearestPlayers(radius)
    61. local r = {}
    62.  
    63. local ped = GetPlayerPed(i)
    64. local pid = PlayerId()
    65. local px,py,pz = tvRP.getPosition()
    66.  
    67. for k,v in pairs(players) do
    68. local player = GetPlayerFromServerId(k)
    69.  
    70. if v and player ~= pid and NetworkIsPlayerConnected(player) then
    71. local oped = GetPlayerPed(player)
    72. local x,y,z = table.unpack(GetEntityCoords(oped,true))
    73. local distance = GetDistanceBetweenCoords(x,y,z,px,py,pz,true)
    74. if distance <= radius then
    75. r[GetPlayerServerId(player)] = distance
    76. end
    77. end
    78. end
    79.  
    80. return r
    81. end
    82.  
    83. function tvRP.getNearestPlayer(radius)
    84. local p = nil
    85.  
    86. local players = tvRP.getNearestPlayers(radius)
    87. local min = radius+10.0
    88. for k,v in pairs(players) do
    89. if v < min then
    90. min = v
    91. p = k
    92. end
    93. end
    94.  
    95. return p
    96. end
    97.  
    98. function tvRP.notify(msg)
    99. SetNotificationTextEntry("STRING")
    100. AddTextComponentString(msg)
    101. DrawNotification(true, false)
    102. --exports.pNotify:SendNotification({text = msg, type = "info", timeout = 4000, layout = "centerRight", queue = "right"})
    103. end
    104.  
    105. -- SCREEN
    106.  
    107. -- play a screen effect
    108. -- name, see https://wiki.fivem.net/wiki/Screen_Effects
    109. -- duration: in seconds, if -1, will play until stopScreenEffect is called
    110. function tvRP.playScreenEffect(name, duration)
    111. if duration < 0 then -- loop
    112. StartScreenEffect(name, 0, true)
    113. else
    114. StartScreenEffect(name, 0, true)
    115.  
    116. Citizen.CreateThread(function() -- force stop the screen effect after duration+1 seconds
    117. Citizen.Wait(math.floor((duration+1)*1000))
    118. StopScreenEffect(name)
    119. end)
    120. end
    121. end
    122.  
    123. -- stop a screen effect
    124. -- name, see https://wiki.fivem.net/wiki/Screen_Effects
    125. function tvRP.stopScreenEffect(name)
    126. StopScreenEffect(name)
    127. end
    128.  
    129. -- ANIM
    130.  
    131. -- animations dict and names: http://docs.ragepluginhook.net/html/62951c37-a440-478c-b389-c471230ddfc5.htm
    132.  
    133. local anims = {}
    134. local anim_ids = Tools.newIDGenerator()
    135.  
    136. -- play animation (new version)
    137. -- upper: true, only upper body, false, full animation
    138. -- seq: list of animations as {dict,anim_name,loops} (loops is the number of loops, default 1) or a task def (properties: task, play_exit)
    139. -- looping: if true, will infinitely loop the first element of the sequence until stopAnim is called
    140. function tvRP.playAnim(upper, seq, looping)
    141. if seq.task ~= nil then -- is a task (cf https://github.com/ImagicTheCat/vRP/pull/118)
    142. DeleteEntity(phoneProp)
    143. tvRP.stopAnim(true)
    144.  
    145. local ped = GetPlayerPed(-1)
    146. if seq.task == "PROP_HUMAN_SEAT_CHAIR_MP_PLAYER" then -- special case, sit in a chair
    147. local x,y,z = tvRP.getPosition()
    148. TaskStartScenarioAtPosition(ped, seq.task, x, y, z-1, GetEntityHeading(ped), 0, 0, false)
    149. else
    150. TaskStartScenarioInPlace(ped, seq.task, 0, not seq.play_exit)
    151. end
    152. else -- a regular animation sequence
    153. tvRP.stopAnim(upper)
    154.  
    155. local flags = 0
    156. if upper then flags = flags+48 end
    157. if looping then flags = flags+1 end
    158.  
    159. Citizen.CreateThread(function()
    160. -- prepare unique id to stop sequence when needed
    161. local id = anim_ids:gen()
    162. anims[id] = true
    163.  
    164. for k,v in pairs(seq) do
    165. local dict = v[1]
    166. local name = v[2]
    167. local loops = v[3] or 1
    168.  
    169. for i=1,loops do
    170. if anims[id] then -- check animation working
    171. local first = (k == 1 and i == 1)
    172. local last = (k == #seq and i == loops)
    173.  
    174. -- request anim dict
    175. RequestAnimDict(dict)
    176. local i = 0
    177. while not HasAnimDictLoaded(dict) and i < 1000 do -- max time, 10 seconds
    178. Citizen.Wait(10)
    179. RequestAnimDict(dict)
    180. i = i+1
    181. end
    182.  
    183. -- play anim
    184. if HasAnimDictLoaded(dict) and anims[id] then
    185. local inspeed = 8.0001
    186. local outspeed = -8.0001
    187. if not first then inspeed = 2.0001 end
    188. if not last then outspeed = 2.0001 end
    189.  
    190. TaskPlayAnim(GetPlayerPed(-1),dict,name,inspeed,outspeed,-1,flags,0,0,0,0)
    191. end
    192.  
    193. Citizen.Wait(0)
    194. while GetEntityAnimCurrentTime(GetPlayerPed(-1),dict,name) <= 0.95 and IsEntityPlayingAnim(GetPlayerPed(-1),dict,name,3) and anims[id] do
    195. Citizen.Wait(0)
    196. end
    197. end
    198. end
    199. end
    200.  
    201. -- free id
    202. anim_ids:free(id)
    203. anims[id] = nil
    204. end)
    205. end
    206. end
    207.  
    208. -- stop animation (new version)
    209. -- upper: true, stop the upper animation, false, stop full animations
    210. function tvRP.stopAnim(upper)
    211. anims = {} -- stop all sequences
    212. if upper then
    213. ClearPedSecondaryTask(GetPlayerPed(-1))
    214. else
    215. ClearPedTasks(GetPlayerPed(-1))
    216. end
    217. end
    218.  
    219. -- RAGDOLL
    220. local ragdoll = false
    221.  
    222. -- set player ragdoll flag (true or false)
    223. function tvRP.setRagdoll(flag)
    224. ragdoll = flag
    225. end
    226.  
    227. -- ragdoll thread
    228. Citizen.CreateThread(function()
    229. while true do
    230. Citizen.Wait(10)
    231. if ragdoll then
    232. SetPedToRagdoll(GetPlayerPed(-1), 1000, 1000, 0, 0, 0, 0)
    233. end
    234. end
    235. end)
    236.  
    237. -- SOUND
    238. -- some lists:
    239. -- pastebin.com/A8Ny8AHZ
    240. -- https://wiki.gtanet.work/index.php?title=FrontEndSoundlist
    241.  
    242. -- play sound at a specific position
    243. function tvRP.playSpatializedSound(dict,name,x,y,z,range)
    244. PlaySoundFromCoord(-1,name,x+0.0001,y+0.0001,z+0.0001,dict,0,range+0.0001,0)
    245. end
    246.  
    247. -- play sound
    248. function tvRP.playSound(dict,name)
    249. PlaySound(-1,name,dict,0,0,1)
    250. end
    251.  
    252. function tvRP.setDrunk(player)
    253. SetPedIsDrunk(player, true)
    254. SetPedMovementClipset(player, "MOVE_M@DRUNK@SLIGHTLYDRUNK", true)
    255. SetTimeout(60000, function()
    256. ResetPedMovementClipset(player, 0)
    257. SetPedIsDrunk(player, false)
    258. end)
    259. end
    260.  
    261. function tvRP.setDrugged(player)
    262. DoScreenFadeOut(500)
    263. Citizen.Wait(500)
    264. --vRPclient.playScreenEffect("DrugsDrivingIn", 60)
    265. SetTimecycleModifier("spectator5")
    266. SetPedMotionBlur(player, true)
    267. Citizen.Wait(500)
    268. DoScreenFadeIn(1500)
    269.  
    270. SetTimeout(60000, function()
    271. SetPedMotionBlur(player, false)
    272. ClearTimecycleModifier()
    273. end)
    274. end
    275.  
    276. function tvRP.setSpeedboost(player)
    277. SetRunSprintMultiplierForPlayer(player, 1.2)
    278. SetSwimMultiplierForPlayer(player, 1.2)
    279. SetTimeout(120000, function()
    280. SetRunSprintMultiplierForPlayer(player, 1.0)
    281. SetSwimMultiplierForPlayer(player, 1.0)
    282. end)
    283. end
    284.  
    285. function tvRP.setStaminaboost(player)
    286. local staminaboost = true
    287. while (staminaboost == true) do
    288. RestorePlayerStamina(player, 1.0)
    289. end
    290.  
    291. SetTimeout(120000, function()
    292. staminaboost = false
    293. end)
    294. end
    295.  
    296.  
    297. -- events
    298.  
    299. AddEventHandler("playerSpawned",function()
    300. TriggerServerEvent("vRPcli:playerSpawned")
    301. end)
    302.  
    303. AddEventHandler("onPlayerDied",function(player,reason)
    304. TriggerServerEvent("vRPcli:playerDied")
    305. end)
    306.  
    307. AddEventHandler("onPlayerKilled",function(player,killer,reason)
    308. TriggerServerEvent("vRPcli:playerDied")
    309. end)
    310.  
    311. function tvRP.useLockpick(player)
    312. Citizen.CreateThread(function()
    313. Citizen.Wait(1)
    314. local plyCoords = GetEntityCoords(GetPlayerPed(-1), 0)
    315. veh = GetClosestVehicle(plyCoords["x"], plyCoords["y"], plyCoords["z"], 5.001, 0, 70)
    316. if veh then
    317. TaskPlayAnim(GetPlayerPed(-1),"mini@repair","fixing_a_player", 8.0, 0.0, -1, 1, 0, 0, 0, 0)
    318. StartVehicleAlarm(veh)
    319. Citizen.Wait(20000)
    320. SetVehicleDoorsLocked(veh, 1)
    321. ClearPedTasksImmediately(GetPlayerPed(-1))
    322. end
    323. end)
    324. end
    325.  
    326. local voice = "base"
    327. local voicetitle = "обычная"
    328.  
    329. -- voice proximity computation
    330. Citizen.CreateThread(function()
    331. while true do
    332. Citizen.Wait(1)
    333.  
    334. local proximity = 20.0
    335.  
    336. if IsControlJustPressed(1, 182) then
    337. if voice == "base" then
    338. voice = "short"
    339. voicetitle = "ближняя"
    340. proximity = 5.0
    341. else
    342. voice = "base"
    343. voicetitle = "обычная"
    344. proximity = 20.0
    345. end
    346. end
    347.  
    348. SetTextFont(0)
    349. SetTextProportional(1)
    350. SetTextScale(0.0, 0.30)
    351. SetTextColour(255, 255, 255, 255)
    352. SetTextDropshadow(0, 0, 0, 0, 255)
    353. SetTextEdge(1, 0, 0, 0, 255)
    354. SetTextDropShadow()
    355. SetTextOutline()
    356. SetTextEntry("STRING")
    357. AddTextComponentString("Слышимость: "..voicetitle)
    358. DrawText(0.15, 0.94)
    359.  
    360.  
    361. if IsPedSittingInAnyVehicle(ped) then
    362. local veh = GetVehiclePedIsIn(ped,false)
    363. local hash = GetEntityModel(veh)
    364.  
    365. if IsThisModelACar(hash) or IsThisModelAHeli(hash) or IsThisModelAPlane(hash) then
    366. if voice == "short" then
    367. proximity = 5.0
    368. else
    369. proximity = 10.0
    370. end
    371. end
    372.  
    373. elseif tvRP.isInside() then
    374. if voice == "short" then
    375. proximity = 3.0
    376. else
    377. proximity = 7.0
    378. end
    379. end
    380.  
    381. NetworkSetTalkerProximity(proximity+0.0001)
    382. end
    383. end)
    384.  
    385. Citizen.CreateThread(function()
    386. while true do
    387. Citizen.Wait(1)
    388. local ped = GetPlayerPed(-1)
    389. local radius = 5
    390. local x,y,z = table.unpack(GetEntityCoords(ped,true))
    391.  
    392. local veh = GetClosestVehicle(x+0.0001,y+0.0001,z+0.0001, radius+0.0001, 0, 8192+4096+4+2+1) -- boats, helicos
    393. if not IsEntityAVehicle(veh) then veh = GetClosestVehicle(x+0.0001,y+0.0001,z+0.0001, radius+0.0001, 0, 4+2+1) end -- cars
    394. if veh ~= false then
    395. SetVehicleAutomaticallyAttaches(veh, 1, 0)
    396. end
    397. end
    398. end)
    399.