myjobisgop
Members-
Posts
39 -
Joined
-
Last visited
Everything posted by myjobisgop
-
TAPL, I.e. I must to create a event of music stop on the client side and run it from the server side? And yet. For example, the player A turned a music player. Then the server goes the new player B. New player B doesn't listen to music, which turned player A. How to make so B could hear A music?
-
TAPL, OK, but now there was another problem. So: --Server side function stopMusic(thePlayer, key, keyState) local playerVehicle = getPedOccupiedVehicle(thePlayer); if (playerVehicle ~= false) then local playerVehicleAttachedElements = getAttachedElements(playerVehicle) if playerVehicleAttachedElements then for ElementKey, ElementValue in ipairs (playerVehicleAttachedElements) do if (getElementData(ElementValue, "MusicPlayer") == 1) then destroyElement(ElementValue); break; end end outputChatBox("0!", thePlayer, 255, 0, 0, true) return 0 else outputChatBox("-2!", thePlayer, 255, 0, 0, true) return (-2) end else outputChatBox("-1!", thePlayer, 255, 0, 0, true) return (-1) end end When i enter 0 button, in chat script whites "0!", but sound doest't stop. Why? Could this be due to the fact that data element 'MusicPlayer' sets in client side?
-
If I understand you correctly, i must do so: function stopMusic(thePlayer, key, keyState) local playerVehicle = getPedOccupiedVehicle(thePlayer); if (playerVehicle ~= false) then local playerVehicleAttachedElements = getAttachedElements(playerVehicle) if playerVehicleAttachedElements then for ElementKey, ElementValue in ipairs (playerVehicleAttachedElements) do if (getElementData(ElementValue, "MusicPlayer") == 1) then destroyElement(ElementValue); break; end end outputChatBox("0!", thePlayer, 255, 0, 0, true) return 0 else outputChatBox("-2!", thePlayer, 255, 0, 0, true) return (-2) end else outputChatBox("-1!", thePlayer, 255, 0, 0, true) return (-1) end end addEventHandler("onPlayerJoin", root, function() bindKey(source, "0", "down", stopMusic) end) addEventHandler("onResourceStart", root, function() bindKey(getElementsByType("player"), "0", "down", stopMusic) end) It is right?
-
I made: function bindKeyHandler() bindKey(source, "0", "down", stopMusic) end addEventHandler("onPlayerJoin", root, bindKeyHandler) addEventHandler("onResourceStart", root, bindKeyHandler) but, debugscripter shows the same error.
-
Solidsnake14, I did so: --Server side code function stopMusic(thePlayer, key, keyState) ... end function bindKeyHandler(source) bindKey(source, "0", "down", stopMusic) end addEventHandler("onPlayerJoin", root, bindKeyHandler) addEventHandler("onResourceStart", root, bindKeyHandler) But now /debugscript 3 shows "Bad 'player' pointer @' bindKey(1)" Why?
-
No. it is a server side script.
-
So, Now I want that If player turn music, he can turn off music using the 0 button. I wrote a script in server side as: server.lua function stopMusic(thePlayer, key, keyState) local playerVehicle = getPedOccupiedVehicle(thePlayer); if (playerVehicle ~= false) then local playerVehicleAttachedElements = getAttachedElements(playerVehicle) if playerVehicleAttachedElements then for ElementKey, ElementValue in ipairs (playerVehicleAttachedElements) do if (getElementData(ElementValue, "MusicPlayer") == 1) then destroyElement(ElementValue); break; end end outputChatBox("Music player off!", thePlayer, 255, 0, 0, true) return 0 else return (-2) end else return (-1) end end bindKey(getLocalPlayer(), "0", "down", stopMusic) But when i press the 0 button - then nothing happens.Why is it so?
-
manawydan, Your script has started. But when i enter a command "sm", debugscript dispalays: music/music.lua:20:attempt to call global 'triggerClientEvent' (a nil value)
-
Ohh, Can you tell more about 1? Is it hard? Because i am a new in mta scripting.
-
Yes. Now script is working. But: 1)Music hears only the player who runs the command. And I wanted the music heard all players that are near the player. How can it do? 2)If a player re-enters the command "sm", then the music starts to overlap the previous one. How can this be solved?
-
My script contains 2 files and 1 folder for music meta.xml music.lua music_tracks - Folder for mp3 tracks. meta.xml <meta> <info author="myjobisgop" description="Music" version="1.0" type="script"/> <script src="music.lua" type="shared"/> <file src="music_tracks/1.mp3" download="true"/> <file src="music_tracks/2.mp3" download="true"/> </meta> music.lua function setMusicForPlayer(source, command, trackNumber) --Load player vehicle local playerVehicle = getPedOccupiedVehicle(source); --Is player driving a car now? if playerVehicle then --Is player entering a track number. if (trackNumber ~= '') then local TN = tonumber(trackNumber) --Is value of track number being a natural number and >= 1 and < 3. if (TN >= 1 and TN < 3) then --Get the coordinates of player vehicle local pvX, pvY, pvZ = getElementPosition(playerVehicle) --Load sound file local Sound = playSound3D( 'music_tracks/'..TN..'.mp3', pvX, pvY, pvZ) --Check for successfull load. if (Sound) then attachElements(Sound,source,0,0,0) setSoundMaxDistance(Sound, 100); outputChatBox("Track #"..TN.." is now playing in a music player.", source, 255, 0, 0, true) else outputChatBox("Error loading tracks", source, 255, 0, 0, true) end else outputChatBox("Track number enters incorrect!", source, 255, 0, 0, true) end else outputChatBox("You didn't enter a track number!", source, 255, 0, 0, true) end else outputChatBox("You don't turn a music player if you are not in the vehicle!", source, 255, 0, 0, true) end end addCommandHandler("sm", setMusicForPlayer)
-
Yes and when player drives a vehicle!
-
I did as told manawydan and it works. But was appearing a new problem. The variable playerVehicle accepts only false value constantly.Why is it so?
-
Good evening.I have a problem with my script This script must to play music, when the player drives vehicle. It works the next rule: When player in vehicle, he writes in a chat a command /sm [track number] and later in his car starts to play music track with number [track number] I did this: music.lua function setMusicForPlayer(source, command, trackNumber) --Load player vehicle local playerVehicle = getPedOccupiedVehicle(source); --Is player driving a car now? if playerVehicle then --Is player entering a track number. if (trackNumber ~= nil) then TN = tonumber(trackNumber) --Is value of track number being a natural number and >= 1 and < 3. if ((TN ~= nil) and (TN >= 1 AND TN < 3)) then --Get the coordinates of player vehicle local pvX, pvY, pvZ = getElementPosition(playerVehicle) --Load sound file local Sound = playSound3D( 'music_tracks/'..TN..'.mp3', pvX, pvY, pvZ) --Check for successfull load. if (Sound ~= false) then setSoundMaxDistance(Sound, 100); outputChatBox("Track #"..TN.." is now playing in a music player.", source, 255, 0, 0, true) else outputChatBox("Error loading tracks", source, 255, 0, 0, true) end else outputChatBox("Track number enters incorrect!", source), 255, 0, 0, true) end else outputChatBox("You didn't enter a track number!", source, 255, 0, 0, true) end local pvX, pvY, pvZ = getElementPosition(playerVehicle) else outputChatBox("You don't turn a music player if you are not in the vehicle!", source, 255, 0, 0, true) end end addCommandHandler("sm", setMusicForPlayer) meta.xml <meta> <info description="Music" version="1.0" type="script"/> <script src="music.lua" type="client"/> </meta> music_track - folder for mp3 tracks. Script loads successfully in a server. But when i enter a comand /sm [track_number] nothing happens.Even if a player drives the vehicle then too there is no response. Why is it so?
