Files
esx_core/client/main.lua
T
2018-06-22 15:06:01 +02:00

167 lines
4.7 KiB
Lua

local holdingup = false
local store = ""
local blipRobbery = nil
ESX = nil
local Keys = {
["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
}
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
function DisplayHelpText(str)
SetTextComponentFormat("STRING")
AddTextComponentString(str)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
end
function drawTxt(x,y ,width,height,scale, text, r,g,b,a, outline)
SetTextFont(0)
SetTextProportional(0)
SetTextScale(scale, scale)
SetTextColour(r, g, b, a)
SetTextDropShadow(0, 0, 0, 0,255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
if(outline)then
SetTextOutline()
end
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(x - width/2, y - height/2 + 0.005)
end
RegisterNetEvent('esx_holdup:currentlyrobbing')
AddEventHandler('esx_holdup:currentlyrobbing', function(robb)
holdingup = true
store = robb
end)
RegisterNetEvent('esx_holdup:killblip')
AddEventHandler('esx_holdup:killblip', function()
RemoveBlip(blipRobbery)
end)
RegisterNetEvent('esx_holdup:setblip')
AddEventHandler('esx_holdup:setblip', function(position)
blipRobbery = AddBlipForCoord(position.x, position.y, position.z)
SetBlipSprite(blipRobbery , 161)
SetBlipScale(blipRobbery , 2.0)
SetBlipColour(blipRobbery, 3)
PulseBlip(blipRobbery)
end)
RegisterNetEvent('esx_holdup:toofarlocal')
AddEventHandler('esx_holdup:toofarlocal', function()
holdingup = false
ESX.ShowNotification(_U('robbery_cancelled'))
robbingName = ""
incircle = false
end)
RegisterNetEvent('esx_holdup:robberycomplete')
AddEventHandler('esx_holdup:robberycomplete', function(award)
holdingup = false
ESX.ShowNotification(_U('robbery_complete', award))
store = ""
incircle = false
end)
RegisterNetEvent('esx_holdup:starttimer')
AddEventHandler('esx_holdup:starttimer', function()
timer = Stores[store].secondsRemaining
Citizen.CreateThread(function()
while timer > 0 do
Citizen.Wait(0)
Citizen.Wait(1000)
if(timer > 0)then
timer = timer - 1
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if holdingup then
drawTxt(0.66, 1.44, 1.0,1.0,0.4, _U('robbery_timer', timer), 255, 255, 255, 255)
else
Citizen.Wait(1000)
end
end
end)
end)
Citizen.CreateThread(function()
for k,v in pairs(Stores)do
local ve = v.position
local blip = AddBlipForCoord(ve.x, ve.y, ve.z)
SetBlipSprite(blip, 156)
SetBlipScale(blip, 0.8)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(_U('shop_robbery'))
EndTextCommandSetBlipName(blip)
end
end)
incircle = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local pos = GetEntityCoords(GetPlayerPed(-1), true)
for k,v in pairs(Stores)do
local pos2 = v.position
if(Vdist(pos.x, pos.y, pos.z, pos2.x, pos2.y, pos2.z) < 15.0)then
if not holdingup then
DrawMarker(1, v.position.x, v.position.y, v.position.z - 1, 0, 0, 0, 0, 0, 0, 1.0001, 1.0001, 1.5001, 1555, 0, 0,255, 0, 0, 0,0)
if(Vdist(pos.x, pos.y, pos.z, pos2.x, pos2.y, pos2.z) < 1.0)then
if (incircle == false) then
DisplayHelpText(_U('press_to_rob', v.nameofstore))
end
incircle = true
if IsControlJustReleased(0, Keys['E']) then
if IsPedArmed(GetPlayerPed(-1), 4) then
TriggerServerEvent('esx_holdup:rob', k)
else
ESX.ShowNotification(_U('no_threat'))
end
end
elseif(Vdist(pos.x, pos.y, pos.z, pos2.x, pos2.y, pos2.z) > 1.0)then
incircle = false
end
end
end
end
if holdingup then
local pos2 = Stores[store].position
if(Vdist(pos.x, pos.y, pos.z, pos2.x, pos2.y, pos2.z) > 13)then
TriggerServerEvent('esx_holdup:toofar', store)
end
end
end
end)