Frytka
Wiek: 25 Na forum: 1264 dni Posty: 4
Piwa : 4
potrzebuje pomocy z skryptem glosnik chcia?bym ?eby g?o?nik nie znika? po wyj?ciu z servera z g?ry dzi?ki za pomoc
server.lua
------------------------------------------
-- Author : xXMADEXx --
-- Polish version : Czaju --
-- Name : 3D Speakers 2.0 --
-- File : server . lua --
-- Copyright 2013 ( C ) Braydon Davis --
------------------------------------------
local isSpeaker = false
function print ( player , message , r , g , b )
outputChatBox ( message , player , r , g , b )
end
speakerBox = { }
addCommandHandler ( "glosnik" , function ( thePlayer )
if ( isElement ( speakerBox [ thePlayer ] ) ) then isSpeaker = true end
triggerClientEvent ( thePlayer , "onPlayerViewSpeakerManagment" , thePlayer , isSpeaker )
end )
addEvent ( "onPlayerPlaceSpeakerBox" , true )
addEventHandler ( "onPlayerPlaceSpeakerBox" , root , function ( url , isCar )
if ( url ) then
if ( isElement ( speakerBox [ source ] ) ) then
local x , y , z = getElementPosition ( speakerBox [ source ] )
print ( source , "Twoj glosnik zostal zniszczony: " .. math . floor ( x ).. ", " .. math . floor ( y ).. ", " .. math . floor ( z ), 255 , 0 , 0 )
destroyElement ( speakerBox [ source ] )
removeEventHandler ( "onPlayerQuit" , source , destroySpeakersOnPlayerQuit )
end
local x , y , z = getElementPosition ( source )
local rx , ry , rz = getElementRotation ( source )
speakerBox [ source ] = createObject ( 2229 , x - 0.5 , y + 0.5 , z - 1 , 0 , 0 , rx )
print ( source , "Twoj glosnik zostal postawiony na: " .. math . floor ( x ).. ", " .. math . floor ( y ).. ", " .. math . floor ( z ), 0 , 255 , 0 )
addEventHandler ( "onPlayerQuit" , source , destroySpeakersOnPlayerQuit )
triggerClientEvent ( root , "onPlayerStartSpeakerBoxSound" , root , source , url , isCar )
if ( isCar ) then
local car = getPedOccupiedVehicle ( source )
attachElements ( speakerBox [ source ], car , - 0.7 , - 1.5 , - 0.5 , 0 , 90 , 0 )
end
end
end )
addEvent ( "onPlayerDestroySpeakerBox" , true )
addEventHandler ( "onPlayerDestroySpeakerBox" , root , function ( )
if ( isElement ( speakerBox [ source ] ) ) then
destroyElement ( speakerBox [ source ] )
triggerClientEvent ( root , "onPlayerDestroySpeakerBox" , root , source )
removeEventHandler ( "onPlayerQuit" , source , destroySpeakersOnPlayerQuit )
print ( source , "Zniszczono stary glosnik." , 255 , 0 , 0 )
else
print ( source , "Nie masz glosnika." , 255 , 255 , 0 )
end
end )
addEvent ( "onPlayerChangeSpeakerBoxVolume" , true )
addEventHandler ( "onPlayerChangeSpeakerBoxVolume" , root , function ( to )
triggerClientEvent ( root , "onPlayerChangeSpeakerBoxVolumeC" , root , source , to )
end )
function destroySpeakersOnPlayerQuit ( )
if ( isElement ( speakerBox [ source ] ) ) then
destroyElement ( speakerBox [ source ] )
triggerClientEvent ( root , "onPlayerDestroySpeakerBox" , root , source )
end
end
client.lua
------------------------------------------
-- Author : xXMADEXx --
-- Polish version : Czaju --
-- Name : 3D Speakers 2.0 --
-- File : client . lua --
-- Copyright 2013 ( C ) Braydon Davis --
------------------------------
-- Variables --
------------------------------
local subTrackOnSoundDown = 0.1 -- The volume that goes down , when the player clicks "Volume -"
local subTrackOnSoundUp = 0.1 -- The volume that goes up , when the player clicks "Volume +"
function print ( message , r , g , b )
outputChatBox ( message , r , g , b )
end
------------------------------
-- The GUI --
------------------------------
local rx , ry = guiGetScreenSize ( )
button = { }
window = guiCreateWindow ( ( rx - 295 ), ( ry / 2 - 253 / 2 ), 293 , 253 , "Glosnik CripsRPG" , false )
guiWindowSetSizable ( window , false )
guiSetVisible ( window , false )
CurrentSpeaker = guiCreateLabel ( 8 , 33 , 254 , 17 , "Czy masz glosnik: Nie" , false , window )
volume = guiCreateLabel ( 10 , 50 , 252 , 17 , "Obecna glosnosc: 100%" , false , window )
pos = guiCreateLabel ( 10 , 66 , 252 , 15 , "X: 0 | Y: 0 | Z: 0" , false , window )
guiCreateLabel ( 11 , 81 , 251 , 15 , "URL:" , false , window )
-- url = guiCreateEdit ( 11 , 96 , 272 , 23 , "" , false , window )
url = guiCreateEdit ( 11 , 96 , 272 , 23 , "http://www.rmfon.pl/n/rmfmaxxx.pls" , false , window )
button [ "place" ] = guiCreateButton ( 9 , 129 , 274 , 20 , "Stworz" , false , window )
button [ "remove" ] = guiCreateButton ( 9 , 159 , 274 , 20 , "Usun" , false , window )
button [ "v-" ] = guiCreateButton ( 9 , 189 , 128 , 20 , "Glosnosc -" , false , window )
button [ "v+" ] = guiCreateButton ( 155 , 189 , 128 , 20 , "Glosnosc +" , false , window )
button [ "close" ] = guiCreateButton ( 9 , 219 , 274 , 20 , "Wyjscie" , false , window )
--------------------------
-- My sweet codes --
--------------------------
local isSound = false
addEvent ( "onPlayerViewSpeakerManagment" , true )
addEventHandler ( "onPlayerViewSpeakerManagment" , root , function ( current )
local toState = not guiGetVisible ( window )
guiSetVisible ( window , toState )
showCursor ( toState )
if ( toState == true ) then
guiSetInputMode ( "no_binds_when_editing" )
local x , y , z = getElementPosition ( localPlayer )
guiSetText ( pos , "X: " .. math . floor ( x ).. " | Y: " .. math . floor ( y ).. " | Z: " .. math . floor ( z ) )
if ( current ) then guiSetText ( CurrentSpeaker , "Czy masz glosnik: Tak" ) isSound = true
else guiSetText ( CurrentSpeaker , "Czy masz glosnik: Nie" ) end
end
end )
addEventHandler ( "onClientGUIClick" , root , function ( )
if ( source == button [ "close" ] ) then
guiSetVisible ( window , false )
showCursor ( false )
elseif ( source == button [ "place" ] ) then
if ( isURL ( ) ) then
triggerServerEvent ( "onPlayerPlaceSpeakerBox" , localPlayer , guiGetText ( url ), isPedInVehicle ( localPlayer ) )
guiSetText ( CurrentSpeaker , "Czy masz glosnik: Tak" )
isSound = true
guiSetText ( volume , "Obecna glosnosc: 100%" )
else
print ( "Musisz wprowadzic URL." , 255 , 0 , 0 )
end
elseif ( source == button [ "remove" ] ) then
triggerServerEvent ( "onPlayerDestroySpeakerBox" , localPlayer )
guiSetText ( CurrentSpeaker , "Czy masz glosnik: Nie" )
isSound = false
guiSetText ( volume , "Obecna glosnosc: 100%" )
elseif ( source == button [ "v-" ] ) then
if ( isSound ) then
local toVol = math . round ( getSoundVolume ( speakerSound [ localPlayer ] ) - subTrackOnSoundDown , 2 )
if ( toVol > 0.0 ) then
print ( "Glosnosc zmieniona na " .. math . floor ( toVol * 100 ).. "%!" , 0 , 255 , 0 )
triggerServerEvent ( "onPlayerChangeSpeakerBoxVolume" , localPlayer , toVol )
guiSetText ( volume , "Current Volume: " .. math . floor ( toVol * 100 ).. "%" )
else
print ( "Glosnosc nie moze byc nizsza." , 255 , 0 , 0 )
end
end
elseif ( source == button [ "v+" ] ) then
if ( isSound ) then
local toVol = math . round ( getSoundVolume ( speakerSound [ localPlayer ] ) + subTrackOnSoundUp , 2 )
if ( toVol < 1.1 ) then
print ( "Glosnosc zmieniona na " .. math . floor ( toVol * 100 ).. "%!" , 0 , 255 , 0 )
triggerServerEvent ( "onPlayerChangeSpeakerBoxVolume" , localPlayer , toVol )
guiSetText ( volume , "Current Volume: " .. math . floor ( toVol * 100 ).. "%" )
else
print ( "Glosnosc nie moze byc wyzsza." , 255 , 0 , 0 )
end
end
end
end )
speakerSound = { }
addEvent ( "onPlayerStartSpeakerBoxSound" , true )
addEventHandler ( "onPlayerStartSpeakerBoxSound" , root , function ( who , url , isCar )
if ( isElement ( speakerSound [ who ] ) ) then destroyElement ( speakerSound [ who ] ) end
local x , y , z = getElementPosition ( who )
speakerSound [ who ] = playSound3D ( url , x , y , z , true )
setSoundVolume ( speakerSound [ who ], 1 )
setSoundMinDistance ( speakerSound [ who ], 15 )
setSoundMaxDistance ( speakerSound [ who ], 20 )
if ( isCar ) then
local car = getPedOccupiedVehicle ( who )
attachElements ( speakerSound [ who ], car , 0 , 5 , 1 )
end
end )
addEvent ( "onPlayerDestroySpeakerBox" , true )
addEventHandler ( "onPlayerDestroySpeakerBox" , root , function ( who )
if ( isElement ( speakerSound [ who ] ) ) then
destroyElement ( speakerSound [ who ] )
end
end )
--------------------------
-- Volume --
--------------------------
addEvent ( "onPlayerChangeSpeakerBoxVolumeC" , true )
addEventHandler ( "onPlayerChangeSpeakerBoxVolumeC" , root , function ( who , vol )
if ( isElement ( speakerSound [ who ] ) ) then
setSoundVolume ( speakerSound [ who ], tonumber ( vol ) )
end
end )
function isURL ( )
if ( guiGetText ( url ) ~= "" ) then
return true
else
return false
end
end
function math . round ( number , decimals , method )
decimals = decimals or 0
local factor = 10 ^ decimals
if ( method == "ceil" or method == "floor" ) then return math [ method ]( number * factor ) / factor
else return tonumber (( "%." .. decimals .. "f" ): format ( number )) end
end
meta.xml
Kod: <meta>
<info author="xXMADEXx, Czaju" name="SpeakerSystem" type="script" version="1.4.1" />
<min_mta_version server="1.3.4-0.00000" client="1.3.4-0.00000" />
<script src="server.lua" />
<script src="client.lua" type="client" />
</meta>
Ostatnio zmieniony przez N0TH1NG 2023-01-27, 19:50, w całości zmieniany 3 razy