function tvRP.teleport(x,y,z)
tvRP.unjail() -- force unjail before a teleportation
SetEntityCoords(GetPlayerPed(-1), x+0.0001, y+0.0001, z+0.0001, 1,0,0,1)
vRPserver.updatePos({x,y,z})
end
-- return x,y,z
function tvRP.getPosition()
local x,y,z = table.unpack(GetEntityCoords(GetPlayerPed(-1),true))
return x,y,z
end
function tvRP.serStamina(value)
local x,y,z = table.unpack(GetEntityCoords(GetPlayerPed(-1),true))
return x,y,z
end
-- return false if in exterior, true if inside a building
function tvRP.isInside()
local x,y,z = tvRP.getPosition()
return not (GetInteriorAtCoords(x,y,z) == 0)
end
-- return vx,vy,vz
function tvRP.getSpeed()
local vx,vy,vz = table.unpack(GetEntityVelocity(GetPlayerPed(-1)))
return math.sqrt(vx*vx+vy*vy+vz*vz)
end
function tvRP.getCamDirection()
local heading = GetGameplayCamRelativeHeading()+GetEntityHeading(GetPlayerPed(-1))
local pitch = GetGameplayCamRelativePitch()
local x = -math.sin(heading*math.pi/180.0)
local y = math.cos(heading*math.pi/180.0)
local z = math.sin(pitch*math.pi/180.0)
-- normalize
local len = math.sqrt(x*x+y*y+z*z)
if len ~= 0 then
x = x/len
y = y/len
z = z/len
end
return x,y,z
end
function tvRP.addPlayer(player)
players[player] = true
end
function tvRP.removePlayer(player)
players[player] = nil
end
function tvRP.getNearestPlayers(radius)
local r = {}
local ped = GetPlayerPed(i)
local pid = PlayerId()
local px,py,pz = tvRP.getPosition()
for k,v in pairs(players) do
local player = GetPlayerFromServerId(k)
if v and player ~= pid and NetworkIsPlayerConnected(player) then
local oped = GetPlayerPed(player)
local x,y,z = table.unpack(GetEntityCoords(oped,true))
local distance = GetDistanceBetweenCoords(x,y,z,px,py,pz,true)
if distance <= radius then
r[GetPlayerServerId(player)] = distance
end
end
end
return r
end
function tvRP.getNearestPlayer(radius)
local p = nil
local players = tvRP.getNearestPlayers(radius)
local min = radius+10.0
for k,v in pairs(players) do
if v < min then
min = v
p = k
end
end
return p
end
function tvRP.notify(msg)
SetNotificationTextEntry("STRING")
AddTextComponentString(msg)
DrawNotification(true, false)
--exports.pNotify:SendNotification({text = msg, type = "info", timeout = 4000, layout = "centerRight", queue = "right"})
end
-- SCREEN
-- play a screen effect
-- name, see https://wiki.fivem.net/wiki/Screen_Effects
-- duration: in seconds, if -1, will play until stopScreenEffect is called
function tvRP.playScreenEffect(name, duration)
if duration < 0 then -- loop
StartScreenEffect(name, 0, true)
else
StartScreenEffect(name, 0, true)
Citizen.CreateThread(function() -- force stop the screen effect after duration+1 seconds
Citizen.Wait(math.floor((duration+1)*1000))
StopScreenEffect(name)
end)
end
end
-- stop a screen effect
-- name, see https://wiki.fivem.net/wiki/Screen_Effects
function tvRP.stopScreenEffect(name)
StopScreenEffect(name)
end
-- ANIM
-- animations dict and names: http://docs.ragepluginhook.net/html/62951c37-a440-478c-b389-c471230ddfc5.htm
local anims = {}
local anim_ids = Tools.newIDGenerator()
-- play animation (new version)
-- upper: true, only upper body, false, full animation
-- 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)
-- looping: if true, will infinitely loop the first element of the sequence until stopAnim is called
function tvRP.playAnim(upper, seq, looping)
if seq.task ~= nil then -- is a task (cf https://github.com/ImagicTheCat/vRP/pull/118)
DeleteEntity(phoneProp)
tvRP.stopAnim(true)
local ped = GetPlayerPed(-1)
if seq.task == "PROP_HUMAN_SEAT_CHAIR_MP_PLAYER" then -- special case, sit in a chair
local x,y,z = tvRP.getPosition()
TaskStartScenarioAtPosition(ped, seq.task, x, y, z-1, GetEntityHeading(ped), 0, 0, false)
else
TaskStartScenarioInPlace(ped, seq.task, 0, not seq.play_exit)
end
else -- a regular animation sequence
tvRP.stopAnim(upper)
local flags = 0
if upper then flags = flags+48 end
if looping then flags = flags+1 end
Citizen.CreateThread(function()
-- prepare unique id to stop sequence when needed
local id = anim_ids:gen()
anims[id] = true
for k,v in pairs(seq) do
local dict = v[1]
local name = v[2]
local loops = v[3] or 1
for i=1,loops do
if anims[id] then -- check animation working
local first = (k == 1 and i == 1)
local last = (k == #seq and i == loops)
-- request anim dict
RequestAnimDict(dict)
local i = 0
while not HasAnimDictLoaded(dict) and i < 1000 do -- max time, 10 seconds
Citizen.Wait(10)
RequestAnimDict(dict)
i = i+1
end
-- play anim
if HasAnimDictLoaded(dict) and anims[id] then
local inspeed = 8.0001
local outspeed = -8.0001
if not first then inspeed = 2.0001 end
if not last then outspeed = 2.0001 end
TaskPlayAnim(GetPlayerPed(-1),dict,name,inspeed,outspeed,-1,flags,0,0,0,0)
end
Citizen.Wait(0)
while GetEntityAnimCurrentTime(GetPlayerPed(-1),dict,name) <= 0.95 and IsEntityPlayingAnim(GetPlayerPed(-1),dict,name,3) and anims[id] do
Citizen.Wait(0)
end
end
end
end
-- free id
anim_ids:free(id)
anims[id] = nil
end)
end
end
-- stop animation (new version)
-- upper: true, stop the upper animation, false, stop full animations
function tvRP.stopAnim(upper)
anims = {} -- stop all sequences
if upper then
ClearPedSecondaryTask(GetPlayerPed(-1))
else
ClearPedTasks(GetPlayerPed(-1))
end
end
-- RAGDOLL
local ragdoll = false
-- set player ragdoll flag (true or false)
function tvRP.setRagdoll(flag)
ragdoll = flag
end
-- ragdoll thread
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
if ragdoll then
SetPedToRagdoll(GetPlayerPed(-1), 1000, 1000, 0, 0, 0, 0)
end
end
end)
-- SOUND
-- some lists:
-- pastebin.com/A8Ny8AHZ
-- https://wiki.gtanet.work/index.php?title=FrontEndSoundlist
-- play sound at a specific position
function tvRP.playSpatializedSound(dict,name,x,y,z,range)
PlaySoundFromCoord(-1,name,x+0.0001,y+0.0001,z+0.0001,dict,0,range+0.0001,0)
end
-- play sound
function tvRP.playSound(dict,name)
PlaySound(-1,name,dict,0,0,1)
end
function tvRP.setDrunk(player)
SetPedIsDrunk(player, true)
SetPedMovementClipset(player, "MOVE_M@DRUNK@SLIGHTLYDRUNK", true)
SetTimeout(60000, function()
ResetPedMovementClipset(player, 0)
SetPedIsDrunk(player, false)
end)
end
function tvRP.setDrugged(player)
DoScreenFadeOut(500)
Citizen.Wait(500)
--vRPclient.playScreenEffect("DrugsDrivingIn", 60)
SetTimecycleModifier("spectator5")
SetPedMotionBlur(player, true)
Citizen.Wait(500)
DoScreenFadeIn(1500)
SetTimeout(60000, function()
SetPedMotionBlur(player, false)
ClearTimecycleModifier()
end)
end
function tvRP.setSpeedboost(player)
SetRunSprintMultiplierForPlayer(player, 1.2)
SetSwimMultiplierForPlayer(player, 1.2)
SetTimeout(120000, function()
SetRunSprintMultiplierForPlayer(player, 1.0)
SetSwimMultiplierForPlayer(player, 1.0)
end)
end
function tvRP.setStaminaboost(player)
local staminaboost = true
while (staminaboost == true) do
RestorePlayerStamina(player, 1.0)
end
SetTimeout(120000, function()
staminaboost = false
end)
end
-- events
AddEventHandler("playerSpawned",function()
TriggerServerEvent("vRPcli:playerSpawned")
end)
AddEventHandler("onPlayerDied",function(player,reason)
TriggerServerEvent("vRPcli:playerDied")
end)
AddEventHandler("onPlayerKilled",function(player,killer,reason)
TriggerServerEvent("vRPcli:playerDied")
end)
function tvRP.useLockpick(player)
Citizen.CreateThread(function()
Citizen.Wait(1)
local plyCoords = GetEntityCoords(GetPlayerPed(-1), 0)
veh = GetClosestVehicle(plyCoords["x"], plyCoords["y"], plyCoords["z"], 5.001, 0, 70)
if veh then
TaskPlayAnim(GetPlayerPed(-1),"mini@repair","fixing_a_player", 8.0, 0.0, -1, 1, 0, 0, 0, 0)
StartVehicleAlarm(veh)
Citizen.Wait(20000)
SetVehicleDoorsLocked(veh, 1)
ClearPedTasksImmediately(GetPlayerPed(-1))
end
end)
end
local voice = "base"
local voicetitle = "обычная"
-- voice proximity computation
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local proximity = 20.0
if IsControlJustPressed(1, 182) then
if voice == "base" then
voice = "short"
voicetitle = "ближняя"
proximity = 5.0
else
voice = "base"
voicetitle = "обычная"
proximity = 20.0
end
end
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.0, 0.30)
SetTextColour(255, 255, 255, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
AddTextComponentString("Слышимость: "..voicetitle)
DrawText(0.15, 0.94)
if IsPedSittingInAnyVehicle(ped) then
local veh = GetVehiclePedIsIn(ped,false)
local hash = GetEntityModel(veh)
if IsThisModelACar(hash) or IsThisModelAHeli(hash) or IsThisModelAPlane(hash) then
if voice == "short" then
proximity = 5.0
else
proximity = 10.0
end
end
elseif tvRP.isInside() then
if voice == "short" then
proximity = 3.0
else
proximity = 7.0
end
end
NetworkSetTalkerProximity(proximity+0.0001)
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local ped = GetPlayerPed(-1)
local radius = 5
local x,y,z = table.unpack(GetEntityCoords(ped,true))
local veh = GetClosestVehicle(x+0.0001,y+0.0001,z+0.0001, radius+0.0001, 0, 8192+4096+4+2+1) -- boats, helicos
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
if veh ~= false then
SetVehicleAutomaticallyAttaches(veh, 1, 0)
end
end
end)