public void OnClientEvent(Client player, string eventName, params object[] arguments) { if (eventName == "request_delivery_info_from_server") { API.triggerClientEvent(player, "send_delivery_info_to_client", API.toJson(gasStations)); } if (eventName == "start_gas_trucking_job") { // create vehicles Vehicle hauler = API.createVehicle(VehicleHash.Hauler, new Vector3(1358.479, -2095.168, 52), new Vector3(0, 0, 30), 0, 0); Vehicle tanker = API.createVehicle(VehicleHash.Tanker, new Vector3(1478.65, -1941.525, 70.87663), new Vector3(-0.1540594, 1.219151, -58.19306), 0, 0); API.setEntitySyncedData(tanker.handle, "GAS", 6000); API.setEntitySyncedData(tanker.handle, "GAS_CAPACITY", 6000); // create contract object DeliveryContract contract = new DeliveryContract(player, tanker); contract.addDelivery(1, 2000); // 2000 gallons to gas station with id of 1 _retailerRepository.AddStockEnRoute(1, 2000); contracts.Add(contract); // create list of delivery locations from contract ArrayList deliveryLocs = new ArrayList(); foreach (var key in contract.Deliveries.Keys) { deliveryLocs.Add(_retailerRepository.GetRetailerById(key)); } // send delivery locations to player var deliveryLocsJson = API.toJson(deliveryLocs); var jobEndPosJson = API.toJson(jobEndPos); API.triggerClientEvent(player, "send_delivery_locations_from_server", deliveryLocsJson, tanker.handle, hauler.handle, jobEndPosJson); } else if (eventName == "player_deliver_gas") { // find the players delivery contract DeliveryContract contract = null; foreach (DeliveryContract c in contracts) { if (c.Player == player) { contract = c; } } // deliver gas var stationId = API.getEntityData(player.handle, "IS_ABLE_TO_DELIVER_TO_STATION"); API.sendChatMessageToPlayer(player, "you are delivering " + contract.Deliveries[stationId] + " gallons of gasoline to station: " + stationId.ToString()); _retailerRepository.AddRetailerStock(stationId, contract.Deliveries[stationId]); // remove delivery from contract contract.removeDelivery(stationId); API.sendChatMessageToPlayer(player, "deliveries remaining: " + contract.Deliveries.Count.ToString()); // trigger client event API.triggerClientEvent(player, "player_delivered_gas", stationId); } }