![]() |
help with hotdog vendor samp - Printable Version + open.mp forum (https://forum.open.mp) -- Forum: General (https://forum.open.mp/forumdisplay.php?fid=19) --- Forum: Programming (https://forum.open.mp/forumdisplay.php?fid=56) --- Thread: help with hotdog vendor samp (/showthread.php?tid=3140) |
help with hotdog vendor samp - Axzyl - 2025-03-24 #include <a_samp> #define VEHICLE_MODEL_ID 588 #define SELLER_SKIN 40 #define HOTDOG_COST 100 #define HOTDOG_HP 100 #define SELLER_REWARD 3000 #define MAX_VENDORS 5 // You can set this to the maximum number of vendor vehicles you want to allow #define KEY_2 0x2000 // Define 2 key #define KEY_LALT 0x40000 // Define Left Alt key #define COLOR_GREEN 0x00FF00FF #define COLOR_YELLOW 0xFFFF00FF #define COLOR_WHITE 0xFFFFFFFF #define COLOR_RED 0xFF0000FF new g_VehicleIDs[MAX_VENDORS]; new g_Sellers[MAX_VENDORS] = {INVALID_PLAYER_ID, INVALID_PLAYER_ID, INVALID_PLAYER_ID, INVALID_PLAYER_ID, INVALID_PLAYER_ID}; new g_VendorSelling[MAX_VENDORS] = {false, false, false, false, false}; // Coordinates for vehicle spawn new Float:spawnX = 404.0; new Float:spawnY = 2135.5701; new Float:spawnZ = 1442.1515; new Float:spawnAngle = 269.9492; public OnGameModeInit() { // Spawn multiple vehicles at specified coordinates for (new i = 0; i < MAX_VENDORS; i++) { g_VehicleIDs[i] = AddStaticVehicle(VEHICLE_MODEL_ID, spawnX + (i * 3), spawnY, spawnZ, spawnAngle, 1, 1); // Slight offset to avoid overlap } SetTimer("CheckVehiclePositions", 300000, true); // Check every 5 minutes for vehicles' positions return 1; } // Pressing "2" to toggle selling hotdogs public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { // Check if player presses "2" if (newkeys & KEY_2) { // Check if the player is inside a vendor vehicle (ID 588) new vehicleid = GetPlayerVehicleID(playerid); if (vehicleid != INVALID_VEHICLE_ID && GetVehicleModel(vehicleid) == VEHICLE_MODEL_ID) { // Loop through all vendor vehicles to find the player's assigned vehicle for (new i = 0; i < MAX_VENDORS; i++) { if (g_VehicleIDs[i] == vehicleid) // The player is inside a valid vendor vehicle { // Check if the player is already a vendor if (g_Sellers[i] == INVALID_PLAYER_ID) { g_Sellers[i] = playerid; // Assign the player as the vendor for this vehicle g_VendorSelling[i] = true; // Start selling for this vehicle SendClientMessage(playerid, COLOR_GREEN, "You are now the Hotdog Vendor!"); SendClientMessageToAll(COLOR_YELLOW, "A new Hotdog vendor has started selling!"); } break; } } } } // If player presses Left Alt (KEY_LALT) to buy hotdog if (newkeys & KEY_LALT) { // Loop through all vendor vehicles for (new i = 0; i < MAX_VENDORS; i++) { if (g_VendorSelling[i] && !IsPlayerInVehicle(playerid)) // Ensure player is not in vehicle and vendor is selling { if (GetPlayerMoney(playerid) >= HOTDOG_COST) { // Increase health new currentHealth = GetPlayerHealth(playerid); SetPlayerHealth(playerid, currentHealth + HOTDOG_HP); // Subtract money GivePlayerMoney(playerid, -HOTDOG_COST); SendClientMessage(playerid, COLOR_WHITE, "You bought a Hotdog and gained 100 HP!"); // Give seller reward if (g_Sellers[i] != INVALID_PLAYER_ID) { GivePlayerMoney(g_Sellers[i], SELLER_REWARD); SendClientMessage(g_Sellers[i], COLOR_YELLOW, "You earned $3000 from a Hotdog sale!"); } } else { SendClientMessage(playerid, COLOR_RED, "You don't have enough money for a Hotdog!"); } } } } return 1; } // When a player exits a vehicle, they stop being the vendor public OnPlayerExitVehicle(playerid, vehicleid) { for (new i = 0; i < MAX_VENDORS; i++) { if (vehicleid == g_VehicleIDs[i] && playerid == g_Sellers[i]) // If the player leaves the vendor vehicle { SendClientMessage(playerid, COLOR_RED, "You have left the vehicle and stopped selling hotdogs."); g_Sellers[i] = INVALID_PLAYER_ID; // Clear the vendor role g_VendorSelling[i] = false; // Stop selling hotdogs for this vehicle } } return 1; } // Check if any vehicle is moved, respawn if needed forward CheckVehiclePositions(); public CheckVehiclePositions() { for (new i = 0; i < MAX_VENDORS; i++) { // Check if the vendor vehicle exists at the spawn location new Float:vehX, Float:vehY, Float:vehZ; GetVehiclePos(g_VehicleIDs[i], vehX, vehY, vehZ); // If the vendor vehicle is not at the spawn location if (floatabs(vehX - (spawnX + (i * 3))) > 10.0 || floatabs(vehY - spawnY) > 10.0 || floatabs(vehZ - spawnZ) > 10.0) // 10 units tolerance { // Try to spawn a new vehicle if it doesn't exist at the spawn point new vehicleid = INVALID_VEHICLE_ID; // Loop through all possible vehicle IDs (vehicle IDs are indexed from 1) for (new vehicleIndex = 1; vehicleIndex <= MAX_VEHICLES; vehicleIndex++) { vehicleid = vehicleIndex; // Check each vehicle ID if (vehicleid != INVALID_VEHICLE_ID) { new Float:checkX, Float:checkY, Float:checkZ; GetVehiclePos(vehicleid, checkX, checkY, checkZ); // If vehicle is within a 10-unit radius of the spawn location if (floatabs(checkX - (spawnX + (i * 3))) <= 10.0 && floatabs(checkY - spawnY) <= 10.0 && floatabs(checkZ - spawnZ) <= 10.0) { // Vehicle is close enough, no need to respawn vehicleid = INVALID_VEHICLE_ID; break; } } } // If no vehicle found at spawn point, spawn a new one if (vehicleid == INVALID_VEHICLE_ID) { g_VehicleIDs[i] = AddStaticVehicle(VEHICLE_MODEL_ID, spawnX + (i * 3), spawnY, spawnZ, spawnAngle, 1, 1); SendClientMessageToAll(COLOR_YELLOW, "A vendor vehicle has been reset to its original location!"); } } } return 1; } so this: SetTimer("CheckVehiclePositions", 300000, true); // Check every 5 minutes for vehicles' positions and this: if (g_VendorSelling[i] && !IsPlayerInVehicle(playerid)) // Ensure player is not in vehicle and vendor is selling and this: new currentHealth = GetPlayerHealth(playerid); has warning messages saying for the first one: (36) warning 239: literal array/string passed to a non-const parameter second one: (75) warning 202: number of arguments does not match definition and third one: (81) warning 202: number of arguments does not match definition. please help ;3 RE: help with hotdog vendor samp - Axzyl - 2025-03-24 its a filterscript RE: help with hotdog vendor samp - Axzyl - 2025-03-24 i wanna make sure that vehicle spawns there but respawns every 5 min if its no longer in that position, that players entering any hotdog vehicle can toggle job by pressing 2 that players next to it can buy by pressing left alt. idk why its so complicated RE: help with hotdog vendor samp - Axzyl - 2025-03-24 (404,2135.5701,1442.1515,10.5530,269.9492,1,1); vehicle position and Vehicle Model ID: 588 RE: help with hotdog vendor samp - J0nathan550 - 2025-04-14 (2025-03-24, 09:27 AM)Axzyl Wrote: i wanna make sure that vehicle spawns there but respawns every 5 min if its no longer in that position, that players entering any hotdog vehicle can toggle job by pressing 2 that players next to it can buy by pressing left alt. idk why its so complicated Hello, you have a flag in your script that tells that you "own" a van but you never use it. In function: Code: forward CheckVehiclePositions(); |