Advertisement
julioCCs

SoundsDemo.vb

Mar 19th, 2013
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.75 KB | None | 0 0
  1. Imports System
  2. Imports System.Windows.Forms
  3. Imports GTA
  4. Imports System.IO
  5.  
  6. Public Class SoundsDemo
  7.     Inherits Script
  8.     private bSOn as boolean = false
  9.     Private l As Int32 = 0
  10.     Private linhas As String()
  11.     Private effect As Int32
  12.     private coef as int16 = 1
  13.     private effectSize as double = 1.0
  14.     private sFilter as string = ""
  15.     private xRot, yRot, zRot as double
  16.     private bRadians as boolean
  17.     private soundID as int32 = 0
  18.     private actualSound as string = ""
  19.     private actualSoundBack as string = ""
  20.     private soundPos as vector3
  21.     dim f As File
  22.    
  23.     Public Sub New()
  24.         Me.Interval = 100
  25.  
  26.         linhas = f.ReadAllLines(".\scripts\sounds.txt")
  27.         f.WriteAllLines(".\scripts\sounds.txt.back", linhas)
  28.     End Sub
  29.  
  30.     private sub console_CMD(ByVal sender As Object, ByVal e As ConsoleEventArgs) Handles MyBase.ConsoleCommand
  31.         if e.command = "sd" then       
  32.             bSOn = not bSOn
  33.            
  34.             if bSOn then
  35.                 msg("SoundsDemo ON", 3000)
  36.             else
  37.                 msg("SoundsDemo OFF", 3000)
  38.             end if
  39.         end if
  40.        
  41.         if e.command = "sfilter" then
  42.             if not bSOn then exit sub
  43.            
  44.             if e.parameterCount = 0 then
  45.                 game.console.print("Sound filter: " & sFilter)
  46.             else
  47.                 sFilter = e.parameter(0).tolower
  48.                 l = 0
  49.             end if
  50.         end if
  51.     end sub
  52.    
  53.     Private Sub msg(ByVal smsg As String, ByVal duracao As int32)
  54.         Native.Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", "STRING", smsg, duracao, 1)
  55.     End Sub
  56.  
  57.     Private Function findLinePos
  58.         For c As Int32 = 0 to linhas.length - 1
  59.             If linhas(c) = actualSoundBack then Return c
  60.         next
  61.  
  62.         Return 0
  63.     End Function
  64.  
  65.     Shadows Sub keyDown(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyDown
  66.         if not bSOn then exit sub
  67.        
  68.         If e.Key = Keys.Right Then nextL()
  69.  
  70.         If e.Key = Keys.Left Then priorL()
  71.        
  72.         if e.key = keys.back then
  73.             actualSound = actualSound.substring(0, actualSound.length - 1)
  74.            
  75.             playEffect(false, actualSound)
  76.         end if
  77.        
  78.         if e.key = keys.numpad9 then
  79.             linhas(findLinePos) = actualSound
  80.            
  81.             f.WriteAllLines(".\scripts\sounds.txt", linhas)
  82.            
  83.             msg("saving...", 1000)
  84.         end if
  85.        
  86.         if e.key = keys.numpad0 then
  87.             coef = 0
  88.            
  89.             playEffect(false, actualSound)
  90.  
  91.             msg("Replay: " & actualSound, 5000)
  92.         end if
  93.         if e.key = keys.numpad1 then
  94.             native.function.call("stop_sound", soundID)
  95.         end if
  96.     End Sub
  97.  
  98.     private sub playEffect(optional bNavigating as boolean = true, optional sTmpString as string = "")
  99.         if not bSOn then exit sub
  100.        
  101.         Dim sTmp As String
  102.        
  103.         if sTmpString = "" then
  104.             sTmp = lerLinha
  105.         else
  106.             sTmp = sTmpString
  107.         end if
  108.        
  109.         If sTmp.Length > 0 Then
  110.             if not bNavigating then
  111.                 soundPos = player.character.position
  112.                
  113.                 native.function.call("stop_sound", soundID)
  114.                 native.function.call(of int32)("release_sound_id", soundID)            
  115.                 soundID = native.function.call(of int32)("get_sound_id")               
  116.                
  117.                 native.function.call("PLAY_SOUND_FROM_position", soundID, sTmp, soundPos.x, soundPos.y, soundPos.z)
  118.             end if
  119.            
  120.             actualSound = sTmp
  121.            
  122.             if sTmpString = "" then actualSoundBack = sTmp
  123.            
  124.             msg(sTmp, 5000)
  125.         End If
  126.     end sub
  127.    
  128.     Private Function lerLinha
  129.         if not bSOn then exit function
  130.        
  131.         Dim sTmp As String
  132.  
  133.         sTmp = ""
  134.  
  135.         While sTmp = ""
  136.             l += coef
  137.            
  138.             If l < 0 Then
  139.                 l = 0
  140.                 Exit While
  141.             End If
  142.  
  143.             If l > linhas.Length - 1 Then
  144.                 l = linhas.Length - 1
  145.                 Exit While
  146.             End If
  147.            
  148.             sTmp = linhas(l)
  149.  
  150.             If (sTmp.Trim.Length > 0) andalso ((sfilter = "") orelse ((sfilter <> "") andalso sTmp.tolower.contains(sfilter.tolower))) then
  151.                 Exit While
  152.             else
  153.                 sTmp = ""
  154.             End If
  155.         End While
  156.  
  157.         Return sTmp.Trim
  158.     End Function
  159.  
  160.     Private Sub nextL()
  161.         coef = 1
  162.        
  163.         playEffect(false)
  164.     End Sub
  165.  
  166.     Private Sub priorL()
  167.         coef = -1
  168.        
  169.         playEffect(false)
  170.     End Sub
  171.    
  172.     Private Sub GraphicsEventHandler(ByVal sender As Object, ByVal e As GTA.GraphicsEventArgs) Handles mybase.PerFrameDrawing
  173.         if bSon then
  174.             e.graphics.drawtext("Sounds demo - Use left/right to navigate, press numpad0 to play and numpad1 to stop", 10, 10)
  175.             e.graphics.drawtext("Sound: " & actualSound, 10, 35)
  176.             e.graphics.drawtext("Distance from sound: " & soundPos.distanceto(player.character.position).tostring, 10, 60)
  177.             e.graphics.drawtext("Filter: " & sFilter, 10, 90)
  178.             e.graphics.drawtext("* Use backspace to remove last character from sound string and retest the sound", 10, 135)
  179.             e.graphics.drawtext("* if its correct, press numpad9 to save the file sounds.txt", 10, 165)
  180.         end if
  181.     end sub
  182. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement