Initial public push (WIP)

This commit is contained in:
ElPumpo
2018-08-04 16:08:24 +02:00
parent 874735443e
commit 8c1494d5c7
7 changed files with 485 additions and 1 deletions
+42 -1
View File
@@ -1,2 +1,43 @@
# esx_boat
Boat shop and garage for ESX
Adds boat shops and boat garages around San Andreas. Unlike esx_vehicleshop this script isn't built around a job.
## Requirements
- [esx_vehicleshop](https://github.com/ESX-Org/esx_vehicleshop)
## Download & Installation
### Using [fvm](https://github.com/qlaffont/fvm-installer)
```
fvm install --save --folder=esx esx-org/esx_boat
```
### Using Git
```
cd resources
git clone https://github.com/ESX-Org/esx_boat [esx]/esx_boat
```
### Manually
- Download https://github.com/ESX-Org/esx_boat/archive/master.zip
- Put it in the `[esx]` directory
## Installation
- Import `esx_boat.sql` in your database
- Add this to your `server.cfg`:
```
start esx_boat
```
# Legal
### License
esx_boat - Boat shop and garage for ESX
Copyright (C) 2015-2018 Jérémie N'gadi
This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version.
This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details.
You should have received a copy Of the GNU General Public License along with this program. If Not, see http://www.gnu.org/licenses/.
+26
View File
@@ -0,0 +1,26 @@
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
description 'ESX Boat'
version '0.1.0'
server_scripts {
'@mysql-async/lib/MySQL.lua',
'@es_extended/locale.lua',
'locales/en.lua',
'config.lua',
'server/main.lua'
}
client_scripts {
'@es_extended/locale.lua',
'locales/en.lua',
'config.lua',
'client/main.lua',
'client/marker.lua'
}
dependencies {
'es_extended',
'esx_vehicleshop'
}
+169
View File
@@ -0,0 +1,169 @@
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
}
ESX = nil
isInShopMenu = false
local spawnedVehicles = {}
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
while ESX.GetPlayerData() == nil do
print('playerdata nil!! (boat)')
Citizen.Wait(10)
end
ESX.PlayerData = ESX.GetPlayerData()
end)
function OpenBoatShop(shop)
isInShopMenu = true
local playerPed = PlayerPedId()
local elements = {}
for i=1, #Config.Vehicles, 1 do
table.insert(elements, {
label = (string.format ('%s - <span style="color: green;">$%i</span>', Config.Vehicles[i].label, Config.Vehicles[i].price)),
name = Config.Vehicles[i].label,
model = Config.Vehicles[i].model,
price = Config.Vehicles[i].price,
})
end
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'boat_shop',
{
title = _U('boat_shop'),
align = 'top-left',
elements = elements
}, function (data, menu)
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'boat_shop_confirm',
{
title = _U('boat_shop_confirm', data.current.name, data.current.price),
align = 'top-left',
elements = {
{ label = _U('confirm_no'), value = 'no' },
{ label = _U('confirm_yes'), value = 'yes' }
}
}, function (data2, menu2)
if data2.current.value == 'yes' then
local plate = exports['esx_vehicleshop']:GeneratePlate()
local vehicle = GetVehiclePedIsIn(playerPed, false)
local props = ESX.Game.GetVehicleProperties(vehicle)
props.plate = plate
print(props.model)
ESX.TriggerServerCallback('esx_boat:buyBoat', function (bought)
if bought then
ESX.ShowNotification(_U('boat_shop_bought', data.current.model, data.current.price))
DeleteSpawnedVehicles()
ESX.UI.Menu.CloseAll()
CurrentAction = 'boat_shop'
CurrentActionMsg = _U('boat_shop_open')
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
SetEntityCoords(playerPed, shop.Outside.x, shop.Outside.y, shop.Outside.z)
else
ESX.ShowNotification(_U('boat_shop_nomoney'))
menu2.close()
end
end, props, data.current.model)
else
menu2.close()
end
end, function (data2, menu2)
menu2.close()
end)
end, function (data, menu)
-- exit menu
menu.close()
DeleteSpawnedVehicles()
CurrentAction = 'boat_shop'
CurrentActionMsg = _U('boat_shop_open')
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
SetEntityCoords(playerPed, shop.Outside.x, shop.Outside.y, shop.Outside.z)
end, function (data, menu)
DeleteSpawnedVehicles()
ESX.Game.SpawnLocalVehicle(data.current.model, shop.Inside, shop.Heading, function (vehicle)
table.insert(spawnedVehicles, vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
FreezeEntityPosition(vehicle, true)
end)
end, function (data, menu)
end)
-- spawn first vehicle
DeleteSpawnedVehicles()
ESX.Game.SpawnLocalVehicle(Config.Vehicles[1].model, shop.Inside, shop.Heading, function (vehicle)
table.insert(spawnedVehicles, vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
FreezeEntityPosition(vehicle, true)
end)
end
-- Key controls
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
if isInShopMenu then
DisableControlAction(0, 75, true) -- Disable exit vehicle
DisableControlAction(27, 75, true) -- Disable exit vehicle
else
Citizen.Wait(500)
end
end
end)
function DeleteSpawnedVehicles()
while #spawnedVehicles > 0 do
local vehicle = spawnedVehicles[1]
ESX.Game.DeleteVehicle(vehicle)
table.remove(spawnedVehicles, 1)
end
end
AddEventHandler('onResourceStop', function(resource)
--if resource == GetCurrentResourceName() and ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'boat_shop') then
ESX.UI.Menu.CloseAll()
-- end
end)
+129
View File
@@ -0,0 +1,129 @@
local HasAlreadyEnteredMarker = false
local LastZone = nil
CurrentAction = nil
CurrentActionMsg = ''
CurrentActionData = {}
-- Key controls
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
if CurrentAction == nil then
Citizen.Wait(200)
else
ESX.ShowHelpNotification(CurrentActionMsg)
if IsControlJustReleased(0, Keys['E']) then
if CurrentAction == 'boat_shop' then
OpenBoatShop(Config.Zones.BoatShops[CurrentActionData.zoneNum])
end
CurrentAction = nil
end
end
end
end)
AddEventHandler('esx_boat:hasEnteredMarker', function(zone, zoneNum)
print(zone)
print(zoneNum)
if zone == 'boat_shop' then
CurrentAction = 'boat_shop'
CurrentActionMsg = _U('boat_shop_open')
CurrentActionData = { zoneNum = zoneNum }
end
end)
AddEventHandler('esx_boat:hasExitedMarker', function()
if not isInShopMenu then
ESX.UI.Menu.CloseAll()
end
CurrentAction = nil
end)
-- Draw markers
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
for i=1, #Config.Zones.BoatShops, 1 do
local zone = Config.Zones.BoatShops[i].Outside
if GetDistanceBetweenCoords(coords, zone.x, zone.y, zone.z, true) < Config.DrawDistance then
DrawMarker(Config.MarkerType, zone.x, zone.y, zone.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.MarkerSize.x, Config.MarkerSize.y, Config.MarkerSize.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, false, false, false)
end
end
end
end)
-- Enter / Exit marker events
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local isInMarker = false
local currentZone = nil
local currentZoneNum = nil
for i=1, #Config.Zones.BoatShops, 1 do
if GetDistanceBetweenCoords(coords, Config.Zones.BoatShops[i].Outside.x, Config.Zones.BoatShops[i].Outside.y, Config.Zones.BoatShops[i].Outside.z, true) < Config.MarkerSize.x then
isInMarker = true
currentZone = 'boat_shop'
currentZoneNum = i
end
--[[
if GetDistanceBetweenCoords(coords, v.Helicopters[i].SpawnPoint.x, v.Helicopters[i].SpawnPoint.y, v.Helicopters[i].SpawnPoint.z, true) < Config.MarkerSize.x then
isInMarker = true
currentZone = 'HelicopterSpawnPoint'
currentZoneNum = i
end
extra för garage
]]
end
local hasExited = false
if isInMarker and not HasAlreadyEnteredMarker or (isInMarker and (LastZone ~= currentZone or LastZoneNum ~= currentZoneNum) ) then
if
(LastZone ~= nil and LastZoneNum ~= nil) and
(LastZone ~= currentZone or LastZoneNum ~= currentZoneNum)
then
TriggerEvent('esx_boat:hasExitedMarker', LastZone)
hasExited = true
end
HasAlreadyEnteredMarker = true
LastZone = currentZone
LastZoneNum = currentZoneNum
TriggerEvent('esx_boat:hasEnteredMarker', currentZone, currentZoneNum)
end
if not hasExited and not isInMarker and HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = false
TriggerEvent('esx_boat:hasExitedMarker')
end
end
end)
+51
View File
@@ -0,0 +1,51 @@
Config = {}
Config.Locale = 'en'
Config.MarkerType = 1
Config.DrawDistance = 100.0
Config.ZoneSize = {x = 5.0, y = 5.0, z = 3.0}
Config.MarkerColor = {r = 100, g = 204, b = 100}
Config.MarkerSize = { x = 1.5, y = 1.5, z = 1.0 }
Config.Zones = {
Garages = {
{
GaragePos = { x = -772.42, y = -1430.90, z = 1.59 },
SpawnPoint = { x = -785.39, y = -1426.30, z = -0.47 },
RemovePos = { x = -798.45, y = -1456.03, z = -0.47 },
Heading = 150.0
}
},
BoatShops = {
{ -- shank st
Outside = { x = -773.76, y = -1495.25, z = 1.6 },
Inside = { x = -798.59, y = -1503.12, z = -0.47 },
Heading = 120.0
}
}
}
Config.Vehicles = {
{
model = 'seashark',
label = 'Seashark',
price = 15000
},
{
model = 'speeder',
label = 'Speeder',
price = 10000
}
}
+10
View File
@@ -0,0 +1,10 @@
Locales['en'] = {
-- shop
['boat_shop'] = 'boat shop',
['boat_shop_open'] = 'press ~INPUT_CONTEXT~ to open the boat shop.',
['boat_shop_confirm'] = 'buy a %s for <span style="color: orange;">$%s</span>?',
['boat_shop_bought'] = 'you have ~y~bought~s~ a ~b~%s~s~ for ~g~$%s~s~',
['boat_shop_nomoney'] = 'you cannot afford this boat!',
['confirm_no'] = 'no',
['confirm_yes'] = 'yes',
}
+58
View File
@@ -0,0 +1,58 @@
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
ESX.RegisterServerCallback('esx_boat:buyBoat', function (source, cb, vehicleProps, model)
local xPlayer = ESX.GetPlayerFromId(source)
local price = getPriceFromModel(model)
-- vehicle model not found
if price == 0 then
print(('esx_boat: %s attempted to exploit the shop! (invalid vehicle model)'):format(xPlayer.identifier))
cb(false)
end
if xPlayer.getMoney() >= price then
xPlayer.removeMoney(price)
MySQL.Async.execute('INSERT INTO owned_vehicles (owner, plate, vehicle, vehicleType) VALUES (@owner, @plate, @vehicle, @vehicleType)',
{
['@owner'] = xPlayer.identifier,
['@plate'] = vehicleProps.plate,
['@vehicle'] = json.encode(vehicleProps),
['@vehicleType'] = 'boat'
})
cb(true)
else
cb(false)
end
end)
ESX.RegisterServerCallback('esx_boat:getGarage', function (source, cb)
MySQL.Async.fetchAll('SELECT * FROM owned_vehicles WHERE owner = @owner, vehicleType = @vehicleType, stored = 1',
{
['@owner'] = GetPlayerIdentifiers(source)[1],
['vehicleType'] = 'boat'
}, function (result)
local vehicles = {}
for i=1, #result, 1 do
table.insert(vehicles, json.decode(result[i].vehicle))
end
cb(vehicles)
end)
end)
function getPriceFromModel(model)
for i=1, #Config.Vehicles, 1 do
if Config.Vehicles[i].model == model then
return Config.Vehicles[i].price
end
end
return 0
end