nick1995 Posted May 11, 2012 Share Posted May 11, 2012 Hi everyone, I have the resource water_level (https://community.multitheftauto.com/index.php?p= ... ils&id=630) Now i want if the water level is going up, that he played a sound "alarm.mp3" I have readed that i have to add in the meta.xml this: "alarm.mp3" type="client" /> But where and what have i to do here: water_level.lua level = 0 highlevel = 0 floodWater1 = 0 function setAllWatersLevel(level) setWaterLevel(level) if isElement(floodWater1) then if (getElementType(floodWater1) == "water") then if (level > 0.2) then setWaterLevel(floodWater1, level) else setWaterLevel(floodWater1, -500) end end end end function checkLevel(glevel) local allow_negative = get("allow_negative") if ((allow_negative == "false") and (tonumber(glevel) < 0)) then return false end return true end function setFloodWeather() local flood_weather = get("flood_weather") if (flood_weather ~= "") then setWeather(tonumber(flood_weather)) end end function setFloodEndWeather() local flood_end_weather = get("flood_end_weather") if (flood_end_weather ~= "") then setWeather(tonumber(flood_end_weather)) end end function waterLevel ( source, glevel ) if ( checkLevel(glevel) == true ) then highlevel = tonumber ( glevel ) if (highlevel == nil) then highlevel = 0 end if (highlevel ~= level) then if ( isTimer(waterTimer)) then killTimer(waterTimer) end --water is going up if (highlevel > level) then setFloodWeather() waterTimer = setTimer ( addSomeWater, 100, 0, highlevel ) if (get("show_messages") == "true") then if (highlevel > -0.2) then outputChatBox ( "ALERT: A FLOOD IS EMERGING! WE ESTIMATE A WATER LEVEL OF "..tostring(highlevel).." meters", getRootElement(), 255, 0, 0 ) else outputChatBox ( "INFO: A DROUGHT IS LEAVING! WE RETURN TO A WATER LEVEL OF "..tostring(highlevel).." meters", getRootElement(), 0, 255, 0 ) end end else --water is going down setFloodEndWeather() waterTimer = setTimer ( removeSomeWater, 100, 0, highlevel ) if (get("show_messages") == "true") then if (highlevel > -0.2) then outputChatBox ( "INFO: A FLOOD IS LEAVING! WE RETURN TO A WATER LEVEL OF "..tostring(highlevel).." meters", getRootElement(), 0, 255, 0 ) else outputChatBox ( "ALERT: A DROUGHT IS COMING! WE ESTIMATE A WATER LEVEL OF "..tostring(highlevel).." meters", getRootElement(), 255, 0, 0 ) end end end outputDebugString ( "Water Level changed by " .. getPlayerName ( source ) .. " to a level " .. highlevel .. ".", 3 ) end end end addEvent( "onWaterLevel", true ) addEventHandler( "onWaterLevel", getRootElement(), waterLevel ) function showClientGui(source, command, highlevel) local neg = get("allow_negative") if (get("restrict_to") ~= "") then if ( isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( source )), aclGetGroup ( get("restrict_to") ) ) ) then triggerClientEvent( source, "onShowWindow", getRootElement(), level, neg, highlevel) end else triggerClientEvent( source, "onShowWindow", getRootElement(), level, neg, highlevel) end end addCommandHandler("water", showClientGui) function addSomeWater ( highlevel ) local thelevel = level local speed = tonumber(get("speed")) level = thelevel + tonumber(speed) setAllWatersLevel(level) if (level >= highlevel) then level = highlevel if ( isTimer(waterTimer)) then killTimer(waterTimer) end setFloodEndWeather() end end function removeSomeWater ( highlevel ) local thelevel = level local speed = tonumber(get("speed")) level = thelevel - speed setAllWatersLevel(level) if (level <= highlevel) then level = highlevel if ( isTimer(waterTimer)) then killTimer(waterTimer) end end end function initialize() setWaterLevel(0) floodWater1 = createWater ( -2998, -2998, -500, 2998, -2998, -500, -2998, 2998, -500, 2998, 2998, -500) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), initialize) function destroy() if ( isTimer(waterTimer)) then killTimer(waterTimer) end setWaterLevel(floodWater1, -500) setWaterLevel(0) setFloodEndWeather() end addEventHandler ( "onResourceStop", getRootElement(), destroy) function onPlayerJoin() setAllWatersLevel(level) end addEventHandler( "onPlayerJoin", getRootElement(), onPlayerJoin ) You can see this: function waterLevel ( source, glevel ) if ( checkLevel(glevel) == true ) then highlevel = tonumber ( glevel ) if (highlevel == nil) then highlevel = 0 end if (highlevel ~= level) then if ( isTimer(waterTimer)) then killTimer(waterTimer) end --water is going up if (highlevel > level) then setFloodWeather() waterTimer = setTimer ( addSomeWater, 100, 0, highlevel ) if (get("show_messages") == "true") then if (highlevel > -0.2) then outputChatBox ( "ALERT: A FLOOD IS EMERGING! WE ESTIMATE A WATER LEVEL OF "..tostring(highlevel).." meters", getRootElement(), 255, 0, 0 ) else outputChatBox ( "INFO: A DROUGHT IS LEAVING! WE RETURN TO A WATER LEVEL OF "..tostring(highlevel).." meters", getRootElement(), 0, 255, 0 ) end end else --water is going down I hope someone can help me. I am learning to script MTA Link to comment
nick1995 Posted May 12, 2012 Author Share Posted May 12, 2012 I had try that, but what have i to do. In the meta it is good, but in the script? I had try that, but there wasn't a sound, i think i do something wrong, thats the reason for this topic... Link to comment
Moderators IIYAMA Posted May 12, 2012 Moderators Share Posted May 12, 2012 https://wiki.multitheftauto.com/wiki/PlaySound local sound = playSound("alarm.mp3") Make sure your mta sounds are ON. (settings) It does work. if (highlevel > -0.2) then outputChatBox ( "ALERT: A FLOOD IS EMERGING! WE ESTIMATE A WATER LEVEL OF "..tostring(highlevel).." meters", getRootElement(), 255, 0, 0 ) local sound = playSound("alarm.mp3") else Link to comment
nick1995 Posted May 12, 2012 Author Share Posted May 12, 2012 I get the same error, [2012-05-12 18:54:20] ERROR: unzipped\water_level2\water_level.lua:57: attempt to call global 'playSound' (a nil value) Link to comment
Booo Posted May 12, 2012 Share Posted May 12, 2012 I get the same error, [2012-05-12 18:54:20] ERROR: unzipped\water_level2\water_level.lua:57: attempt to call global 'playSound' (a nil value) you problem here !! where level global ?? function showClientGui(source, command, highlevel) local neg = get("allow_negative") if (get("restrict_to") ~= "") then if ( isObjectInACLGroup ( "user." .. getAccountName ( getPlayerAccount ( source )), aclGetGroup ( get("restrict_to") ) ) ) then triggerClientEvent( source, "onShowWindow", getRootElement(), level, neg, highlevel) end else triggerClientEvent( source, "onShowWindow", getRootElement(), level, neg, highlevel) end end addCommandHandler("water", showClientGui) Link to comment
nick1995 Posted May 12, 2012 Author Share Posted May 12, 2012 I'm sorry, I don't understand you Link to comment
Moderators IIYAMA Posted May 12, 2012 Moderators Share Posted May 12, 2012 maybe you must put it in an unzipped folder? Link to comment
Moderators IIYAMA Posted May 12, 2012 Moderators Share Posted May 12, 2012 You know this is cliend side? Link to comment
Jaysds1 Posted May 12, 2012 Share Posted May 12, 2012 https://wiki.multitheftauto.com/wiki/Cli ... _functions Link to comment
nick1995 Posted May 12, 2012 Author Share Posted May 12, 2012 https://wiki.multitheftauto.com/wiki/Client_Scripting_Functions#Audio_functions Yes i have readed that, but i dont understand how to get it in my script... And my post is deleted.... Link to comment
Jaysds1 Posted May 12, 2012 Share Posted May 12, 2012 Do you have a client side to that resource? Link to comment
nick1995 Posted May 12, 2012 Author Share Posted May 12, 2012 Do you have a client side to that resource? What is a client side exactly? I have google it, but i dont understand it.. Link to comment
Castillo Posted May 13, 2012 Share Posted May 13, 2012 https://wiki.multitheftauto.com/wiki/Client_side_scripts Link to comment
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