help lua streamzone

Sam201

Известный
Автор темы
103
5
Версия MoonLoader
.027.0-preview
lua:
require "moonloader"

local sampev = require "lib.samp.events"
local isEnabled = true -- Default to enabled
local soundId = 0

function main()
    while not isSampAvailable() do wait(0) end -- Wait for SA-MP to become available
    sampAddChatMessage("{3498DB}Checkshamal by V", -1)
    sampRegisterChatCommand("checkshamal", toggleShamalCheck)
    soundId = loadAudioStream("shamal.mp3")
end

function toggleShamalCheck()
    isEnabled = not isEnabled
    if isEnabled then
        sampAddChatMessage("{2471A3}Checkshamal{FFFFFF} has been {0FFF00}Enabled", -1)
    else
        sampAddChatMessage("{2471A3}Checkshamal{FFFFFF} has been {FF0000}Disabled", -1)
    end
end

function checkShamal()
    if isEnabled then
        local vehicles = sampGetVehiclePool()
        for i = 1, #vehicles do
            local modelId = sampGetVehicleModel(vehicles[i])
            if modelId == 519 then -- Model ID of Shamal vehicle
                playAudioStream(soundId)
                return
            end
        end
    end
end

sampAddChatMessage("{FF0000}Script loaded successfully! Use /checkshamal to toggle Shamal vehicle check.", -1)
main()



code supposed to play a sound when vehicle shamal is in player streamzone the code works but it doesn't play sound anyone can help me out with this?
 

qdIbp

Автор темы
Проверенный
1,450
1,191
lua:
require "moonloader"

local sampev = require "lib.samp.events"
local isEnabled = true -- Default to enabled
local soundId = 0

function main()
    while not isSampAvailable() do wait(0) end -- Wait for SA-MP to become available
    sampAddChatMessage("{3498DB}Checkshamal by V", -1)
    sampRegisterChatCommand("checkshamal", toggleShamalCheck)
    soundId = loadAudioStream("shamal.mp3")
end

function toggleShamalCheck()
    isEnabled = not isEnabled
    if isEnabled then
        sampAddChatMessage("{2471A3}Checkshamal{FFFFFF} has been {0FFF00}Enabled", -1)
    else
        sampAddChatMessage("{2471A3}Checkshamal{FFFFFF} has been {FF0000}Disabled", -1)
    end
end

function checkShamal()
    if isEnabled then
        local vehicles = sampGetVehiclePool()
        for i = 1, #vehicles do
            local modelId = sampGetVehicleModel(vehicles[i])
            if modelId == 519 then -- Model ID of Shamal vehicle
                playAudioStream(soundId)
                return
            end
        end
    end
end

sampAddChatMessage("{FF0000}Script loaded successfully! Use /checkshamal to toggle Shamal vehicle check.", -1)
main()



code supposed to play a sound when vehicle shamal is in player streamzone the code works but it doesn't play sound anyone can help me out with this?
Lua:
require("moonloader")
local sampev = require("lib.samp.events")
local isEnabled = true -- Default to enabled
local soundId = 0

function main()
    while not isSampAvailable() do wait(0) end -- Wait for SA-MP to become available
        sampAddChatMessage("{3498DB}Checkshamal by V", -1)
        sampAddChatMessage("Script loaded successfully! Use /checkshamal to toggle Shamal vehicle check.",0xFF0000)

        sampRegisterChatCommand("checkshamal", toggleShamalCheck)
        soundId = loadAudioStream("shamal.mp3")
    wait(-1)
end

function toggleShamalCheck()
    isEnabled = not isEnabled
    sampAddChatMessage("Checkshamal{FFFFFF} has been " ..(isEnabled and "{0FFF00}Enabled" or "{FF0000}Disabled"), 0x2471A3)
end

function checkShamal()
    if isEnabled then
        local vehicles = sampGetVehiclePool()
        for i = 1, #vehicles do
            local modelId = sampGetVehicleModel(vehicles[i])
            if modelId == 519 then -- Model ID of Shamal vehicle
                playAudioStream(soundId)
                return
            end
        end
    end
end

Although it is better to do so in function checkShamal()

Lua:
function checkShamal()
    if isEnabled then
        for i,k in getAllVehicles() do
            local modelId = getCarModel(k)
            if modelId == 519 then -- Model ID of Shamal vehicle
                playAudioStream(soundId)
                return
            end
        end
    end
end

Or do you have a different system?
 

Sam201

Известный
Автор темы
103
5
Lua:
require("moonloader")
local sampev = require("lib.samp.events")
local isEnabled = true -- Default to enabled
local soundId = 0

function main()
    while not isSampAvailable() do wait(0) end -- Wait for SA-MP to become available
        sampAddChatMessage("{3498DB}Checkshamal by V", -1)
        sampAddChatMessage("Script loaded successfully! Use /checkshamal to toggle Shamal vehicle check.",0xFF0000)

        sampRegisterChatCommand("checkshamal", toggleShamalCheck)
        soundId = loadAudioStream("shamal.mp3")
    wait(-1)
end

function toggleShamalCheck()
    isEnabled = not isEnabled
sampAddChatMessage("Checkshamal{FFFFFF} has been " .. (isEnabled and "{0FFF00}Enabled" or "{FF0000}Disabled"), 0x2471A3)
end

function checkShamal()
    if isEnabled then
        local vehicles = sampGetVehiclePool()
        for i = 1, #vehicles do
            local modelId = sampGetVehicleModel(vehicles[i])
            if modelId == 519 then -- Model ID of Shamal vehicle
                playAudioStream(soundId)
                return
            end
        end
    end
end

Although it is better to do so in function checkShamal()

Lua:
function checkShamal()
    if isEnabled then
        for i,k in getAllVehicles() do
            local modelId = getCarModel(k)
            if modelId == 519 then -- Model ID of Shamal vehicle
                playAudioStream(soundId)
                return
            end
        end
    end
end

Or do you have a different system?


lua:
require("moonloader")
local sampev = require("lib.samp.events")
local isEnabled = true -- Default to enabled

function main()
    while not isSampAvailable() do wait(0) end -- Wait for SA-MP to become available
        sampAddChatMessage("{3498DB}Checkshamal by V", -1)
        sampAddChatMessage("Script loaded successfully! Use /checkshamal to toggle Shamal vehicle check.",0xFF0000)

        sampRegisterChatCommand("checkshamal", toggleShamalCheck)
    wait(-1)
end

function toggleShamalCheck()
    isEnabled = not isEnabled
 sampAddChatMessage("Checkshamal{FFFFFF} has been " .. (isEnabled and "{0FFF00}Enabled" or "{FF0000}Disabled"), 0x2471A3)
end

function checkShamal()
    if isEnabled then
        for i,k in getAllVehicles() do
            local modelId = getCarModel(k)
            if modelId == 519 then -- Model ID of Shamal vehicle
                sampAddChatMessage("found it", -1)
                return
            end
        end
    end
end



i tried this instead of sound sampaddchat "found" if found shamal but it still didnt show up the problem is in the find shamal code i dont really know how to fix it

lua:
local moonloader = require('moonloader')
local sampfuncs = require('sampfuncs')
local sampev = require('lib.samp.events') -- Added SAMPEvents library
local isEnabled = true -- Default to enabled

function main()
    while not isSampAvailable() do wait(0) end -- Wait for SA-MP to become available
        sampAddChatMessage("{3498DB}Checkshamal by V", -1)
        sampAddChatMessage("Script loaded successfully! Use /checkshamal to toggle Shamal vehicle check.",0xFF0000)

        sampRegisterChatCommand("checkshamal", toggleShamalCheck)
    wait(-1)
end

function toggleShamalCheck()
    isEnabled = not isEnabled
sampAddChatMessage("Checkshamal{FFFFFF} has been " .. (isEnabled and "{0FFF00}Enabled" or "{FF0000}Disabled"), 0x2471A3)
end

function checkShamal()
    local playerVehicle = sampfuncs.getPlayerVehicle()
    local streamZone = sampfuncs.getActiveStreamZone()
    for _, k in ipairs(sampfuncs.getStreamedVehicles()) do -- Use sampfuncs.getStreamedVehicles() instead of sampfuncs.getAllVehicles() to only check vehicles in the player's streaming zone
        if sampfuncs.getVehicleModel(k) == 519 then -- Model ID of Shamal vehicle
            if sampfuncs.getVehicleStreamedScript(k) == streamZone then -- Check if the Shamal vehicle is in the player's streaming zone
                local driver = sampfuncs.getVehicleDriverId(k)
                if driver == 65535 and k ~= playerVehicle then -- If there is no driver in the vehicle and the player is not in the vehicle
                    sampfuncs.addChatMessage("Empty Shamal found!", 0x00FF00) -- Use a different chat color to signify an empty Shamal has been found
                end
            end
        end
    end
end

-- Added SAMPEvents callback to toggle Shamal check on/off when the player enters a vehicle
function sampev.onPlayerStateChange(playerId, newState, oldState)
    if playerId == sampfuncs.getPlayerId() and newState == 17 then -- Check if this is the local player and the new state is inside a vehicle
        isEnabled = false -- Disable Shamal check when the player gets inside a vehicle
    elseif playerId == sampfuncs.getPlayerId() and oldState == 17 then -- Check if this is the local player and the old state is inside a vehicle
        isEnabled = true -- Re-enable Shamal check when the player gets out of a vehicle
    end
end



new code still not working neither OnplayerStateChange function is working
 
Последнее редактирование:
  • Эм
Реакции: qdIbp