Eroge Posted February 3, 2022 Share Posted February 3, 2022 Im using this script to allow players purchase vehicles with keys. But I got 3 problems: 1. Car key does not spawn correctly 2. Only players with GM or higher access can spawn vehicle, others only get "you dont have the right to use /addvehicle command" in chatbox 3. Spawned cars are not repaired correctly Can anyone tell me where did this script go wrong? Much appreciated!! vehicleTradeRecipe.lua Link to comment Share on other sites More sharing options...
Tykvesh Posted February 3, 2022 Share Posted February 3, 2022 (edited) I think you can resolve all three with client-server commands, using functions sendClientCommand, sendServerCommand, and events OnClientCommand, OnServerCommand. There are plenty of examples in the code! For example, this built-in command should repair vehicles properly (see VehicleCommands.lua): sendClientCommand(player, "vehicle", "repair", { vehicle = vehicle:getId() }) Edited February 3, 2022 by Tykvesh Link to comment Share on other sites More sharing options...
Eroge Posted February 4, 2022 Author Share Posted February 4, 2022 21 hours ago, Tykvesh said: I think you can resolve all three with client-server commands, using functions sendClientCommand, sendServerCommand, and events OnClientCommand, OnServerCommand. There are plenty of examples in the code! For example, this built-in command should repair vehicles properly (see VehicleCommands.lua): sendClientCommand(player, "vehicle", "repair", { vehicle = vehicle:getId() }) Any examples for spawning vehicles? Link to comment Share on other sites More sharing options...
Tykvesh Posted February 4, 2022 Share Posted February 4, 2022 (edited) Here's an example for your script: function Recipe.OnCreate.hezhuangqichea(items, result, player) if getWorld():getGameMode() ~= "Multiplayer" then for i=0,items:size() - 1 do local item = items:get(i) if item:getType() == "carboxmustangpolice" then if not player:isOutside() or player:getZ() > 0 then player:Say(getText("IGUI_zuzhuangshibai")) player:getInventory():AddItem("carboxmustangpolice") else --first we tell the server to spawn a vehicle for us sendClientCommand(player, "eroge", "SpawnVehicle", { type = "Base.ATAMustangPolice" }) end Events.OnClientCommand.Add(function(module, name, player, params) if module == "eroge" and name == "SpawnVehicle" then --server got the request and spawns the desired vehicle local vehicle = addVehicleDebug(params.type, randomdir[ZombRand(4) + 1], -1, getSquare(player:getX(), player:getY(), player:getZ())) --should repair properly as this code is run server-side vehicle:repair() --tell back to the player to do their client-side stuff sendServerCommand(player, "eroge", "ClaimVehicle", { vehicle = vehicle:getId() }) end end) Events.OnServerCommand.Add(function(module, name, params) if module == "eroge" and name == "ClaimVehicle" then local vehicle = getVehicleById(params.vehicle) if vehicle ~= nil then --now client can get some keys in peace player:getInventory():AddItem(vehicle:getCurrentKey() or vehicle:createVehicleKey()) player:Say(getText("IGUI_zuzhuangchenggong")) end end end) Edited February 4, 2022 by Tykvesh Eroge 1 Link to comment Share on other sites More sharing options...
Eroge Posted February 11, 2022 Author Share Posted February 11, 2022 On 2/5/2022 at 2:13 AM, Tykvesh said: Here's an example for your script: function Recipe.OnCreate.hezhuangqichea(items, result, player) if getWorld():getGameMode() ~= "Multiplayer" then for i=0,items:size() - 1 do local item = items:get(i) if item:getType() == "carboxmustangpolice" then if not player:isOutside() or player:getZ() > 0 then player:Say(getText("IGUI_zuzhuangshibai")) player:getInventory():AddItem("carboxmustangpolice") else --first we tell the server to spawn a vehicle for us sendClientCommand(player, "eroge", "SpawnVehicle", { type = "Base.ATAMustangPolice" }) end Events.OnClientCommand.Add(function(module, name, player, params) if module == "eroge" and name == "SpawnVehicle" then --server got the request and spawns the desired vehicle local vehicle = addVehicleDebug(params.type, randomdir[ZombRand(4) + 1], -1, getSquare(player:getX(), player:getY(), player:getZ())) --should repair properly as this code is run server-side vehicle:repair() --tell back to the player to do their client-side stuff sendServerCommand(player, "eroge", "ClaimVehicle", { vehicle = vehicle:getId() }) end end) Events.OnServerCommand.Add(function(module, name, params) if module == "eroge" and name == "ClaimVehicle" then local vehicle = getVehicleById(params.vehicle) if vehicle ~= nil then --now client can get some keys in peace player:getInventory():AddItem(vehicle:getCurrentKey() or vehicle:createVehicleKey()) player:Say(getText("IGUI_zuzhuangchenggong")) end end end) Sorry but what does module == "eroge" means? Im totally noob to scripting Link to comment Share on other sites More sharing options...
Tykvesh Posted February 11, 2022 Share Posted February 11, 2022 It's just a namespace, kinda similar to "Base" module used for items, recipes and so on. You can name it however you want. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now