diff --git a/accounts/server.lua b/accounts/server.lua index cee42ba0..fdc72360 100644 --- a/accounts/server.lua +++ b/accounts/server.lua @@ -107,7 +107,7 @@ function OnAccountCheckIpBan(player) end function CreatePlayerAccount(player) - local query = mariadb_prepare(sql, "INSERT INTO `accounts` (`id`, `steamid`, `name`, `clothing`, `police`, `medic`, `inventory`, `position`, `admin`, `health`, `armor`, `thirst`, `hunger`, `bank_balance`, `created`, `phone_number`, `driver_license`, `gun_license`, `helicopter_license`, `drug_knowledge`, `job`, `is_cuffed`, `age`) VALUES (NULL, '?', 'Unregistered', '[]', '0', '0', '[]', '[]', '0', '100', '0', '100', '100', '4900', '0', NULL, '0', '0', '0', '[]', NULL, '0', '0');", + local query = mariadb_prepare(sql, "INSERT INTO `accounts` (`id`, `steamid`, `name`, `clothing`, `police`, `medic`, `inventory`, `position`, `admin`, `health`, `armor`, `thirst`, `hunger`, `bank_balance`, `created`, `phone_number`, `driver_license`, `gun_license`, `helicopter_license`, `taxi_license`, `drug_knowledge`, `job`, `is_cuffed`, `age`) VALUES (NULL, '?', 'Unregistered', '[]', '0', '0', '[]', '[]', '0', '100', '0', '100', '100', '4900', '0', NULL, '0', '0', '0', '0', '[]', NULL, '0', '0');", tostring(GetPlayerSteamId(player))) mariadb_query(sql, query, OnAccountCreated, player) @@ -155,7 +155,8 @@ function OnAccountLoaded(player) PlayerData[player].driver_license = math.tointeger(result['driver_license']) PlayerData[player].gun_license = math.tointeger(result['gun_license']) PlayerData[player].helicopter_license = math.tointeger(result['helicopter_license']) - PlayerData[player].inventory = json_decode(result['inventory']) + PlayerData[player].taxi_license = math.tointeger(result['taxi_license']) + PlayerData[player].inventory = json_decode(result['inventory']) PlayerData[player].created = math.tointeger(result['created']) PlayerData[player].position = json_decode(result['position']) PlayerData[player].drug_knowledge = json_decode(result['drug_knowledge']) @@ -304,6 +305,7 @@ function CreatePlayerData(player) PlayerData[player].driver_license = 0 PlayerData[player].gun_license = 0 PlayerData[player].helicopter_license = 0 + PlayerData[player].taxi_license = 0 PlayerData[player].logged_in = false PlayerData[player].admin = 0 PlayerData[player].created = 0 @@ -346,7 +348,6 @@ function DestroyPlayerData(player) end end - print("Player disconnected : " .. PlayerData[player].accountid) PlayerData[player] = nil print("Data destroyed for : " .. player) end @@ -366,7 +367,7 @@ function SavePlayerAccount(player) local x, y, z = GetPlayerLocation(player) PlayerData[player].position = {x = x, y = y, z = z} - local query = mariadb_prepare(sql, "UPDATE accounts SET admin = ?, bank_balance = ?, health = ?, armor = ?, hunger = ?, thirst = ?, name = '?', clothing = '?', inventory = '?', created = '?', position = '?', driver_license = ?, gun_license = ?, helicopter_license = ?, drug_knowledge = '?', job = '?', is_cuffed = ?, age = ?, is_online = '?' WHERE id = ? LIMIT 1;", + local query = mariadb_prepare(sql, "UPDATE accounts SET admin = ?, bank_balance = ?, health = ?, armor = ?, hunger = ?, thirst = ?, name = '?', clothing = '?', inventory = '?', created = '?', position = '?', driver_license = ?, gun_license = ?, helicopter_license = ?, taxi_license = ?, drug_knowledge = '?', job = '?', is_cuffed = ?, age = ?, is_online = '?' WHERE id = ? LIMIT 1;", PlayerData[player].admin, PlayerData[player].bank_balance, PlayerData[player].health, @@ -381,6 +382,7 @@ function SavePlayerAccount(player) PlayerData[player].driver_license, PlayerData[player].gun_license, PlayerData[player].helicopter_license, + PlayerData[player].taxi_license, json_encode(PlayerData[player].drug_knowledge), PlayerData[player].job or "", PlayerData[player].is_cuffed or 0, diff --git a/admin/server.lua b/admin/server.lua index a984e529..a5930f63 100644 --- a/admin/server.lua +++ b/admin/server.lua @@ -32,7 +32,8 @@ local teleportPlace = { mining_process_2 = {-191437, -31107, 1148}, mining_supplier = {67862, 184741, 535}, ironsmith = {-189805, -34122, 1148}, - hospital = {213530, 158344, 1416} + hospital = {213530, 158344, 1416}, + taxi_center = {175330,160737,4959} } local weaponList = { diff --git a/callouts/c_callouts.lua b/callouts/c_callouts.lua index 48bfb859..1a59bdee 100644 --- a/callouts/c_callouts.lua +++ b/callouts/c_callouts.lua @@ -3,6 +3,7 @@ local _ = function(k, ...) return ImportPackage("i18n").t(GetPackageName(), k, . local wpObject local currentCallout +local wplocation = {} local calloutsUI = nil @@ -78,6 +79,16 @@ function CloseCallout(player) end AddEvent("callouts:ui:close", CloseCallout) +AddRemoteEvent("callouts:createtaxiwp", function(x, y, z, label) + taxiwp = CreateWaypoint(x, y, z, tostring(label)) + GetPickupStaticMeshComponent(pickup):SetHiddenInGame(true) + Delay(360000, function() + if taxiwp ~= nil then + DestroyWaypoint(taxiwp) + end + end) +end) + AddRemoteEvent("callouts:createwp", function(target, x, y, z, label) if wpObject ~= nil then DestroyWaypoint(wpObject) end currentCallout = target @@ -90,6 +101,26 @@ AddRemoteEvent("callouts:cleanwp", function() currentCallout = nil if wpObject ~= nil then DestroyWaypoint(wpObject) end wpObject = nil - CallEvent("ClearCalloutDestination") -end) \ No newline at end of file +end) + +-- TAXI WAYPOINT + +AddRemoteEvent("DestroyTaxiWP", function(pickup) + local px, py, pz = GetPickupLocation(pickup) + for k, v in pairs(GetAllWaypoints()) do + local wx, wy, wz = GetWaypointLocation(v) + local distance = GetDistance3D(px, py, pz, wx, wy, wz) + if distance < 30 then + DestroyWaypoint(v) + CallRemoteEvent("DestroyPickup", pickup) + break + end + end +end) + +AddEvent("OnPickupStreamIn", function(pickup) + if GetPickupPropertyValue(pickup, "TaxiCall") then + GetPickupStaticMeshComponent(pickup):SetHiddenInGame(true) + end +end) diff --git a/callouts/s_callouts.lua b/callouts/s_callouts.lua index a8b3ce82..e44fbbfc 100644 --- a/callouts/s_callouts.lua +++ b/callouts/s_callouts.lua @@ -10,6 +10,9 @@ AddCommand("911", function(player, label) CreateCallout(player, "police", tostring(label)) end) +AddCommand("taxi", function(player, label) + CreateCallout(player, "taxi", tostring(label)) +end) --------- CALLOUTS AddCommand("clearcallouts", function(player) @@ -29,6 +32,8 @@ function CreateCallout(player, job, label)-- create a new callout caller_job = 'police' elseif PlayerData[player].job == "medic" then caller_job = 'medic' + elseif PlayerData[player].job == "taxi" then + caller_job = 'taxi' end callOuts[player] = { location = {x = x, y = y, z = z}, taken = false, job = job, label = label, caller_job = caller_job } @@ -39,6 +44,9 @@ function CreateCallout(player, job, label)-- create a new callout CallRemoteEvent(player, "MakeNotification", _("medic_callout_created"), "linear-gradient(to right, #00b09b, #96c93d)", 10000) elseif job == "police" then CallRemoteEvent(player, "MakeNotification", _("police_callout_created"), "linear-gradient(to right, #00b09b, #96c93d)", 10000) + elseif job == "taxi" then + CallRemoteEvent(player, "MakeNotification", _("taxi_callout_created"), "linear-gradient(to right, #00b09b, #96c93d)", 10000) + SendGPStoTaxi(player, callOuts[player]) else CallRemoteEvent(player, "MakeNotification", _("callout_created"), "linear-gradient(to right, #00b09b, #96c93d)", 10000) end @@ -54,13 +62,46 @@ function CalloutsNotifyPlayers(callout)-- send the new callout to medics and pol elseif callout.job == "police" then CallRemoteEvent(v, "MakeNotification", _("police_new_callout", callout.label), "linear-gradient(to right, #00b09b, #96c93d)", 10000) CallRemoteEvent(v, "medic:deathalarm") - else + else CallRemoteEvent(v, "MakeNotification", _("new_callout", callout.label), "linear-gradient(to right, #00b09b, #96c93d)", 10000) end end end end +function SendGPStoTaxi(player, callout) + local target = player + label = _("taxi_waypoint_label") + if GetPlayerPropertyValue(target, "Caller") ~= nil then + DPickup = GetPlayerPropertyValue(target, "Caller") + if IsValidPickup(DPickup) then + current_call = true + end + end + local TaxiPickup = CreatePickup(336, callOuts[tonumber(target)].location.x, callOuts[tonumber(target)].location.y, callOuts[tonumber(target)].location.z) + SetPickupScale(TaxiPickup, 40, 40, 4) + SetPickupPropertyValue(TaxiPickup, "TaxiCall", true, true) + SetPlayerPropertyValue(target, "Caller", TaxiPickup, true) + for k, v in pairs(GetAllPlayers()) do + if PlayerData[v] ~= nil and PlayerData[v].job ~= nil and PlayerData[v].job ~= "" and callout.job == PlayerData[v].job then + if callout.job == "taxi" then + if current_call then + CallRemoteEvent(v, "DestroyTaxiWP", DPickup) + end + CallRemoteEvent(v, "medic:deathalarm") + CallRemoteEvent(v, "callouts:createtaxiwp", callOuts[tonumber(target)].location.x, callOuts[tonumber(target)].location.y, callOuts[tonumber(target)].location.z, label) + end + end + end + + Delay(360000, function() + if TaxiPickup ~= nil then + DestroyPickup(TaxiPickup) + SetPlayerPropertyValue(target, "Caller", nil, true) + end + end) +end + function CalloutTake(player, target)-- allow to take the callout if PlayerData[player].job ~= "medic" and PlayerData[player].job ~= "police" then return end if callOuts[tonumber(target)] == nil then return end @@ -163,4 +204,29 @@ function GetCalloutsList(player) return calloutsList end ---------- CALLOUTS END \ No newline at end of file +--------- CALLOUTS END + +AddEvent("OnPlayerPickupHit", function(player, pickup) -- Destroy pickup + if GetPickupPropertyValue(pickup, "TaxiCall") then + if PlayerData[player].job ~= "taxi" then return end + local vehicle = GetPlayerVehicle(player) + if vehicle == nil then return end + local seat = GetPlayerVehicleSeat(player) + if vehicle == PlayerData[player].job_vehicle and + VehicleData[vehicle].owner == PlayerData[player].accountid and + seat == 1 + then + for k, v in pairs(GetAllPlayers()) do + if PlayerData[v] ~= nil and PlayerData[v].job == "taxi" then + CallRemoteEvent(v, "DestroyTaxiWP", pickup) + end + end + end + end +end) + +AddRemoteEvent("DestroyPickup", function(player, pickup) + if pickup ~= nil and IsValidPickup(pickup) then + DestroyPickup(pickup) + end +end) diff --git a/hud/pinmap/config.ini b/hud/pinmap/config.ini index 1701e455..99e20798 100644 --- a/hud/pinmap/config.ini +++ b/hud/pinmap/config.ini @@ -2,7 +2,7 @@ #If developerModeEnabled is set to true, it will allow for teleporting when the map is open via right click. developerModeEnabled = false [mapLegend] -keyCount = 21 +keyCount = 22 key1 = market key2 = atm key3 = gunstore @@ -24,6 +24,7 @@ key18 = mining_gather key19 = mining_process_1 key20 = mining_process_2 key21 = mining_supplier +key22 = taxi_center [market] @@ -194,3 +195,9 @@ displayText = lumberjack_supplier blipCount = 1 blip1 = 203566, 171875 +[taxi_center] +iconpath = http://asset/onsetrp/hud/pinmap/client/web/icons/shelby/ico-pos-taxi.png +displayText = taxi_center +blipCount = 1 +blip1 = 176194, 158444 + diff --git a/i18n/en.json b/i18n/en.json index cd859203..1ebd1739 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -595,5 +595,35 @@ "item_menu": "Objects menu", "admin_give_item_success": "Objects given with succes", "admin_give_item_fail": "Can't give this objects", - "orange": "orange" + "orange": "orange", + "taxi_job": "Chauffeur de taxi", + "taxi_menu": "Taxi menu", + "taxi_garage_menu": "Garage taxi", + "spawn_taxi_cash": "Get taxi car (Caution [1500€] cash)", + "spawn_taxi_bank": "Get taxi car (Caution [1500€] bank account)", + "quit_taxi": "You are no longer taxi driver", + "taxi_npc_message_stop": "What ? You want to let us already ?", + "taxi_npc_message_start": "Hello, Do you want to become taxi driver ?", + "taxi_npc_name": "Mr. White, Employer", + "taxi_service_npc_starting": "It's OK, Welcome in our team !", + "taxi_service_npc_end": "Go it, come back when you want", + "join_taxi": "You become taxi driver", + "not_taxi": "You're not taxi driver", + "taxi_license": "taxi license", + "start_course": "Start course", + "end_course": "End course", + "cancel_course": "Cancel course", + "payement": "Payement", + "payement menu": "Payement Menu", + "payin_cash": "Player pay in cash", + "payin_bank": "Player pay with bank", + "cash_taxi": "Payment in cash : Payment need to be made from your inventory", + "process_pay": "Course is over, please process to payment", + "no_player_in_vehicle": "There is nobody in your car !", + "not_in_vehicle": "You have to be in your car !", + "not_driver": "You have to be the driver !", + "pay_success": "Transaction success", + "no_current_course": "There is no course in progress !", + "taxi_callout_created": "Taxis receive your call", + "taxi_waypoint_label": "Taxi" } diff --git a/i18n/fr.json b/i18n/fr.json index 917fec2b..ccaddbec 100644 --- a/i18n/fr.json +++ b/i18n/fr.json @@ -500,7 +500,7 @@ "policecar_place_player_in_back": "Vous avez mis cette personne dans votre voiture", "policecar_player_remove_from_car": "Vous avez fait sortir les personnes de votre voiture", "police_no_player_in_range": "Il n'y a aucune personne à qui donner cette amende", - "please_leave_previous_job": "Merci de quitter votre précédent travaille", + "please_leave_previous_job": "Merci de quitter votre précédent travail", "police_alert_bank": "CODE 3 : L'alarme de la banque vient d'être déclenchée !", "police_robbery_in_progress": "BRAQUAGE EN COURS", "police_check_my_equipment": "Vérifier mon équipement", @@ -644,5 +644,38 @@ "gris_fonce": "Gris foncé", "gris_titanium": "Gris Titanium", "violet_fonce": "Violet foncé", - "disable_dev_mode": "Merci de désactiver le DEVMODE dans votre launcher Steam pour jouer sur ce serveur." -} \ No newline at end of file + "disable_dev_mode": "Merci de désactiver le DEVMODE dans votre launcher Steam pour jouer sur ce serveur.", + "taxi_center": "Centre des taxis", + "taxi_job": "Chauffeur de taxi", + "taxi_menu": "Menu Taxi", + "taxi_garage_menu": "Garage taxi", + "spawn_taxi_cash": "Sortir taxi (Caution en cash)", + "spawn_taxi_bank": "Sortir taxi (Caution en banque)", + "quit_taxi": "Vous n'êtes plus chauffeur de taxi", + "taxi_npc_message_stop": "Quoi ?! Tu veux déjà nous quitter ?", + "taxi_npc_message_start": "Bonjour, tu souhaites devenir chauffeur de taxi ?", + "taxi_npc_name": "Mr. White, Employeur", + "taxi_service_npc_starting": "C'est d'accord, bienvenue dans l'équipe", + "taxi_service_npc_end": "Compris, reviens quand tu veux", + "join_taxi": "Vous êtes devenus chauffeur de taxi", + "not_taxi": "Vous n'êtes pas chauffeur de taxi", + "taxi_license": "License de taxi", + "no_taxi_licence": "Vous avez besoin d'une license de taxi pour cela", + "start_course": "Commencer une course", + "end_course": "Terminer une course", + "cancel_course": "Annuler une course", + "payement": "Paiement", + "payement menu": "Menu Paiement", + "payin_cash": "Paiement en liquide", + "payin_bank": "Paiment avec la banque", + "cash_taxi": "Paiement en liquide : La transaction doit être réalisée depuis vos inventaires", + "process_pay": "La course est terminée. Veuillez procéder au paiement", + "no_player_in_vehicle": "Il n'y a personne dans votre vehicule !", + "not_in_vehicle": "Vous devez être dans votre vehicule !", + "not_driver": "Vous devez être au volant du vehicule !", + "pay_success": "La transaction a été effectué avec succes", + "no_current_course": "Il n'y a pas de course en cours !", + "taxi_callout_created": "Les taxis ont reçu votre appels", + "taxi_waypoint_label": "Taxi", + "taxi_disclaimer_caution": "Une caution de {1} $ est nécessaire pour utiliser un taxi. Vous les retrouverez une fois le taxi rendu." +} diff --git a/licenses/server.lua b/licenses/server.lua index 87694cba..7eee7d0e 100644 --- a/licenses/server.lua +++ b/licenses/server.lua @@ -2,7 +2,8 @@ local _ = function(k,...) return ImportPackage("i18n").t(GetPackageName(),k,...) Licenses = { driver_license = 1500, - gun_license = 6000 + gun_license = 6000, + taxi_license = 5000 -- helicopter_license = 30000 } LicensesNpcLocation = { x = 169336, y = 193430, z = 1307, h = 180 } diff --git a/package.json b/package.json index dd06a2bb..a1f8e9c6 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,8 @@ "admin/s_spectate.lua", "searchobject/server.lua", "callouts/s_callouts.lua", - "onset-characterize/server.lua" + "onset-characterize/server.lua", + "taxi/s_taxi.lua" ], "client_scripts": [ "welcome/client.lua", @@ -94,7 +95,8 @@ "admin/c_spectate.lua", "searchobject/client.lua", "callouts/c_callouts.lua", - "onset-characterize/client.lua" + "onset-characterize/client.lua", + "taxi/c_taxi.lua" ], "files": [ "hud/speaking/speaking.png", @@ -241,6 +243,7 @@ "onset-characterize/ui/jquery.js", "onset-characterize/ui/style.css", "onset-characterize/click.wav", - "admin/broadcastui/broadcastui.html" + "admin/broadcastui/broadcastui.html", + "taxi/taxihud.html" ] } diff --git a/roleplay.sql b/roleplay.sql index 28417c04..b746ed6a 100644 --- a/roleplay.sql +++ b/roleplay.sql @@ -19,6 +19,7 @@ CREATE TABLE IF NOT EXISTS `accounts` ( `driver_license` tinyint(1) NOT NULL DEFAULT '0', `gun_license` tinyint(1) NOT NULL DEFAULT '0', `helicopter_license` tinyint(1) NOT NULL DEFAULT '0', + `taxi_license` tinyint(1) NOT NULL DEFAULT '0', `drug_knowledge` text NOT NULL, `job` varchar(20) DEFAULT NULL, `is_cuffed` tinyint(1) NOT NULL DEFAULT '0', diff --git a/taxi/c_taxi.lua b/taxi/c_taxi.lua new file mode 100644 index 00000000..c9e56f4a --- /dev/null +++ b/taxi/c_taxi.lua @@ -0,0 +1,174 @@ +local Dialog = ImportPackage("dialogui") +local _ = function(k, ...) return ImportPackage("i18n").t(GetPackageName(), k, ...) end + +local IsOnDuty = false + +local taxiMenu +local taxiNpcGarageMenu +local taxiPayMenu +local CourseTime +local taxicourse + +local taxiNpcIds = {} +local taxiVehicleNpcIds = {} +local taxiGarageIds = {} + +local TaxiHud + +local cautionTaxi = 0 + +function OnPackageStart() + TaxiHud = CreateWebUI(0, 0, 0, 0, 0, 60) + SetWebAlignment(TaxiHud, 1.0, 0.0) + SetWebAnchors(TaxiHud, 0.0, 0.0, 1.0, 1.0) + LoadWebFile(TaxiHud, "http://asset/onsetrp/taxi/taxihud.html") + SetWebVisibility(TaxiHud, WEB_HIDDEN) +end +AddEvent("OnPackageStart", OnPackageStart) + + +AddRemoteEvent("taxi:setup", function(_taxiNpcIds, _taxiGarageIds, _taxiVehicleNpcIds, _caution) + taxiNpcIds = _taxiNpcIds + taxiGarageIds = _taxiGarageIds + taxiVehicleNpcIds = _taxiVehicleNpcIds + cautionTaxi = _caution + + -- SPAWN VEHICLE MENU + taxiNpcGarageMenu = Dialog.create(_("taxi_garage_menu"), _("taxi_disclaimer_caution", cautionTaxi), _("spawn_taxi_cash"), _("spawn_taxi_bank"), _("cancel")) +end) + +AddRemoteEvent("taxi:client:isonduty", function(isOnDuty) + IsOnDuty = isOnDuty +end) + +AddEvent("OnTranslationReady", function() + -- TAXI MENU + taxiMenu = Dialog.create(_("taxi_menu"), nil, _("start_course"), _("end_course"), _("cancel_course"), _("payement"), _("cancel")) + + -- PAYEMENT MENU + taxiPayMenu = Dialog.create(_("payement menu"), nil, _("payin_cash"), _("payin_bank"), _("cancel")) +end) + +AddEvent("OnKeyPress", function(key) + + if key == JOB_MENU_KEY and not GetPlayerBusy() and IsOnDuty then + Dialog.show(taxiMenu) + end + + if key == INTERACT_KEY and not GetPlayerBusy() and IsOnDuty and IsNearbyNpc(GetPlayerId(), taxiVehicleNpcIds) ~= false then + Dialog.show(taxiNpcGarageMenu) + end + + if key == INTERACT_KEY and not GetPlayerBusy() and IsNearbyNpc(GetPlayerId(), taxiNpcIds) ~= false then + AskForTaxiJob(IsNearbyNpc(GetPlayerId(), taxiNpcIds)) + end +end) + +function AskForTaxiJob(npc) + + local message = (IsOnDuty and _("taxi_npc_message_stop") or _("taxi_npc_message_start")) + startCinematic({ + title = _("taxi_npc_name"), + message = message, + actions = { + { + text = _("yes"), + callback = "taxi:startstopcinematic" + }, + { + text = _("no"), + close_on_click = true + } + } + }, NearestTaxi, "ITSJUSTRIGHT") +end + +AddEvent("taxi:startstopcinematic", function() + + local message = (IsOnDuty and _("taxi_service_npc_end") or _("taxi_service_npc_starting")) + updateCinematic({ + message = message + }, NearestTaxi, "WALLLEAN04") + Delay(1500, function() + stopCinematic() + end) + CallRemoteEvent("taxi:startstopservice") +end) + +AddEvent("OnDialogSubmit", function(dialog, button, ...) + local args = {...} + if dialog == taxiMenu then + if button == 1 then -- start course + CallRemoteEvent("course:start") + end + if button == 2 then -- stop course + CallRemoteEvent("course:stop") + end + if button == 3 then -- cancel course + CallRemoteEvent("course:cancel") + end + if button == 4 then + Dialog.show(taxiPayMenu) + end + end + + if dialog == taxiNpcGarageMenu then + if button == 1 then + CallRemoteEvent("taxi:checkcash") + end + if button == 2 then + CallRemoteEvent("taxi:checkbank") + end + end + + if dialog == taxiPayMenu then + if button == 1 then + CallRemoteEvent("notifCash") + end + if button == 2 then + CallRemoteEvent("bankPay", CourseTime) + end + end +end) + +function IsNearbyNpc(player, npcs) + local x, y, z = GetPlayerLocation(player) + for k, v in pairs(npcs) do + local x2, y2, z2 = GetNPCLocation(v) + if x2 ~= false and GetDistance3D(x, y, z, x2, y2, z2) <= 200 then return v end + end + return false +end + + +--- Course + +AddRemoteEvent("course", function(state) + if state then + SetWebVisibility(TaxiHud, WEB_HITINVISIBLE) + CourseTime = 0 + ExecuteWebJS(TaxiHud, "StartCourse("..CourseTime..");") + taxicourse = CreateTimer(function(player) + CourseTime = CourseTime + 1 + ExecuteWebJS(TaxiHud, "StartCourse("..CourseTime..");") + end, 2000, player) + else + DestroyTimer(taxicourse) + end +end) + +AddRemoteEvent("HideTaxiHud", function() + SetWebVisibility(TaxiHud, WEB_HIDDEN) +end) + +AddRemoteEvent("cancelcourse", function() + if GetWebVisibility(TaxiHud) == 0 then + SetWebVisibility(WEB_HITINVISIBLE) + end + DestroyTimer(taxicourse) + local CourseTime = 0 + ExecuteWebJS(TaxiHud, "StartCourse("..CourseTime..");") + Delay(1000, function() + SetWebVisibility(TaxiHud, WEB_HIDDEN) + end) +end) diff --git a/taxi/s_taxi.lua b/taxi/s_taxi.lua new file mode 100644 index 00000000..e2c6f24e --- /dev/null +++ b/taxi/s_taxi.lua @@ -0,0 +1,363 @@ +local _ = function(k, ...) return ImportPackage("i18n").t(GetPackageName(), k, ...) end + +local MAX_TAXI = 10 -- Number of taximens at the same time +local ALLOW_RESPAWN_VEHICLE = false -- Allow the respawn of the vehicle by destroying the previously spawned one. (Can break RP if the car is stolen or need repairs or fuel) +local CAUTION = 1500 -- Amount of the caution + +local occupants = {} + +local VEHICLE_SPAWN_LOCATION = { + {x = 177218, y = 159869, z = 4817, h = -70}, +} + +local TAXI_SERVICE_NPC = { + {x = 176053, y = 158567, z = 4850, h = 0}, +} + +local TAXI_VEHICLE_NPC = { + {x = 176211, y = 159760, z = 4818, h = 10}, +} + +local TAXI_GARAGE = { + {x = 175676, y = 159208, z = 4819}, +} + +local taxiNpcIds = {} +local taxiVehicleNpcIds = {} +local taxiGarageIds = {} + +AddEvent("OnPackageStart", function() + for k, v in pairs(TAXI_SERVICE_NPC) do + v.npcObject = CreateNPC(v.x, v.y, v.z, v.h) + CreateText3D(_("taxi_job") .. "\n" .. _("press_e"), 18, v.x, v.y, v.z + 120, 0, 0, 0) + SetNPCAnimation(v.npcObject, "CROSSARMS", true) + table.insert(taxiNpcIds, v.npcObject) + end + + if ALLOW_RESPAWN_VEHICLE == false then + for k, v in pairs(TAXI_GARAGE) do + v.garageObject = CreatePickup(2, v.x, v.y, v.z) + table.insert(taxiGarageIds, v.garageObject) + end + end + + for k, v in pairs(TAXI_VEHICLE_NPC) do + v.npcObject = CreateNPC(v.x, v.y, v.z, v.h) + CreateText3D(_("taxi_garage_menu") .. "\n" .. _("press_e"), 18, v.x, v.y, v.z + 120, 0, 0, 0) + SetNPCAnimation(v.npcObject, "WALLLEAN04", true) + table.insert(taxiVehicleNpcIds, v.npcObject) + end +end) + +AddEvent("OnPlayerJoin", function(player) + CallRemoteEvent(player, "taxi:setup", taxiNpcIds, taxiGarageIds, taxiVehicleNpcIds, CAUTION) +end) + +AddEvent("job:onspawn", function(player) + --PlayerData[player].job_vehicle = trucksOnLocation[PlayerData[player].accountid] -- Pour récupérer la propriété du véhicule de prêt + if PlayerData[player].job == "taxi" then -- Anti glitch + CallRemoteEvent(player, "taxi:client:isonduty", true) + end +end) + + +--------- SERVICE +function TaxiStartStopService(player) + if PlayerData[player].job == "" then + TaxiStartService(player) + elseif PlayerData[player].job == "taxi" then + TaxiEndService(player) + else + CallRemoteEvent(player, "MakeErrorNotification", _("please_leave_previous_job")) + end +end +AddRemoteEvent("taxi:startstopservice", TaxiStartStopService) + +function TaxiStartService(player)-- To start the taxi service + -- #1 Check if the player has a job vehicle spawned then destroy it + if PlayerData[player].job_vehicle ~= nil then + DestroyVehicle(PlayerData[player].job_vehicle) + DestroyVehicleData(PlayerData[player].job_vehicle) + PlayerData[player].job_vehicle = nil + end + + -- #2 Check for the number of taximen in service + local taximens = 0 + for k, v in pairs(PlayerData) do + if v.job == "taxi" then taximens = taximens + 1 end + end + if taximens >= MAX_TAXI then + CallRemoteEvent(player, "MakeErrorNotification", _("job_full")) + return + end + + -- #3 Check for the taxi licence + if PlayerData[player].taxi_license == 0 then + CallRemoteEvent(player, "MakeErrorNotification", _("no_taxi_licence")) + return + end + + -- #3 Set the player job to taxi + PlayerData[player].job = "taxi" + CallRemoteEvent(player, "taxi:client:isonduty", true) + CallRemoteEvent(player, "MakeNotification", _("join_taxi"), "linear-gradient(to right, #00b09b, #96c93d)") + + return true +end + +function TaxiEndService(player)-- To end the taxi service + --Set player job + PlayerData[player].job = "" + CallRemoteEvent(player, "taxi:client:isonduty", false) + CallRemoteEvent(player, "MakeNotification", _("quit_taxi"), "linear-gradient(to right, #00b09b, #96c93d)") + + return true +end + +--------- SERVICE END +--------- TAXI VEHICLE +function CheckCash(player) + -- #1 Check if the player has the taxi job + if PlayerData[player].job ~= "taxi" then + CallRemoteEvent(player, "MakeErrorNotification", _("not_taxi")) + return + end + + -- #2 Check if the player has money for caution + if CAUTION > GetPlayerCash(player) then + CallRemoteEvent(player, "MakeErrorNotification",_("no_money_car")) + else + SetPlayerPropertyValue(player, "caution", "cash", true) + SpawnTaxiCar(player) + end +end +AddRemoteEvent("taxi:checkcash", CheckCash) + +function CheckBank(player) + -- #1 Check if the player has the taxi job + if PlayerData[player].job ~= "taxi" then + CallRemoteEvent(player, "MakeErrorNotification", _("not_taxi")) + return + end + + -- #2 Check if the player has money for caution + if CAUTION > PlayerData[player].bank_balance then + CallRemoteEvent(player, "MakeErrorNotification", _("no_money_car")) + else + SetPlayerPropertyValue(player, "caution", "bank", true) + SpawnTaxiCar(player) + end +end +AddRemoteEvent("taxi:checkbank", CheckBank) + +function SpawnTaxiCar(player) + --[[ #1 Check if the player has the taxi job + if PlayerData[player].job ~= "taxi" then + CallRemoteEvent(player, "MakeErrorNotification", _("not_taxi")) -- Already checked before + return + end]] + + -- #2 Check if the player has a job vehicle spawned then destroy it + if PlayerData[player].job_vehicle ~= nil and ALLOW_RESPAWN_VEHICLE then + DestroyVehicle(PlayerData[player].job_vehicle) + DestroyVehicleData(PlayerData[player].job_vehicle) + PlayerData[player].job_vehicle = nil + end + + -- #3 Try to spawn the vehicle + if PlayerData[player].job_vehicle == nil then + local spawnPoint = VEHICLE_SPAWN_LOCATION[TaxiGetClosestSpawnPoint(player)] + if spawnPoint == nil then return end + for k, v in pairs(GetStreamedVehiclesForPlayer(player)) do + local x, y, z = GetVehicleLocation(v) + if x == false then break end + local dist2 = GetDistance3D(spawnPoint.x, spawnPoint.y, spawnPoint.z, x, y, z) + if dist2 < 500.0 then + CallRemoteEvent(player, "MakeErrorNotification", _("cannot_spawn_vehicle")) + return + end + end + local vehicle = CreateVehicle(2, spawnPoint.x, spawnPoint.y, spawnPoint.z, spawnPoint.h) + PlayerData[player].job_vehicle = vehicle + CreateVehicleData(player, vehicle, 2) + SetVehicleRespawnParams(vehicle, false) + SetVehiclePropertyValue(vehicle, "locked", true, true) + if GetPlayerPropertyValue(player, "caution") == "cash" then + RemovePlayerCash(player, CAUTION) + elseif GetPlayerPropertyValue(player, "caution") == "bank" then + PlayerData[player].bank_balance = PlayerData[player].bank_balance - CAUTION + end + CallRemoteEvent(player, "MakeNotification", _("spawn_vehicle_success", " taxi car"), "linear-gradient(to right, #00b09b, #96c93d)") + else + CallRemoteEvent(player, "MakeErrorNotification", _("cannot_spawn_vehicle")) + end +end +AddEvent("taxi:spawnvehicle", SpawnTaxiCar) + +function DespawnTaxiCar(player) + -- Check if the player has a job vehicle spawned then destroy it + if PlayerData[player].job_vehicle ~= nil then + DestroyVehicle(PlayerData[player].job_vehicle) + DestroyVehicleData(PlayerData[player].job_vehicle) + PlayerData[player].job_vehicle = nil + if GetPlayerPropertyValue(player, "caution") == "cash" then + AddPlayerCash(player, CAUTION) + else + PlayerData[player].bank_balance = PlayerData[player].bank_balance + CAUTION + end + SetPlayerPropertyValue(player, "caution", nil, true) + CallRemoteEvent(player, "MakeNotification", _("vehicle_stored"), "linear-gradient(to right, #00b09b, #96c93d)") + return + end +end + +AddEvent("OnPlayerPickupHit", function(player, pickup)-- Store the vehicle in garage + if PlayerData[player].job ~= "taxi" then return end + for k, v in pairs(TAXI_GARAGE) do + if v.garageObject == pickup then + local vehicle = GetPlayerVehicle(player) + if vehicle == nil then return end + local seat = GetPlayerVehicleSeat(player) + if vehicle == PlayerData[player].job_vehicle and + VehicleData[vehicle].owner == PlayerData[player].accountid and + seat == 1 + then + DespawnTaxiCar(player) + end + end + end +end) +--------- TAXI VEHICLE END +--------- INTERACTIONS + +function StartCourse(player) + taximan = player + local taxiID = GetPlayerVehicle(taximan) + if taxiID ~= 0 then -- Check if taximan in vehicle + local vehID = GetVehicleModel(taxiID) + if vehID == 2 then -- Check if taximan in taxi + local playerDriver = GetVehicleDriver(taxiID) + if taximan == playerDriver then -- Check if taximan is driver + if GetPlayerPropertyValue(taximan, "TaxiOcupped") == nil or not GetPlayerPropertyValue(taximan, "TaxiOcupped") then -- Check if course not in progress + local occupants = GetClientInTaxi(taximan, taxiID) + if occupants ~= nil then -- Check if there is client in taxi + SetPlayerPropertyValue(taximan, "TaxiOcupped", true, true) + SetPlayerPropertyValue(taximan, "Occup", occupants, true) + state = true + for k, v in ipairs(occupants) do + CallRemoteEvent(v, "course", state) + end + CallRemoteEvent(taximan, "course", state) + else + CallRemoteEvent(taximan, "MakeErrorNotification", _("no_player_in_vehicle")) + end + end + else + CallRemoteEvent(taximan, "MakeErrorNotification", _("not_driver")) + end + end + else + CallRemoteEvent(taximan, "MakeErrorNotification", _("not_in_vehicle")) + end +end +AddRemoteEvent("course:start", StartCourse) + +--[[function PauseCourse(player) + local state = 2 + for k, v in ipairs(Occupants) do + if v ~= 0 then + CallRemoteEvent(v, "course", state) + end + end + CallRemoteEvent(player, "course", state) +end +AddRemoteEvent("course:pause_unpause", PauseCourse)]] + +function CancelCourse(player) + if GetPlayerPropertyValue(player, "TaxiOccuped") then + occup = GetPlayerPropertyValue(player, "Occup") + for k, v in pairs(occup) do + CallRemoteEvent(v, "cancelcourse") + end + CallRemoteEvent(player, "cancelcourse") + end +end +AddRemoteEvent("course:cancel", CancelCourse) + +function StopCourse(player) + if GetPlayerPropertyValue(player, "TaxiOcupped") ~= nil and GetPlayerPropertyValue(player, "TaxiOcupped") then + state = false + CallRemoteEvent(player, "course", state) + CallRemoteEvent(player, "MakeNotification", _("process_pay"), "linear-gradient(to right, #00b09b, #96c93d)") + occup = GetPlayerPropertyValue(player, "Occup") + for k, v in ipairs(occup) do + CallRemoteEvent(v, "course", state) + CallRemoteEvent(v, "MakeNotification", _("process_pay"), "linear-gradient(to right, #00b09b, #96c93d)") + end + else + CallRemoteEvent(player, "MakeErrorNotification", _("no_current_course")) + end +end +AddRemoteEvent("course:stop", StopCourse) + +AddRemoteEvent("notifCash", function(player) + if GetPlayerPropertyValue(player, "TaxiOcupped") ~= nil and GetPlayerPropertyValue(player, "TaxiOcupped") then + SetPlayerPropertyValue(player, "TaxiOcupped", false, true) + CallRemoteEvent(player, "MakeNotification", _("cash_taxi"), "linear-gradient(to right, #00b09b, #96c93d)") -- Les joueurs doivent procéder au paiement depuis leur inventaires + CallRemoteEvent(player, "HideTaxiHud") + occup = GetPlayerPropertyValue(player, "Occup") + SetPlayerPropertyValue(player, "Occup", nil, true) + for k, v in ipairs(occup) do + CallRemoteEvent(v, "MakeNotification", _("cash_taxi"), "linear-gradient(to right, #00b09b, #96c93d)") + CallRemoteEvent(v, "HideTaxiHud") + end + end +end) + +AddRemoteEvent("bankPay", function(player, CourseTime) + if GetPlayerPropertyValue(player, "TaxiOcupped") ~= nil and GetPlayerPropertyValue(player, "TaxiOcupped") then + SetPlayerPropertyValue(player, "TaxiOcupped", false, true) + occup = GetPlayerPropertyValue(player, "Occup") + SetPlayerPropertyValue(player, "Occup", nil, true) + for k, v in ipairs(occup) do + PlayerData[v].bank_balance = PlayerData[v].bank_balance - CourseTime -- On débite les clients + PlayerData[player].bank_balance = PlayerData[player].bank_balance + CourseTime -- On alimente le compte du chauffeur + CallRemoteEvent(v, "MakeNotification", _("pay_success"), "linear-gradient(to right, #00b09b, #96c93d)") + CallRemoteEvent(v, "HideTaxiHud") + end + CallRemoteEvent(player, "HideTaxiHud") + CallRemoteEvent(player, "MakeNotification", _("pay_success"), "linear-gradient(to right, #00b09b, #96c93d)") + end +end) + +--------- INTERACTIONS END +-- Tools +function TaxiGetClosestSpawnPoint(player) + local x, y, z = GetPlayerLocation(player) + local closestSpawnPoint + local dist + for k, v in pairs(VEHICLE_SPAWN_LOCATION) do + local currentDist = GetDistance3D(x, y, z, v.x, v.y, v.z) + if (dist == nil or currentDist < dist) and currentDist <= 2000 then + closestSpawnPoint = k + dist = currentDist + end + end + return closestSpawnPoint +end + +function GetClientInTaxi(player, taxiID) + occupants = {} + for i = 2, 4 do + local passenger = GetVehiclePassenger(taxiID, i) + if (passenger ~= 0) then + table.insert( occupants, passenger ) + --occupants [#occupants + 1] = passenger + end + end + if #occupants == 0 then + return nil + else + return occupants + end +end diff --git a/taxi/taxihud.html b/taxi/taxihud.html new file mode 100644 index 00000000..e285e617 --- /dev/null +++ b/taxi/taxihud.html @@ -0,0 +1,89 @@ + + + + + + Taxi + + + + + + + +
+
Prix course :
+
+
+ + + + + + \ No newline at end of file