Advertisement
Doug4347

SAMP_FL

Feb 11th, 2022
1,986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Creator: Doug4347/RedNeckSnailSpit
  2. ; Date: 12/02/2022 (DD/MM/YYYY)
  3.  
  4. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  5. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  6.  
  7. procName := "gta_sa.exe"
  8. SettingsFile := A_MyDocuments . "\AutoHotkey\SAMP_FL\Settings.ini"
  9. chatlog := A_MyDocuments . "\GTA San Andreas User Files\SAMP\chatlog.txt"
  10.  
  11. Menu, Tray, Tip, SAMP FL (No Script Running)
  12. Menu, Tray, Add, Add Character, AddCharGui
  13.  
  14. FileCreateDir, % A_MyDocuments . "\AutoHotkey\SAMP_FL\"
  15.  
  16. IniRead, CharacterCount, % SettingsFile, General, CharCount, 0
  17. If !CharacterCount
  18.     Goto, AddCharGui
  19.  
  20. Chars := Array()
  21. Loop, % CharacterCount
  22. {
  23.     IniRead, host, % SettingsFile, Hosts, % A_Index, 0
  24.     if !host
  25.     {
  26.         MsgBox, 16, Error, Character #%A_Index% has no Host Name. This will cause problems later on. Please delete your %SettingsFile% file (Located in %A_MyDocuments%\AutoHotkey\SAMP_Launcher\) and run the script again.
  27.         ExitApp
  28.     }
  29.     IniRead, name, % SettingsFile, CharNames, % A_Index, 0
  30.     if !name
  31.     {
  32.         MsgBox, 16, Error, Character #%A_Index% has no Name. This will cause problems later on. Please delete your %SettingsFile% file (Located in %A_WorkingDir%) and run the script again.
  33.         ExitApp
  34.     }
  35.     IniRead, script, % SettingsFile, exe, % A_Index, 0
  36.     if !script
  37.     {
  38.         MsgBox, 16, Error, Character #%A_Index% has no associated script/executable. This will cause problems later on. Please delete your %SettingsFile% file (Located in %A_WorkingDir%) and run the script again.
  39.         ExitApp
  40.     }
  41.     Chars[A_Index] := Array()
  42.     Chars[A_Index]["host"] := host
  43.     Chars[A_Index]["name"] := name
  44.     Chars[A_Index]["script"] := script
  45. }  
  46.  
  47. TrayTip, SAMP File Launcher, SAMP FL is now running. Registered characters: %CharacterCount%
  48.  
  49. Loop,
  50. {
  51.     Process, Wait, % procName
  52.     ifExist, %chatlog%
  53.     {
  54.         FileGetTime, OriginalModTime, % chatlog, M
  55.         NewModTime := OriginalModTime
  56.         While (NewModTime = OriginalModTime)
  57.             FileGetTime, NewModTime, % chatlog, M
  58.     }
  59.     i := 1
  60.     Loop,
  61.     {
  62.         FileRead, Logs, % chatlog
  63.         If (InStr(Logs, Chars[i]["host"]) and InStr(Logs, Chars[i]["name"]))
  64.         {
  65.             Run, % Chars[i]["script"]
  66.             Menu, Tray, Tip, % "SAMP FL (Character: " . Chars[i]["name"] . ")"
  67.             TrayTip, Script Launched, % "A file was launched when you logged into SAMP.`nHost Name: " . Chars[i]["host"] . "`nCahracter Name: " . Chars[i]["name"]
  68.             Break
  69.         }
  70.         i += 1
  71.         if !Chars[i]["host"]
  72.             i := 1
  73.     }
  74.     Process, WaitClose, % procName
  75.     Menu, Tray, Tip, SAMP FL (No Script Running)
  76. }
  77.  
  78. AddCharGui:
  79.     Gui, Add, Text,, Server Host Name
  80.     Gui, Add, Edit, vServHostName w500
  81.     Gui, Add, Text,, Character Name
  82.     Gui, Add, Edit, vCharName w500
  83.     Gui, Add, Text,, File to Execute
  84.     Gui, Add, Edit, vExe w500
  85.     Gui, Add, Button, gBrowse, Browse...
  86.     Gui, Add, Button, gSubmitChar w500, Add Character
  87.     Gui, Show,, Add New Character
  88. Return
  89.  
  90. Browse:
  91.     FileSelectFile, SelectedFile
  92.     GuiControl,, Exe, %SelectedFile%
  93. Return
  94.  
  95. SubmitChar:
  96.     Gui, Submit, NoHide
  97.    
  98.     if (!ServHostName or !CharName or !Exe)
  99.     {
  100.         MsgBox, 16, Empty Fields, Please make sure to fill in all fields.
  101.         Return
  102.     }
  103.    
  104.     IniRead, CharacterCount, % SettingsFile, General, CharCount, 0
  105.     IniWrite, % CharacterCount + 1, % SettingsFile, General, CharCount
  106.     IniWrite, % ServHostName, % SettingsFile, Hosts, % CharacterCount + 1
  107.     IniWrite, % CharName, % SettingsFile, CharNames, % CharacterCount + 1
  108.     IniWrite, % Exe, % SettingsFile, exe, % CharacterCount + 1
  109.     MsgBox, 64, Character Added, Successfully added %CharName% for server %ServHostName%
  110. Return
  111.  
  112. GuiClose:
  113.     Reload
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement