Advertisement
Altamurenza

Bully SE: Console Commands 1.0

Nov 9th, 2019
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 62.31 KB | None | 0 0
  1. -- CONSOLE COMMANDS 1.0 (SOURCE CODE)
  2. -- AUTHOR   : ALTAMURENZA
  3.  
  4. -- SPECIAL THANKS TO DERPY54320 FOR HER STABLE COROUTINE METHOD.
  5.  
  6.  
  7. --[[
  8.     this is what i got so far, not even close to perfect but it's quite good to go, and beside that
  9.     i don't know what to add for upcoming version which means this is the end of my project's idea.
  10.    
  11.     anyway, here are some information that you probably want to know about this script :
  12.     - F_ConsoleMenu             = user interface, 1st argument is string, 2nd argument is function, 3rd argument is boolean, 4th argument is boolean, 5th argument is string
  13.     - F_StringToObj             = convert string into object such as pedestrians and vehicles, only string is required here
  14.     - F_StringToVar             = commonly used for re-arrange the string from table, may return table or string
  15.     - F_StringToArg             = convert string into various arguments but it was changed lately in 0.9 version which 1st argument were table, and the 2nd argument was string
  16.     - F_TableToVar              = convert a specified table into readable format, only need table as its argument
  17.     - F_TableToStr              = re-arrange table into string / reversion of F_StringToVar and returns string, require a specified table as its argument
  18.     - F_Arithmetical            = processing math likely calculator, 1st argument is a specified table and the 2nd one is a specified string
  19.     - F_FuncGetResult           = self-explanatory, require a string for the function and the second argument is an optional field filled by table or string
  20.     - F_ImportTable             = create new table by importing from an old table, of course table is required
  21.     - F_CreateAnIndependentLoop = basically create new thread, but it will be a container for an external script, function is required as its argument
  22.     - F_ToggleSwitchBoolean     = reverse boolean, string or table is required as its argument
  23.     - F_ToString                = an improved function of F_TableToStr, string or table is required as its argument
  24.     - F_ToVariable              = an improved function of F_TableToVar, string or table is required as its argument
  25.     - F_Wait                    = wait function can't be used properly in ConsoleCommand, so it's a custom made wait function as alternate
  26.     - SET_VARIABLES             = set local and global, require "_G " or "_L " in the 1st argument, a specified table or string by F_StringToVar in the 2nd argument, string in the 3rd argument, 4th argument is optional filled with table of the 3rd argument
  27.     - ER_MESSAGE                = print an error result, 1st argument is string, and the 2nd one is number for how long it'll be on the screen
  28.    
  29.     feel free to tweak as much as possible, as long as it doesn't crash the game state xd.
  30. ]]
  31.  
  32.  
  33. -------------------------------------------------------------------------------
  34. -- Setup
  35. -------------------------------------------------------------------------------
  36.  
  37. _G.A,_G.X,_G.Y,_G.Z = AreaGetVisible(),PlayerGetPosXYZ() -- this A X Y Z values is always be the current player position
  38.  
  39. _G["PLAYER_POS_UPDATER"] = function()
  40.     while true do _G["A"],_G["X"],_G["Y"],_G["Z"] = AreaGetVisible(),PlayerGetPosXYZ() Wait(0) end
  41. end
  42.  
  43. _G.Ins,_G.Rem,_G.Getn = table.insert,table.remove,table.getn
  44.  
  45. gConsole = {
  46.     Mode = 1,Option = 1,Clipboard = {},IsHistoryEnabled = true,ScrollFaster = GetTimer(),Yield = false,ColumnFill = {},
  47.     History = {Commands = {},FuncArg = {},Threads = {}},Pause = {false,{}},Name = "CONSOLE",
  48.    
  49.     DEFAULT_DIR = "Scripts/", -- this is the folder where you should put your custom script
  50.    
  51.     Alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"," "},
  52. }
  53.  
  54. function main()
  55.     local THREAD = {"PRELOADER","PLAYER_POS_UPDATER"}
  56.     for i = 1,table.getn(THREAD) do
  57.         CreateThread(THREAD[i])
  58.     end
  59.    
  60.     main = nil -- we don't need this main function because it will be replaced later by another script
  61. end
  62.  
  63. -------------------------------------------------------------------------------
  64. -- Preloader
  65. -------------------------------------------------------------------------------
  66.  
  67. local FAKE_TextPrintString,CC_Print = function(Arg1,Arg2,Arg3)
  68.     print(Arg1)
  69. end,TextPrintString
  70.  
  71. local FAKE_Button,IBP,IBBP,IBBR = function(b,c)
  72.     print(b)
  73. end,IsButtonPressed,IsButtonBeingPressed,IsButtonBeingReleased
  74.  
  75. function PRELOADER()
  76.     local Wait,EndScript = function(ms)
  77.         if gConsole.Yield == true then coroutine.yield(ms)
  78.         else
  79.             _G["Wait"](ms)
  80.         end
  81.     end,false
  82.    
  83.     while true do
  84.         local Console,Status,Result = coroutine.create(ConsoleCommand)
  85.        
  86.         while coroutine.status(Console) == "suspended" do
  87.             gConsole.Yield = true
  88.             if gConsole.Yield == true then
  89.                 Status,Result = coroutine.resume(Console)
  90.             end
  91.             gConsole.Yield = false
  92.            
  93.             _G["Wait"](Result)
  94.         end
  95.        
  96.         local Timer,Time = GetTimer(),15
  97.         while true do
  98.             _G.IsButtonPressed,_G.IsButtonBeingPressed,_G.IsButtonBeingReleased = FAKE_Button,FAKE_Button,FAKE_Button
  99.             _G.TextPrintString = FAKE_TextPrintString
  100.            
  101.             CC_Print("( "..Time.."s )\n\nConsole Command has stopped working\nHold ~ddown~ to restart the script",0,2)
  102.             if IBBP(3,0) then
  103.                 local FullyLoaded,Load = false,0
  104.                
  105.                 while FullyLoaded == false do
  106.                     if Load > 100 then
  107.                         Load = 100
  108.                     end
  109.                     Load = Load + 1
  110.                    
  111.                     Wait(math.random(0,70))
  112.                    
  113.                     CC_Print("Console Commands "..Load.."%",0.5,2)
  114.                     if Load == 100 then FullyLoaded = true end
  115.                 end
  116.                
  117.                 _G.IsButtonPressed,_G.IsButtonBeingPressed,_G.IsButtonBeingReleased = IBP,IBBP,IBBR
  118.                 _G.TextPrintString = CC_Print
  119.                
  120.                 break
  121.             end
  122.            
  123.             if Timer + 1000 < GetTimer() then
  124.                 Timer,Time = GetTimer(),Time - 1
  125.                 if Time == 0 then EndScript = true break end
  126.             end
  127.            
  128.             _G["Wait"](0)
  129.         end
  130.        
  131.         PlayerSetControl(1) collectgarbage()
  132.        
  133.         if EndScript == true then
  134.             _G.IsButtonPressed,_G.IsButtonBeingPressed,_G.IsButtonBeingReleased = IBP,IBBP,IBBR
  135.             _G.TextPrintString = CC_Print
  136.            
  137.             break
  138.         end
  139.         _G["Wait"](0)
  140.     end
  141. end
  142.  
  143. -------------------------------------------------------------------------------
  144. -- Main part
  145. -------------------------------------------------------------------------------
  146.  
  147. function ConsoleCommand()
  148.     while not SystemIsReady() or AreaIsLoading() do
  149.         Wait(0)
  150.     end
  151.    
  152.     -- Take the 'CreateThread' over, it's the only way to break in
  153.     local DEFAULT_CreateThread = CreateThread
  154.     _G["CreateThread"] = function(Name)
  155.         local Thread = DEFAULT_CreateThread(Name)
  156.        
  157.         table.insert(gConsole.History.Threads,{Name,Thread})
  158.         if table.getn(gConsole.History.Threads) > 250 then
  159.             table.remove(gConsole.History.Threads,10)
  160.         end
  161.        
  162.         return Thread
  163.     end
  164.    
  165.     -- Main Loop
  166.     while true do
  167.         if IBBR(4,0) then
  168.             function ExecuteCommand(Typing,Text)
  169.                 if table.getn(Typing) > 0 then
  170.                     local IsCommandValid = false
  171.                    
  172.                     local COMMAND_Type = ""
  173.                     for COMMAND_Word = 1,3 do
  174.                         COMMAND_Type = COMMAND_Type..""..Typing[COMMAND_Word]
  175.                     end
  176.                    
  177.                     -- _G & _L = change variable
  178.                     if COMMAND_Type == "_G " or COMMAND_Type == "_L " then
  179.                         local COMMAND_Text = F_StringToVar(Typing,4,table.getn(Typing))
  180.                        
  181.                         function F_SetVariable(TableArg,Arg)
  182.                             SET_VARIABLES(COMMAND_Type,COMMAND_Text,Arg,TableArg)
  183.                            
  184.                             table.insert(gConsole.History.Commands,{F_ImportTable(Typing),COMMAND_Type.."."..F_ToString(COMMAND_Text)})
  185.                             IsCommandValid = true
  186.                         end
  187.                        
  188.                         F_ConsoleMenu("#VALUE",F_SetVariable,false,true,COMMAND_Type == "_G " and "'"..F_ToString(COMMAND_Text).."' is recognized as "..type(F_ToVariable(COMMAND_Text)) or nil)
  189.                     end
  190.                    
  191.                     -- _R = run function, the most intricate part of this script but yeah here we go
  192.                     if COMMAND_Type == "_R " then
  193.                         local CALL_FUNC,COMMAND_Text = function(Func,TableArg,Arg)
  194.                             local IsTextPrint,Separator,Key = false,{},","
  195.                             local SeparatedArg,TEMP_Arguments,Arguments = {},{},{}
  196.                            
  197.                             if type(Func) == "string" and Func == "TextPrintString" then
  198.                                 IsTextPrint = true
  199.                             end
  200.                            
  201.                             F_Func,FuncInString = F_ToVariable(Func),type(Func) == "table" and F_ToString(Func) or Func
  202.                            
  203.                             if table.getn(TableArg) > 0 then
  204.                                 if string.find(Arg,Key,1) then
  205.                                     for Index = 1,table.getn(TableArg) do
  206.                                         if TableArg[Index] == Key then
  207.                                             table.insert(Separator,Index)
  208.                                         else
  209.                                             if type(SeparatedArg[table.getn(Separator) + 1]) ~= "table" then
  210.                                                 SeparatedArg[table.getn(Separator) + 1] = {}
  211.                                             end
  212.                                            
  213.                                             table.insert(SeparatedArg[table.getn(Separator) + 1],TableArg[Index])
  214.                                         end
  215.                                     end
  216.                                    
  217.                                     local TEMP_Arg,Current = "",0
  218.                                     while true do
  219.                                         Current = Current + 1
  220.                                        
  221.                                         if Current > table.getn(TableArg) then
  222.                                             break
  223.                                         else
  224.                                             if Current > 1 then
  225.                                                 local SkipThisOne = false
  226.                                                 for i = 1,table.getn(Separator) do
  227.                                                     if Current == Separator[i] then
  228.                                                         table.insert(TEMP_Arguments,{F_ImportTable(SeparatedArg[i]),TEMP_Arg})
  229.                                                        
  230.                                                         TEMP_Arg,SkipThisOne = "",true
  231.                                                     end
  232.                                                 end
  233.                                                
  234.                                                 if not SkipThisOne then
  235.                                                     TEMP_Arg = TEMP_Arg..""..TableArg[Current]
  236.                                                    
  237.                                                     if Current == table.getn(TableArg) then
  238.                                                         table.insert(TEMP_Arguments,{F_ImportTable(SeparatedArg[table.getn(SeparatedArg)]),TEMP_Arg})
  239.                                                     end
  240.                                                 end
  241.                                             else
  242.                                                 TEMP_Arg = TableArg[Current]
  243.                                             end
  244.                                         end
  245.                                     end
  246.                                    
  247.                                     local New = {Symbol = {".","[","]"},Separator = {},Table = {}}
  248.                                     for TableNumber = 1,table.getn(TEMP_Arguments) do
  249.                                         if (string.find(TEMP_Arguments[TableNumber][2],New.Symbol[2],1) and string.find(TEMP_Arguments[TableNumber][2],New.Symbol[3],1)) or string.find(TEMP_Arguments[TableNumber][2],New.Symbol[1],1) then
  250.                                            
  251.                                             for Number = 1,table.getn(TEMP_Arguments[TableNumber][1]) do
  252.                                                 if TEMP_Arguments[TableNumber][1] == New.Symbol[2] or TEMP_Arguments[TableNumber][1] == New.Symbol[3] or TEMP_Arguments[TableNumber][1] == New.Symbol[1] then
  253.                                                     table.insert(New.Separator,Number)
  254.                                                 end
  255.                                             end
  256.                                         end
  257.                                     end
  258.                                     if table.getn(New.Separator) > 0 then
  259.                                         for TableNumber = 1,table.getn(TEMP_Arguments) do
  260.                                            
  261.                                             local Var,Current = "",0
  262.                                             while true do
  263.                                                 Current = Current + 1
  264.                                                
  265.                                                 if Current > table.getn(TEMP_Arguments[TableNumber][1]) then
  266.                                                     break
  267.                                                 else
  268.                                                     if Current > 1 then
  269.                                                         local SKIP = false
  270.                                                         for i = 1,table.getn(New.Separator) do
  271.                                                             if Current == New.Separator[i] then
  272.                                                                 if type(New.Table[TableNumber]) ~= "table" then
  273.                                                                     New.Table[TableNumber] = {}
  274.                                                                 end
  275.                                                                
  276.                                                                 table.insert(New.Table[TableNumber],Var)
  277.                                                                 Var,SKIP = "",true
  278.                                                             end
  279.                                                         end
  280.                                                        
  281.                                                         if not SKIP then
  282.                                                             Var = Var..""..TEMP_Arguments[TableNumber][1][Current]
  283.                                                            
  284.                                                             if Current == table.getn(TEMP_Arguments[TableNumber][1]) then
  285.                                                                 if type(New.Table[TableNumber]) ~= "table" then
  286.                                                                     New.Table[TableNumber] = {}
  287.                                                                 end
  288.                                                                
  289.                                                                 table.insert(New.Table[TableNumber],Var)
  290.                                                             end
  291.                                                         end
  292.                                                     else
  293.                                                         Var = Var..""..TEMP_Arguments[TableNumber][1][Current]
  294.                                                     end
  295.                                                 end
  296.                                             end
  297.                                         end
  298.                                     end
  299.                                    
  300.                                     for Number = 1,table.getn(TEMP_Arguments) do
  301.                                         if type(New.Table[Number]) == "table" then
  302.                                             table.insert(Arguments,F_ToVariable(New.Table[Number]))
  303.                                         else
  304.                                             table.insert(Arguments,F_StringToArg(TEMP_Arguments[Number][1],TEMP_Arguments[Number][2]))
  305.                                         end
  306.                                     end
  307.                                    
  308.                                     if IsTextPrint == false then
  309.                                         local IsReturningValue = F_FuncGetResult(FuncInString,Arguments)
  310.                                        
  311.                                         if not IsReturningValue then
  312.                                             local Reference = {
  313.                                                 PedCreateXYZ = 1,VehicleCreateXYZ = 2,PickupCreateXYZ = 3,BlipAddXYZ = 4,AddBlipForChar = 5,EffectCreate = 6,
  314.                                             }
  315.                                             if Reference[FuncInString] then
  316.                                                 for Count = 1,5000 do
  317.                                                     if type(_G["OBJ_"..Count]) == "nil" then
  318.                                                         _G["OBJ_"..Count] = F_Func(unpack(Arguments)) break
  319.                                                     end
  320.                                                 end
  321.                                             else
  322.                                                 if FuncInString == "CreatePersistentEntity" then
  323.                                                     for Count = 1,5000 do
  324.                                                         if type(_G["OBJ_"..Count]) == "nil" then
  325.                                                             _G["OBJ_"..Count.."_I"],_G["OBJ_"..Count.."_P"] = F_Func(unpack(Arguments)) break
  326.                                                         end
  327.                                                     end
  328.                                                 else
  329.                                                     F_Func(unpack(Arguments))
  330.                                                 end
  331.                                             end
  332.                                         end
  333.                                     end
  334.                                 else
  335.                                     if IsTextPrint == false then
  336.                                         local IsReturningValue = F_FuncGetResult(FuncInString,
  337.                                             ((string.find(Arg,"[",1) and string.find(Arg,"]",1)) or string.find(Arg,".",1)) and F_TableToVar(F_StringToVar(TableArg,1,table.getn(TableArg))) or F_StringToArg(TableArg,Arg)
  338.                                         )
  339.                                        
  340.                                         if not IsReturningValue then
  341.                                             F_Func(
  342.                                                 ((string.find(Arg,"[",1) and string.find(Arg,"]",1)) or string.find(Arg,".",1)) and F_TableToVar(F_StringToVar(TableArg,1,table.getn(TableArg))) or F_StringToArg(TableArg,Arg)
  343.                                             )
  344.                                         end
  345.                                     end
  346.                                 end
  347.                             else
  348.                                 if IsTextPrint == false then
  349.                                     local IsReturningValue = F_FuncGetResult(FuncInString)
  350.                                     if not IsReturningValue then
  351.                                         F_Func()
  352.                                     end
  353.                                 end
  354.                             end
  355.                            
  356.                             if IsTextPrint == true then
  357.                                 if table.getn(Arguments) >= 3 then
  358.                                     CC_Print(unpack(Arguments))
  359.                                     F_Wait(type(Arguments[2]) == "number" and Arguments[2] * 1000 or 0)
  360.                                 else
  361.                                     ER_MESSAGE("expected 3 more arguments",2)
  362.                                 end
  363.                             end
  364.                            
  365.                             local FoundIt = false
  366.                             if table.getn(gConsole.History.FuncArg) > 0 then
  367.                                 for i = 1,table.getn(gConsole.History.FuncArg) do
  368.                                     if FuncInString == gConsole.History.FuncArg[i].F then
  369.                                         gConsole.History.FuncArg[i].A,FoundIt = TableArg,true break
  370.                                     end
  371.                                 end
  372.                             end
  373.                            
  374.                             if FoundIt == false then
  375.                                 table.insert(gConsole.History.FuncArg,{F = FuncInString,A = TableArg})
  376.                             end
  377.                            
  378.                             table.insert(gConsole.History.Commands,{F_ImportTable(Typing),COMMAND_Type.."."..F_ToString(Func)})
  379.                             IsCommandValid = true
  380.                         end,F_StringToVar(Typing,4,table.getn(Typing))
  381.                            
  382.                         if type(F_ToVariable(COMMAND_Text)) == "function" then
  383.                             function F_CallFunc(TableArg,Arg)
  384.                                 CALL_FUNC(COMMAND_Text,TableArg,Arg)
  385.                             end
  386.                            
  387.                             if table.getn(gConsole.History.FuncArg) > 0 then
  388.                                 for i = 1,table.getn(gConsole.History.FuncArg) do
  389.                                     if COMMAND_Text == gConsole.History.FuncArg[i].F then
  390.                                         if table.getn(gConsole.History.FuncArg[i].A) > 0 then
  391.                                             gConsole.ColumnFill = F_ImportTable(gConsole.History.FuncArg[i].A)
  392.                                             break
  393.                                         end
  394.                                     end
  395.                                 end
  396.                             end
  397.                            
  398.                             F_ConsoleMenu("#ARGUMENTS",F_CallFunc,false,true)
  399.                         end
  400.                     end
  401.                    
  402.                     -- _S = load/run script
  403.                     if COMMAND_Type == "_S " then
  404.                         local ScriptList,COMMAND_Text,HasOption = {
  405.                             {Option = " -ls",Func = LaunchScript,History = "Launch Script"},{Option = " -is",Func = ImportScript,History = "Import Script"},
  406.                             {Option = " -rs",Func = function(filename)
  407.                                 local File,Code = loadfile(gConsole.DEFAULT_DIR..""..filename)
  408.                                 if File then
  409.                                     File()
  410.                                    
  411.                                     if type(main) ~= "function" then
  412.                                         function RUN_SCRIPT(Table,Func)
  413.                                             local F_Func = F_ToVariable(Table)
  414.                                            
  415.                                             if type(F_Func) == "function" then F_CreateAnIndependentLoop(F_Func)
  416.                                             else
  417.                                                 ER_MESSAGE("'"..Func.."' FUNCTION DOESN'T EXIST",2)
  418.                                             end
  419.                                         end
  420.                                        
  421.                                         F_ConsoleMenu("#MAIN_FUNC",RUN_SCRIPT,false,true,"type which function do you want to run from "..filename)
  422.                                     else
  423.                                         local MainFunc = main
  424.                                        
  425.                                         F_CreateAnIndependentLoop(MainFunc)
  426.                                         main = nil
  427.                                     end
  428.                                 else
  429.                                     ER_MESSAGE(tostring(Code),2)
  430.                                 end
  431.                             end,History = "Run Script"},{Option = " -lo",Func = function(filename)
  432.                                 local File,Code = loadfile(gConsole.DEFAULT_DIR..""..filename)
  433.                                
  434.                                 if not File then ER_MESSAGE(tostring(Code),2)
  435.                                 else
  436.                                     File()
  437.                                 end
  438.                             end,History = "Load Script"},{Option = " -lm",Func = function(filename)
  439.                                 _G.shared.CC_CustomMission = gConsole.DEFAULT_DIR..""..filename
  440.                                 ForceStartMissionIndex(215)
  441.                             end,History = "Play Custom Mission"}
  442.                         },F_StringToVar(Typing,4,table.getn(Typing)),false
  443.                        
  444.                         for i,SCRIPT in ipairs(ScriptList) do
  445.                             if string.find(F_ToString(COMMAND_Text),SCRIPT.Option,-4) then
  446.                                 COMMAND_Text = ""
  447.                                 for i = 4,table.getn(Typing) - 4 do
  448.                                     COMMAND_Text = COMMAND_Text..""..Typing[i]
  449.                                 end
  450.                                
  451.                                 SCRIPT.Func(COMMAND_Text)
  452.                                
  453.                                 table.insert(gConsole.History.Commands,{F_ImportTable(Typing),SCRIPT.History})
  454.                                 IsCommandValid,HasOption = true,true
  455.                             end
  456.                         end
  457.                        
  458.                         if not HasOption then
  459.                             ER_MESSAGE("expected options: -ls, -is, -rs, -lo and -lm",2)
  460.                         end
  461.                     end
  462.                    
  463.                     -- rb = reverse boolean (v = not v)
  464.                     if COMMAND_Type == "rb " then
  465.                         F_ToggleSwitchBoolean(F_StringToVar(Typing,4,table.getn(Typing)))
  466.                        
  467.                         table.insert(gConsole.History.Commands,{F_ImportTable(Typing),"NOT '"..F_ToString(F_StringToVar(Typing,4,table.getn(Typing))).."'"})
  468.                         IsCommandValid = true
  469.                     end
  470.                    
  471.                     -- tp = check type
  472.                     if COMMAND_Type == "tp " then
  473.                         local VarType,F_ReadValue = F_ToVariable(F_StringToVar(Typing,4,table.getn(Typing))),function(Item)
  474.                             local NewItem = F_ToVariable(Item)
  475.                            
  476.                             if type(NewItem) == "string" or type(NewItem) == "number" or type(NewItem) == "boolean" then
  477.                                 if type(NewItem) == "boolean" then
  478.                                     NewItem = tostring(NewItem)
  479.                                 end
  480.                                
  481.                                 return NewItem..""
  482.                             elseif type(NewItem) == "table" then return table.getn(NewItem).." (max)" end
  483.                             return "unreadable"
  484.                         end
  485.                        
  486.                         local Content = F_StringToVar(Typing,4,table.getn(Typing))
  487.                         while not IBBP(8,0) do
  488.                             CC_Print("#INFO\n\n\n"..F_ToString(Content).."\nt: "..type(VarType)..", v: "..F_ReadValue(Content),0,1) Wait(0)
  489.                         end
  490.                        
  491.                         table.insert(gConsole.History.Commands,{F_ImportTable(Typing),"check '"..F_ToString(Content).."'"})
  492.                         IsCommandValid = true
  493.                     end
  494.                    
  495.                     -- thread = kill thread
  496.                     if Text == "thread" then
  497.                         if table.getn(gConsole.History.Threads) > 0 then
  498.                             local ThreadSelect = 1
  499.                             while not IBBP(8,0) do
  500.                                
  501.                                 ThreadSelect = F_Navigate(gConsole.History.Threads,ThreadSelect,0,1,0)
  502.                                 if F_Controller(3,0) then
  503.                                     while not IBBR(3,0) do
  504.                                         Wait(0)
  505.                                     end
  506.                                    
  507.                                     local NoThreadsLeft = false
  508.                                     function F_KillOrLeaveItAlone(TableArg,Arg)
  509.                                         if Arg == "y" or Arg == "yes" or Arg == "Y" or Arg == "YES" then
  510.                                             TerminateThread(gConsole.History.Threads[ThreadSelect][2])
  511.                                            
  512.                                             table.remove(gConsole.History.Threads,ThreadSelect)
  513.                                             if table.getn(gConsole.History.Threads) >= 1 then ThreadSelect = 1
  514.                                             else
  515.                                                 NoThreadsLeft = true
  516.                                             end
  517.                                         end
  518.                                     end
  519.                                    
  520.                                     F_ConsoleMenu("#CHOICE",F_KillOrLeaveItAlone,false,true,"Y = KILL | N = LEAVE")
  521.                                     if NoThreadsLeft then
  522.                                         break
  523.                                     end
  524.                                 end
  525.                                
  526.                                 CC_Print("THREAD KILL\n\n"..ThreadSelect..") "..gConsole.History.Threads[ThreadSelect][1],0,1)
  527.                                 Wait(0)
  528.                             end
  529.                            
  530.                             if IBBP(8,0) then
  531.                                 while not IBBR(8,0) do
  532.                                     Wait(0)
  533.                                 end
  534.                             end
  535.                         else
  536.                             CC_Print("NO THREADS FOUND",2,1)
  537.                             F_Wait(2000)
  538.                         end
  539.                        
  540.                         table.insert(gConsole.History.Commands,{F_ImportTable(Typing),"kill thread"})
  541.                         IsCommandValid = true
  542.                     end
  543.                    
  544.                     -- save = save game
  545.                     if Text == "save" then
  546.                         if not MissionActive() then
  547.                             PlayerSetControl(1)
  548.                             PlayerLockButtonInputsExcept(true,9,8)
  549.                            
  550.                             repeat
  551.                                 CC_Print("CONSOLE COMMANDS\n- SaveGame -\n\n\nSAVE ~GRAPPLE~ / CANCEL ~JUMP~",0.5,1)
  552.                                 Wait(0)
  553.                             until IBBP(9,0) or IBBP(8,0)
  554.                            
  555.                             if IBBP(9,0) then
  556.                                 local x,y,z = PlayerGetPosXYZ()
  557.                                 PlayerSetScriptSavedData(69,4134)
  558.                                
  559.                                 PedFaceXYZ(gPlayer,x,y + 1,z)
  560.                                 local Index,Pool = CreatePersistentEntity("AnimSave",x,y + 0.5,z + 1,PedGetHeading(gPlayer),AreaGetVisible())
  561.                                
  562.                                 PlayerLockButtonInputsExcept(false)
  563.                                 CameraReturnToPlayer()
  564.                                 repeat
  565.                                     Wait(0)
  566.                                 until IBBR(7,0) or IBBR(8,0)
  567.                                
  568.                                 DeletePersistentEntity(Index,Pool)
  569.                             else
  570.                                 while not IBBR(8,0) do
  571.                                     Wait(0)
  572.                                 end
  573.                             end
  574.                            
  575.                             PlayerLockButtonInputsExcept(false)
  576.                             PlayerSetControl(0)
  577.                         else
  578.                             CC_Print("UNABLE TO SAVE DURING A MISSION",2,1)
  579.                             F_Wait(2000)
  580.                         end
  581.                        
  582.                         table.insert(gConsole.History.Commands,{F_ImportTable(Typing),"game: save progress"})
  583.                         IsCommandValid = true
  584.                     end
  585.                    
  586.                     -- save [slot] = save game editor / checker
  587.                     local SGIndex = nil
  588.                     for _SAVEINDEX = 0,100 do
  589.                         if Text == "save ".._SAVEINDEX or Text == "save ".._SAVEINDEX.." /c" then
  590.                             SGIndex = _SAVEINDEX
  591.                         end
  592.                     end
  593.                     if type(SGIndex) == "number" then
  594.                         if Text ~= "save "..SGIndex.." /c" then
  595.                             NEW_ALPHABET = function()
  596.                                 while true do
  597.                                     gConsole.Alphabet = {"1","2","3","4","5","6","7","8","9","0"} Wait(0)
  598.                                 end
  599.                             end
  600.                            
  601.                             local T = CreateThread("NEW_ALPHABET")
  602.                             function SAVEDATA(TableVAL,Value)
  603.                                 PlayerSetScriptSavedData(SGIndex,Value)
  604.                             end
  605.                            
  606.                             F_ConsoleMenu("#VALUE",SAVEDATA,false,true,"wild edits may damage your savegame")
  607.                             TerminateThread(T)
  608.                         else
  609.                             local Value = PlayerGetScriptSavedData(SGIndex)
  610.                             while not IBBP(8,0) do
  611.                                 CC_Print("#INFO\n\n\nSAVEDATA("..SGIndex..")\nt: "..type(Value)..", v: "..Value,0,1) Wait(0)
  612.                             end
  613.                         end
  614.                        
  615.                         table.insert(gConsole.History.Commands,{F_ImportTable(Typing),"game: modify saves"})
  616.                         IsCommandValid = true
  617.                     end
  618.                    
  619.                     -- /pass = quick pass the mission
  620.                     if Text == "/pass" then
  621.                         if MissionActive() then
  622.                             SoundPlayMissionEndMusic(true,10)
  623.                             MissionSucceed(false,true,true)
  624.                         end
  625.                        
  626.                         table.insert(gConsole.History.Commands,{F_ImportTable(Typing),"mission pass"})
  627.                         IsCommandValid = true
  628.                     end
  629.                    
  630.                     -- /fail = quick fail the mission
  631.                     if Text == "/fail" or Text == "/fail -f" then
  632.                         if MissionActive() then
  633.                             if Text == "/fail -f" then
  634.                                 MissionSetAutoRestart(false)
  635.                             end
  636.                            
  637.                             SoundPlayMissionEndMusic(false,10)
  638.                             MissionFail(false,true,true)
  639.                         end
  640.                        
  641.                         table.insert(gConsole.History.Commands,{F_ImportTable(Typing),"mission fail"})
  642.                         IsCommandValid = true
  643.                     end
  644.                    
  645.                     -- command is not valid, still being ported to command's history
  646.                     if not IsCommandValid then
  647.                         if table.getn(Typing) <= 6 then
  648.                             table.insert(gConsole.History.Commands,{F_ImportTable(Typing),"'"..Text.."' is unrecognized"})
  649.                         else
  650.                             local TEMP_Text = ""
  651.                            
  652.                             for TEXT_Num = 1,4 do
  653.                                 TEMP_Text = TEMP_Text..""..Typing[TEXT_Num]
  654.                             end
  655.                             TEMP_Text = TEMP_Text..".."
  656.                            
  657.                             table.insert(gConsole.History.Commands,{F_ImportTable(Typing),"'"..TEMP_Text.."' is unrecognized"})
  658.                         end
  659.                     end
  660.                 end
  661.             end
  662.            
  663.             F_ConsoleMenu(gConsole.Name,ExecuteCommand,true,false)
  664.         end
  665.         Wait(0)
  666.     end
  667. end
  668.  
  669. function F_ConsoleMenu(Title,Executor,IsHistoryAllowed,Once,Note)
  670.     PlayerSetControl(0)
  671.     PlayerStopAllActionControllers()
  672.    
  673.     local InsertionWait,InsertionAvailable = GetTimer(),false
  674.     local InsertionPoint,Typing = function()
  675.         if InsertionWait + 800 < GetTimer() then
  676.             InsertionAvailable = not InsertionAvailable
  677.             InsertionWait = GetTimer()
  678.         end
  679.        
  680.         if InsertionAvailable then return "|"
  681.         else
  682.             return ""
  683.         end
  684.     end,{}
  685.    
  686.     local PrintOut,ReBuild,ExtraMessage = "",false,nil
  687.     local HistoryID
  688.    
  689.     if table.getn(gConsole.ColumnFill) > 0 then
  690.         Typing,ReBuild = F_ImportTable(gConsole.ColumnFill),true
  691.     end
  692.    
  693.     repeat
  694.         gConsole.Option = F_Navigate(gConsole.Alphabet,gConsole.Option,0,1,0)
  695.        
  696.         if IBBP(3,0) then
  697.             gConsole.Mode = gConsole.Mode + 1
  698.             if gConsole.Mode > 3 then gConsole.Mode = 1 end
  699.            
  700.             if gConsole.Mode == 1 then
  701.                 gConsole.Alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"," "}
  702.             elseif gConsole.Mode == 2 then
  703.                 gConsole.Alphabet = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," "}
  704.             elseif gConsole.Mode == 3 then
  705.                 gConsole.Alphabet = {"1","2","3","4","5","6","7","8","9","0",",",".","/",":",";","'","[","]","{","}","-","_","+","!","@","#","$","%","^","&","*","(",")","`","~"}
  706.             end
  707.         end
  708.        
  709.         if gConsole.Option > table.getn(gConsole.Alphabet) then
  710.             gConsole.Option = 1
  711.         end
  712.        
  713.         if IBBP(7,0) then
  714.             if table.getn(Typing) <= 25 then
  715.                 table.insert(Typing,gConsole.Alphabet[gConsole.Option])
  716.                 ReBuild = true
  717.             else
  718.                 SoundPlay2D("WrongBtn")
  719.             end
  720.         elseif IBBP(2,0) then
  721.             if table.getn(Typing) > 0 then
  722.                 table.remove(Typing,table.getn(Typing))
  723.                
  724.                 if table.getn(Typing) > 0 then ReBuild = true
  725.                 else
  726.                     PrintOut = ""
  727.                 end
  728.             end
  729.         elseif IBBP(6,0) then
  730.             if table.getn(Typing) > 0 then
  731.                 for i = 1,table.getn(Typing) do
  732.                     table.remove(Typing,i)
  733.                 end
  734.                
  735.                 PrintOut = ""
  736.             end
  737.         end
  738.        
  739.         if Title == gConsole.Name then
  740.             if IBBP(15,0) then
  741.                 gConsole.Pause[1] = not gConsole.Pause[1]
  742.             end
  743.            
  744.             if IBBP(12,0) then
  745.                 if table.getn(gConsole.History.Commands) > 0 then
  746.                     if type(HistoryID) == "number" then HistoryID = F_Selection(gConsole.History.Commands,HistoryID,0)
  747.                     else
  748.                         HistoryID = table.getn(gConsole.History.Commands)
  749.                     end
  750.                    
  751.                     Typing = F_ImportTable(gConsole.History.Commands[HistoryID][1])
  752.                     ReBuild = true
  753.                 end
  754.             end
  755.            
  756.             if IBBP(10,0) then
  757.                 if table.getn(gConsole.History.Commands) > 0 then
  758.                     if type(HistoryID) == "number" then HistoryID = F_Selection(gConsole.History.Commands,HistoryID,1)
  759.                     else
  760.                         HistoryID = 1
  761.                     end
  762.                    
  763.                     Typing = F_ImportTable(gConsole.History.Commands[HistoryID][1])
  764.                     ReBuild = true
  765.                 end
  766.             end
  767.         else
  768.             if IBBR(8,0) then
  769.                 break
  770.             end
  771.         end
  772.        
  773.         if gConsole.Pause[1] then
  774.             for i,Ped in {PedFindInAreaXYZ(0,0,0,999999)} do
  775.                 if PedIsValid(Ped) and Ped ~= gPlayer then
  776.                     if table.getn(gConsole.Pause[2]) > 0 then
  777.                         local Found = false
  778.                         for k,v in ipairs(gConsole.Pause[2]) do
  779.                             if Ped == v[1] then Found = true break end
  780.                         end
  781.                        
  782.                         if not Found then table.insert(gConsole.Pause[2],{Ped,GameGetPedStat(Ped,20)}) end
  783.                     else
  784.                         table.insert(gConsole.Pause[2],{Ped,GameGetPedStat(Ped,20)})
  785.                     end
  786.                 end
  787.             end
  788.            
  789.             for k,v in ipairs(gConsole.Pause[2]) do if PedIsValid(v[1]) then GameSetPedStat(v[1],20,0) end end
  790.         else
  791.             for k,v in ipairs(gConsole.Pause[2]) do
  792.                 if PedIsValid(v[1]) then
  793.                     GameSetPedStat(v[1],20,v[2])
  794.                 end
  795.             end
  796.            
  797.             for i = 1,table.getn(gConsole.Pause[2]) do table.remove(gConsole.Pause[2],i) end
  798.         end
  799.        
  800.         if IBP(9,0) then
  801.             if IBBP(0,0) and table.getn(Typing) > 0 then
  802.                 if table.getn(gConsole.Clipboard) > 0 then gConsole.Clipboard = {} end
  803.                
  804.                 local Text = ""
  805.                 for i = 1,table.getn(Typing) do
  806.                     table.insert(gConsole.Clipboard,Typing[i])
  807.                     Text = Text..""..Typing[i]
  808.                 end
  809.                
  810.                 while not IBBR(0,0) do Wait(0) end
  811.                
  812.                 if type(Note) ~= "string" then CC_Print("'"..Text.."' has been copied to clipboard",2,2)
  813.                 else
  814.                     ExtraMessage = {"'"..Text.."' has been copied to clipboard",GetTimer(),2}
  815.                 end
  816.             end
  817.            
  818.             if IBBP(1,0) and table.getn(gConsole.Clipboard) > 0 then
  819.                 for i = 1,table.getn(gConsole.Clipboard) do
  820.                     if table.getn(Typing) >= 25 then
  821.                         break
  822.                     end
  823.                    
  824.                     table.insert(Typing,gConsole.Clipboard[i])
  825.                 end
  826.                 ReBuild = true
  827.                
  828.                 while not IBBR(1,0) do Wait(0) end
  829.             end
  830.         end
  831.        
  832.         if ReBuild then
  833.             local Current = 0
  834.             while true do
  835.                 Current = Current + 1
  836.                
  837.                 if Current > table.getn(Typing) then
  838.                     break
  839.                 else
  840.                     if Current > 1 then
  841.                         PrintOut = PrintOut..""..Typing[Current]
  842.                     else
  843.                         PrintOut = Typing[Current]
  844.                     end
  845.                 end
  846.             end
  847.            
  848.             ReBuild = false
  849.         end
  850.        
  851.         Sequence,ConsoleHistory = function(Table,Option)
  852.             if Option == 1 then
  853.                 return Table[table.getn(Table) - 1]..""..Table[table.getn(Table)]..""..Table[Option]..""..Table[Option + 1]..""..Table[Option + 2]
  854.             elseif Option == 2 then
  855.                 return Table[table.getn(Table)]..""..Table[Option - 1]..""..Table[Option]..""..Table[Option + 1]..""..Table[Option + 2]
  856.             elseif Option == table.getn(Table) then
  857.                 return Table[table.getn(Table) - 2]..""..Table[table.getn(Table) - 1]..""..Table[Option]..""..Table[1]..""..Table[2]
  858.             elseif Option == table.getn(Table) - 1 then
  859.                 return Table[table.getn(Table) - 3]..""..Table[table.getn(Table) - 2]..""..Table[Option]..""..Table[table.getn(Table)]..""..Table[1]
  860.             else
  861.                 return Table[Option - 2]..""..Table[Option - 1]..""..Table[Option]..""..Table[Option + 1]..""..Table[Option + 2]
  862.             end
  863.         end,function()
  864.             if gConsole.IsHistoryEnabled then
  865.                 local HistoryNum = table.getn(gConsole.History.Commands)
  866.                 if HistoryNum > 0 then
  867.                     if table.getn(gConsole.History.Commands) > 3 then
  868.                         return gConsole.History.Commands[HistoryNum - 2][2].."\n"..gConsole.History.Commands[HistoryNum - 1][2].."\n"..gConsole.History.Commands[HistoryNum][2]
  869.                     end
  870.                    
  871.                     if HistoryNum == 1 then
  872.                         return gConsole.History.Commands[1][2]
  873.                     elseif HistoryNum == 2 then
  874.                         return gConsole.History.Commands[1][2].."\n"..gConsole.History.Commands[2][2]
  875.                     elseif HistoryNum == 3 then
  876.                         return gConsole.History.Commands[1][2].."\n"..gConsole.History.Commands[2][2].."\n"..gConsole.History.Commands[3][2]
  877.                     end
  878.                 end
  879.             end
  880.            
  881.             return ""
  882.         end
  883.        
  884.         CC_Print(Title.."\n\n> "..PrintOut..""..InsertionPoint().."\n\n| "..gConsole.Alphabet[gConsole.Option].." |\n"..Sequence(gConsole.Alphabet,gConsole.Option),0,1)
  885.         if type(Note) == "string" then
  886.             if type(ExtraMessage) == "table" then
  887.                 CC_Print(ExtraMessage[1].."\n^\n"..Note,0,2)
  888.                
  889.                 if ExtraMessage[2] + (ExtraMessage[3] * 1000) <= GetTimer() then
  890.                     ExtraMessage = nil
  891.                 end
  892.             else
  893.                 CC_Print(Note,0,2)
  894.             end
  895.         end
  896.        
  897.         if IBBP(14,0) then
  898.             while not IBBR(14,0) do Wait(0) end
  899.             Executor(Typing,PrintOut)
  900.            
  901.             if Once then
  902.                 break
  903.             end
  904.         end
  905.        
  906.         _G["IsButtonPressed"],_G["IsButtonBeingPressed"],_G["IsButtonBeingReleased"] = FAKE_Button,FAKE_Button,FAKE_Button
  907.         _G["TextPrintString"] = FAKE_TextPrintString
  908.         PlayerSetControl(0)
  909.        
  910.         Wait(0)
  911.     until IBBR(4,0)
  912.     while IBBR(4,0) or IBBR(8,0) do
  913.         Wait(0)
  914.     end
  915.    
  916.     gConsole.ColumnFill = {}
  917.    
  918.     if Title == gConsole.Name and gConsole.Pause[1] then
  919.         for k,v in ipairs(gConsole.Pause[2]) do
  920.             if PedIsValid(v[1]) then
  921.                 GameSetPedStat(v[1],20,v[2])
  922.             end
  923.         end
  924.        
  925.         for i = 1,table.getn(gConsole.Pause[2]) do table.remove(gConsole.Pause[2],i) end
  926.     end
  927.    
  928.     _G["IsButtonPressed"],_G["IsButtonBeingPressed"],_G["IsButtonBeingReleased"] = IBP,IBBP,IBBR
  929.     _G["TextPrintString"] = CC_Print
  930.     PlayerSetControl(1)
  931. end
  932.  
  933. -------------------------------------------------------------------------------
  934. -- Decoder / Converter
  935. -------------------------------------------------------------------------------
  936.  
  937. function F_StringToObj(String)
  938.     local Peds = {
  939.         gPlayer = 0,
  940.         gZoe = {2,48},
  941.         gBeatrice = {3,95},
  942.         gAlgernon = {4,208},
  943.         gFatty = {5,122,155},
  944.         gMelvin = 6,
  945.         gThad = {7,174,210,224},
  946.         gBucky = {8,209},
  947.         gCornelius = 9,
  948.         gEarnest = {10,215},
  949.         gDonald = {11,162},
  950.         gDamon = {12,112,168,205},
  951.         gKirby = {13,109,207},
  952.         gMandy = {14,93,230},
  953.         gDan = {15,111},
  954.         gLuis = {16,92},
  955.         gCasey = {17,164,232},
  956.         gBo = {18,204,231},
  957.         gTed = {19,110,216},
  958.         gJuri = {20,206},
  959.         gPeanut = {21,202},
  960.         gHal = {22,200},
  961.         gJohnny = {23,217},
  962.         gLefty = 24,
  963.         gLola = {25,96},
  964.         gLucky = {26,161},
  965.         gVance = {27,173,203},
  966.         gRicky = 28,
  967.         gNorton = {29,201},
  968.         gGord = {30,214},
  969.         gTad = {31,177,213},
  970.         gChad = {32,117,241,242},
  971.         gBif = {33,133,172,243},
  972.         gJustin = {34,118,179,212,244,245},
  973.         gBryce = {35,36,178,239,240},
  974.         gDarby = {37,218},
  975.         gPinky = {38,94,167,175,182},
  976.         gAngie = {39,166,180},
  977.         gParker = {40,119,163,211,246,247},
  978.         gJerry = {41,198},
  979.         gOtto = {42,150},
  980.         gLeon = {43,153,199},
  981.         gDuncan = 44,
  982.         gHenry = {45,154},
  983.         gGurney = {46,197},
  984.         gOmar = 47,
  985.         gMax = 49,
  986.         gSeth = 50,
  987.         gEdward = 51,
  988.         gKarl = 52,
  989.         gTheo = 53,
  990.         gPeabody = 54,
  991.         gBurton = {55,229},
  992.         gLuntz = 56,
  993.         gGalloway = {57,129},
  994.         gEdna = {58,221},
  995.         gWinston = 59,
  996.         gMcRae = 60,
  997.         gHattrick = 61,
  998.         gCarvin = 62,
  999.         gPhillips = 63,
  1000.         gSlawter = 64,
  1001.         gCrabblesnitch = 65,
  1002.         gSheldon = {66,225},
  1003.         gChristy = {67,90,181},
  1004.         gGloria = 68,
  1005.         gPedro = {69,159,226,258},
  1006.         gConstantinos = {70,235},
  1007.         gRay = 71,
  1008.         gIvan = {72,170,227},
  1009.         gTrevor = {73,171,228},
  1010.         gEunice = {74,256},
  1011.         gRussell = {75,176},
  1012.         gBambillo = 76,
  1013.         gSullivan = 77,
  1014.         gKopke = 78,
  1015.         gRushinski = 79,
  1016.         gIsaacs = 80,
  1017.         gBethany = 81,
  1018.         gORourke = 82,
  1019.         gMonson = {83,234},
  1020.         gOwens = 84,
  1021.         gTrent = 85,
  1022.         gTobias = 86,
  1023.         gGrant = 87,
  1024.         gMascot = 88,
  1025.         gOh = 89,
  1026.         gEdgar = {91,196},
  1027.         gWilliams = {97,238},
  1028.         gOWrest = 98,
  1029.         gDavis = 99,
  1030.         gBreckindale = 100,
  1031.         gDoolin = 101,
  1032.         gTroy = 102,
  1033.         gNate = 103,
  1034.         gCarmichael = 104,
  1035.         gNicky = 105,
  1036.         gWatts = 106,
  1037.         gAbby = 107,
  1038.         gMihailovich = 108,
  1039.         gFreeley = 113,
  1040.         gDorsey = 114,
  1041.         gHector = 115,
  1042.         gOsbourne = 116,
  1043.         gMaria = 120,
  1044.         gBob = 121,
  1045.         gChuck = 123,
  1046.         gIan = 124,
  1047.         gFenwick = 125,
  1048.         gNeil = 126,
  1049.         gSvenson = 127,
  1050.         gDenny = 128,
  1051.         gGary = {130,160},
  1052.         gKrakauer = 131,
  1053.         gMoratti = 132,
  1054.         gPeter = {134,165,255},
  1055.         gSmith = 135,
  1056.         gRat = 136,
  1057.         gMelody = {137,257},
  1058.         gKaren = 138,
  1059.         gGordon = {139,169},
  1060.         gBrandy = 140,
  1061.         gPitbull = {141,219,220},
  1062.         gLance = 142,
  1063.         gCrystal = 143,
  1064.         gMartin = 144,
  1065.         gEthan = 145,
  1066.         gWade = 146,
  1067.         gTom = 147,
  1068.         gRamirez = 148,
  1069.         gHuntingdon = 149,
  1070.         gWiggins = 151,
  1071.         gFloyd = 152,
  1072.         gStan = 156,
  1073.         gHandy = 157,
  1074.         gGregory = 158,
  1075.         gBuba = 183,
  1076.         gMrGordon = 184,
  1077.         gLisburn = 185,
  1078.         gBetty = 187,
  1079.         gLightning = 188,
  1080.         gZeke = 189,
  1081.         gAlfred = 190,
  1082.         gParis = 191,
  1083.         gCourtney = 192,
  1084.         gDelilah = 193,
  1085.         gDrew = 194,
  1086.         gCastillo = 195,
  1087.         gMcInnis = {222,236,237},
  1088.         gJohnson = 223,
  1089.         gPunchBag = 233,
  1090.         gMatthews = 248,
  1091.         gPeters = 249,
  1092.         gElfF = 250,
  1093.         gElfM = 251,
  1094.         gRudy = 252,
  1095.         gSanta = {253,254},
  1096.        
  1097.         gGay = {85,13,109,207}, -- bonus!, you already know who's who
  1098.     }
  1099.     if Peds[String] then
  1100.         if String == "gPlayer" then
  1101.             return gPlayer
  1102.         end
  1103.        
  1104.         for i,Ped in {PedFindInAreaXYZ(0,0,0,99999)} do
  1105.             if PedIsValid(Ped) then
  1106.                 if type(Peds[String]) == "table" then
  1107.                     for Index = 1,table.getn(Peds[String]) do
  1108.                         if PedIsModel(Ped,Peds[String][Index]) then
  1109.                             return Ped
  1110.                         end
  1111.                     end
  1112.                 else
  1113.                     if PedIsModel(Ped,Peds[String]) then
  1114.                         return Ped
  1115.                     end
  1116.                 end
  1117.             end
  1118.         end
  1119.     end
  1120.    
  1121.     local Vehicles = {
  1122.         vGreen = 272,
  1123.         vRetro = 273,
  1124.         vCrap = 274,
  1125.         vBan = 279,
  1126.         vRed = 278,
  1127.         vBlue = 277,
  1128.         vMountain = 280,
  1129.         vLady = 281,
  1130.         vAqua = 283,
  1131.         vRacer = 282,
  1132.         vScooter = 276,
  1133.         vMower = 284,
  1134.         vGoCart = 289,
  1135.         vTaxi = 286,
  1136.         vLimo = 290,
  1137.         vForeign = 292,
  1138.         vRegular = 293,
  1139.         v70Wagon = 294,
  1140.         vDomestic = 296,
  1141.         vTruck = 297,
  1142.         vDozer = 288,
  1143.         vPBike = 275,
  1144.         vPCar = 295,
  1145.         vArc1 = 298,
  1146.         vArc2 = 287,
  1147.         vArc3 = 285,
  1148.        
  1149.         -- shorter name
  1150.         vGRN = 272,
  1151.         vRTR = 273,
  1152.         vMTN = 280,
  1153.         vSCTR = 276,
  1154.         vGC = 289,
  1155.         vFRGN = 292,
  1156.         vRGLR = 293,
  1157.         vWGN = 294,
  1158.         vDMST = 296,
  1159.         vPB = 275,
  1160.         vPC = 295,
  1161.     }
  1162.     if Vehicles[String] then
  1163.         local Result = VehicleFindInAreaXYZ(0,0,0,999999)
  1164.         if type(Result) == "table" then
  1165.             for I,V in ipairs(Result) do
  1166.                 if VehicleIsValid(V) and VehicleIsModel(V,Vehicles[String]) then
  1167.                     return V
  1168.                 end
  1169.             end
  1170.         end
  1171.     end
  1172.    
  1173.     return nil
  1174. end
  1175.  
  1176. function F_FuncGetResult(String,Arguments)
  1177.     local Func = {
  1178.         AreaGetTransitionTime = 1,
  1179.         AreaGetPlayerPositionBeforeStore = 5,
  1180.         AreaGetPopulationCullDistance = 1,
  1181.         AreaPOIGetGender = 1,
  1182.         AreaPOIGetMaxNumber = 1,
  1183.         AreaPOIGetFaction = 1,
  1184.         AreaPOIGetInterestType = 1,
  1185.         AreaPOIGetPosition = 3,
  1186.         AreaGetScriptedPOIPointToActivate = 1,
  1187.         AreaGetVisible = 1,
  1188.         ButtonHistoryGetFromHistory = 1,
  1189.         CameraGet169Mode = 1,
  1190.         CameraGetActive = 1,
  1191.         CameraGetFOV = 1,
  1192.         WeatherGet = 1,
  1193.         CarnivalBallTossGetCount = 1,
  1194.         CarnivalDunkTankGetCount = 1,
  1195.         CarnivalDunkTankGetTargetPos = 3,
  1196.         CarnivalStrikerMeterGetLevel = 1,
  1197.         ClassBiologyGetScorePercentage = 1,
  1198.         ClassChemGetActionJustFailed = 1,
  1199.         ClassChemGetActionJustFinished = 1,
  1200.         ClassChemGetActionJustStarted = 1,
  1201.         ClassChemGetLastAction = 1,
  1202.         ClassChemGetPerformance = 1,
  1203.         ClassEnglishGetLastSubmittedWord = 1,
  1204.         ClassEnglishGetLastSubmittedWordLength = 1,
  1205.         ClassEnglishGetScorePercentage = 1,
  1206.         ClassGeographyGetScorePercentage = 1,
  1207.         ClassMathAnswerGiven = 1,
  1208.         ClassMathGetScore = 1,
  1209.         ClassMathGetScorePercentage = 1,
  1210.         ClassMusicGetWinner = 1,
  1211.         CompareHashIDs = 1,
  1212.         ClockGet = 1,
  1213.         ClothingGetPlayersHair = 1,
  1214.         ClothingGetPlayerOutfit = 1,
  1215.         ClothingGetPlayer = 1,
  1216.         CollectiblesGetNumCollected = 1,
  1217.         CollectiblesGetNumCollectable = 1,
  1218.         DemoBuildGetSelectedMission = 1,
  1219.         GetCutsceneRunning = 1,
  1220.         GetCutsceneTime = 1,
  1221.         CounterGetCurrent = 1,
  1222.         CounterGetMax = 1,
  1223.         GetPointFromPath = 3,
  1224.         GetPointListSize = 1,
  1225.         GetPointFromPointList = 3,
  1226.         GetPointList = 3,
  1227.         PathGetLastNode = 1,
  1228.         ItemGetCurrentNum = 1,
  1229.         GetStickValue = 1,
  1230.         MissionGetUserStartResponse = 1,
  1231.         GetFactionRespect = 1,
  1232.         GetCurrentDay = 1,
  1233.         GetWeaponLOD = 1,
  1234.         ChapterGet = 1,
  1235.         FireGetHealth = 1,
  1236.         GetMissionCount = 1,
  1237.         MissionGetCurrentName = 1,
  1238.         MissionGetName = 1,
  1239.         MissionGetIndex = 1,
  1240.         GetTotalMissionSuccessCount = 1,
  1241.         GetMissionCurrentSuccessCount = 1,
  1242.         GetMissionCurrentAttemptCount = 1,
  1243.         GetMissionSuccessCount = 1,
  1244.         GetMissionAttemptCount = 1,
  1245.         MissionTimerGetTimeRemaining = 1,
  1246.         ObjectGetModelIndex = 1,
  1247.         PAnimGetHealth = 1,
  1248.         PAnimGetPathFollowSpeed = 1,
  1249.         PAnimGetPoolIndex = 1,
  1250.         PAnimGetPosition = 3,
  1251.         PAnimGetPropFlag = 1,
  1252.         PAnimGetSocketXYZ = 3,
  1253.         PedGetGrappleTargetPed = 1,
  1254.         PedGetDamageTakenMultiplier = 1,
  1255.         PedGetDamageGivenMultiplier = 1,
  1256.         PedGetName = 1,
  1257.         PedGetNameHashID = 1,
  1258.         PedGetAmmoCount = 1,
  1259.         PedGetTargetPed = 1,
  1260.         PedGetFaction = 1,
  1261.         PedGetPedCountWithModel = 1,
  1262.         PedGetLastVehicle = 1,
  1263.         PedGetImmortalFlag = 1,
  1264.         PedGetOffsetInWorldCoords = 3,
  1265.         PedGetWeapon = 1,
  1266.         PedGetHeadPos = 3,
  1267.         PedGetUniqueModelStatus = 1,
  1268.         PedGetEmotionTowardsPed = 1,
  1269.         PedGetAllyFollower = 1,
  1270.         PedGetAllyLeader = 1,
  1271.         PedGetLastHitWeapon = 1,
  1272.         PedGetHeading = 1,
  1273.         PedGetFlag = 1,
  1274.         PedGetPedToTypeAttitude = 1,
  1275.         PedGetTypeToTypeAttitude = 1,
  1276.         PedGetRandomModelId = 1,
  1277.         PedGetHitRecordDamage = 1,
  1278.         PedGetMoney = 1,
  1279.         PedGetHealth = 1,
  1280.         PedGetMaxHealth = 1,
  1281.         PedGetVehicleWhoHitMeLast = 1,
  1282.         PedGetWhoHitMeLast = 1,
  1283.         PedGetPosXYZ = 3,
  1284.         WeaponGetType = 1,
  1285.         PickupGetXYZ = 3,
  1286.         PlayerGetPhysicalState = 1,
  1287.         PlayerGetScriptSavedData = 1,
  1288.         PlayerGetNumTimesBusted = 1,
  1289.         PlayerGetPunishmentPoints = 1,
  1290.         PlayerGetLastBikeId = 1,
  1291.         PlayerGetBikeId = 1,
  1292.         PlayerGetMoney = 1,
  1293.         PlayerGetHealth = 1,
  1294.         PlayerGetPosXYZ = 3,
  1295.         POIGetPosXYZ = 3,
  1296.         ShopGetClerkID = 1,
  1297.         StatGetGameCompletion = 1,
  1298.         StatGetPrincipalDiffAsFloat = 1,
  1299.         StatGetPrincipalDiffAsInt = 1,
  1300.         StatGetAsFloat = 1,
  1301.         StatGetAsInt = 1,
  1302.         GameGetPedStat = 1,
  1303.         SystemGetSavedPositionInformation = 6,
  1304.         GetLanguage = 1,
  1305.         GetCurrentNumOfAmbientBikes = 1,
  1306.         VehicleGetHealth = 1,
  1307.         CarGetDamageNumber = 1,
  1308.         VehicleGetModelId = 1,
  1309.         VehicleGetPosXYZ = 3,
  1310.        
  1311.         AreaIsCollisionLoaded = 1,
  1312.         AreaIsDoorLocked = 1,
  1313.         AreaIsDoorLockedToPeds = 1,
  1314.         AreaIsDoorOpen = 1,
  1315.         AreaIsLoading = 1,
  1316.         AreaTriggerIsValid = 1,
  1317.         CameraIsPointVisible = 1,
  1318.         CarnivalStrikerMeterIsRunning = 1,
  1319.         ClassBiologyIsBadMove = 1,
  1320.         ClassBiologyIsGrossOut = 1,
  1321.         ClassEnglishWordWasDuplicate = 1,
  1322.         ClassEnglishWordWasNaughty = 1,
  1323.         ClassEnglishWordWasNotValid = 1,
  1324.         ClassEnglishWordWasTooShort = 1,
  1325.         ClassEnglishWordWasValid = 1,
  1326.         ClassMathValidAnswer = 1,
  1327.         ClassMathInvalidAnswer = 1,
  1328.         ClockIsPaused = 1,
  1329.         ClothingIsWearingAnyOutfit = 1,
  1330.         ClothingIsWearingOutfit = 1,
  1331.         EffectIsRunning = 1,
  1332.         GetIsMissionSpecific = 1,
  1333.         IsActionTreeLoaded = 1,
  1334.         IsButtonBeingPressed = IBBP,
  1335.         IsButtonBeingReleased = IBBR,
  1336.         IsButtonPressed = IBP,
  1337.         IsCutsceneLoaded = 1,
  1338.         IsDemoBuildEnabled = 1,
  1339.         IsInTitleMenu = 1,
  1340.         IsItemAWeapon = 1,
  1341.         IsMissionAvailable = 1,
  1342.         IsMissionCompleated = 1,
  1343.         IsMissionDebugFailure = 1,
  1344.         IsMissionDebugSuccess = 1,
  1345.         IsMissionFromDebug = 1,
  1346.         IsMissionFromRestart = 1,
  1347.         IsMissionRestartable = 1,
  1348.         IsMissionSimpleFade = 1,
  1349.         IsStreamingBusy = 1,
  1350.         MinigameIsActive = 1,
  1351.         MinigameIsFadingCompletion = 1,
  1352.         MinigameIsHighScore = 1,
  1353.         MinigameIsReady = 1,
  1354.         MinigameIsShowingCompletion = 1,
  1355.         MinigameIsShowingGrades = 1,
  1356.         MinigameIsSuccess = 1,
  1357.         ObjectIsDestroyed = 1,
  1358.         ObjectIsInAreaObject = 1,
  1359.         ObjectIsInAreaXYZ = 1,
  1360.         ObjectIsModel = 1,
  1361.         ObjectTypeIsInTrigger = 1,
  1362.         PAnimIsDestroyed = 1,
  1363.         PAnimIsOpen = 1,
  1364.         PAnimIsPlaying = 1,
  1365.         PAnimIsPlayingNode = 1,
  1366.         PAnimIsUsed = 1,
  1367.         POIIsValid = 1,
  1368.         PedIsAlerted = 1,
  1369.         PedIsAnimFlagSet = 1,
  1370.         PedIsCurrentAnim = 1,
  1371.         PedIsDead = 1,
  1372.         PedIsDoingTask = 1,
  1373.         PedIsFacingObject = 1,
  1374.         PedIsFacingXYZ = 1,
  1375.         PedIsFemale = 1,
  1376.         PedIsHit = 1,
  1377.         PedIsInAnyVehicle = 1,
  1378.         PedIsInAreaObject = 1,
  1379.         PedIsInAreaXYZ = 1,
  1380.         PedIsInCombat = 1,
  1381.         PedIsInTrigger = 1,
  1382.         PedIsInVehicle = 1,
  1383.         PedIsModel = 1,
  1384.         PedIsOnScreen = 1,
  1385.         PedIsOnVehicle = 1,
  1386.         PedIsPedInBox = 1,
  1387.         PedIsPlayer = 1,
  1388.         PedIsPlaying = 1,
  1389.         PedIsPropAttached = 1,
  1390.         PedIsSocializing = 1,
  1391.         PedIsSpotted = 1,
  1392.         PedIsStandingOnVehicle = 1,
  1393.         PedIsTargetable = 1,
  1394.         PedIsUsingProp = 1,
  1395.         PedIsValid = 1,
  1396.         PedIsWantingToSocialize = 1,
  1397.         PickupIsInAreaXYZ = 1,
  1398.         PickupIsPickedUp = 1,
  1399.         PlayerIsInAnyVehicle = 1,
  1400.         PlayerIsInAreaObject = 1,
  1401.         PlayerIsInAreaXYZ = 1,
  1402.         PlayerIsInStealthProp = 1,
  1403.         PlayerIsInTrigger = 1,
  1404.         PlayerIsInVehicle = 1,
  1405.         SoundIsPreloadReady = 1,
  1406.         SoundIsSpeechPreloaded = 1,
  1407.         SystemIsReady = 1,
  1408.         VehicleIsInAreaXYZ = 1,
  1409.         VehicleIsInTrigger = 1,
  1410.         VehicleIsModel = 1,
  1411.         VehicleIsValid = 1,
  1412.         YearbookIsFull = 1,
  1413.        
  1414.         rawget = 1,
  1415.         getfenv = 1,
  1416.         getmetatable = 1,
  1417.         xpcall = 1,
  1418.         pcall = 1,
  1419.        
  1420.         -- string
  1421.         ["string.find"] = string.find,
  1422.        
  1423.         -- table
  1424.         ["table.getn"] = table.getn,
  1425.         ["table.concat"] = table.concat,
  1426.        
  1427.         -- arithmetic
  1428.         ["math.sin"] = math.sin,
  1429.         ["math.cos"] = math.cos,
  1430.         ["math.tan"] = math.tan,
  1431.         ["math.abs"] = math.abs,
  1432.         ["math.randomseed"] = math.randomseed,
  1433.         ["math.random"] = math.random,
  1434.         ["math.floor"] = math.floor,
  1435.         ["math.ceil"] = math.ceil,
  1436.         ["math.sqrt"] = math.sqrt,
  1437.         ["math.atan"] = math.atan,
  1438.         ["math.atan2"] = math.atan2,
  1439.         ["math.acos"] = math.acos,
  1440.         ["math.asin"] = math.asin,
  1441.         ["math.pow"] = math.pow,
  1442.         ["math.deg"] = math.deg,
  1443.         ["math.rad"] = math.rad,
  1444.         ["math.exp"] = math.exp,
  1445.         ["math.mod"] = math.mod, -- 5.0.2
  1446.        
  1447.         -- debug
  1448.         ["debug.getupvalue"] = debug.getupvalue,
  1449.         ["debug.gethook"] = debug.gethook,
  1450.         --["debug.getinfo"] = debug.getinfo, -- returns a table which can't be read
  1451.         ["debug.getlocal"] = debug.getlocal,
  1452.     }
  1453.     if Func[String] then
  1454.         local Output
  1455.         if Arguments then
  1456.             Output = {
  1457.                 (type(Func[String]) == "function" and Func[String] or _G[String])(type(Arguments) == "table" and unpack(Arguments) or Arguments)
  1458.             }
  1459.         else
  1460.             Output = {(type(Func[String]) == "function" and Func[String] or _G[String])()}
  1461.         end
  1462.        
  1463.         local Text = ""
  1464.         if table.getn(Output) > 1 then
  1465.             local function F_Coma(Current,Max) if Current == Max then return "" end return "," end
  1466.             for K = 1,table.getn(Output) do
  1467.                 Text = Text..""..tostring(Output[K])..""..F_Coma(K,table.getn(Output))
  1468.             end
  1469.         else
  1470.             Text = tostring(Output[1])
  1471.         end
  1472.        
  1473.         while not IBBP(8,0) do
  1474.             CC_Print("#RESULT\n> "..Text.."\n\n~JUMP~ CONFIRM",0,1) Wait(0)
  1475.         end
  1476.        
  1477.         return true
  1478.     end
  1479.     return false
  1480. end
  1481.  
  1482. function SET_VARIABLES(Type,Variable,Value,TableVal)
  1483.     local ArgExpressions,Identified = {
  1484.         {"true",true},{"not false",true},{"false",false},{"not true",false},{"nil",nil},{"not nil",true},{"{}",{}}
  1485.     },false
  1486.    
  1487.     if Type == "_G " then
  1488.         local F_GlobalSet = function(Var,Val)
  1489.             local Type = type(Var)
  1490.            
  1491.             if Type == "table" then
  1492.                 local TableEnd = table.getn(Var)
  1493.                 for i = 1,table.getn(Var) do
  1494.                     for Number = 1,5000 do
  1495.                         if Var[i] == tostring(Number) then Var[i] = Number end
  1496.                     end
  1497.                 end
  1498.                
  1499.                 if TableEnd == 2 then
  1500.                     _G[Var[1]][Var[2]] = Val
  1501.                 elseif TableEnd == 3 then
  1502.                     _G[Var[1]][Var[2]][Var[3]] = Val
  1503.                 elseif TableEnd == 4 then
  1504.                     _G[Var[1]][Var[2]][Var[3]][Var[4]] = Val
  1505.                 elseif TableEnd == 5 then
  1506.                     _G[Var[1]][Var[2]][Var[3]][Var[4]][Var[5]] = Val
  1507.                 elseif TableEnd == 6 then
  1508.                     _G[Var[1]][Var[2]][Var[3]][Var[4]][Var[5]][Var[6]] = Val
  1509.                 elseif TableEnd == 7 then
  1510.                     _G[Var[1]][Var[2]][Var[3]][Var[4]][Var[5]][Var[6]][Var[7]] = Val
  1511.                 elseif TableEnd == 8 then
  1512.                     _G[Var[1]][Var[2]][Var[3]][Var[4]][Var[5]][Var[6]][Var[7]][Var[8]] = Val
  1513.                 elseif TableEnd == 9 then
  1514.                     _G[Var[1]][Var[2]][Var[3]][Var[4]][Var[5]][Var[6]][Var[7]][Var[8]][Var[9]] = Val
  1515.                 elseif TableEnd == 10 then
  1516.                     _G[Var[1]][Var[2]][Var[3]][Var[4]][Var[5]][Var[6]][Var[7]][Var[8]][Var[9]][Var[10]] = Val
  1517.                 else
  1518.                     ER_MESSAGE("error: table is unreachable",2)
  1519.                 end
  1520.             else
  1521.                 _G[Var] = F_StringToObj(Val) or Val
  1522.             end
  1523.         end
  1524.        
  1525.         for i,Exp in ipairs(ArgExpressions) do
  1526.             if Value == Exp[1] then
  1527.                 F_GlobalSet(Variable,Exp[2]) Identified = true
  1528.                 break
  1529.             end
  1530.         end
  1531.        
  1532.         if TableVal ~= nil then
  1533.             local Arithmetic = F_Arithmetical(TableVal,Value)
  1534.             if Arithmetic ~= nil then
  1535.                 F_GlobalSet(Variable,Arithmetic) Identified = true
  1536.             end
  1537.         end
  1538.        
  1539.         if not Identified then
  1540.             local STRINGS,IsString = {
  1541.                 "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
  1542.                 "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," "
  1543.             },false
  1544.             for i,v in ipairs(STRINGS) do
  1545.                 if string.find(Value,v,1) then
  1546.                     IsString = true
  1547.                 end
  1548.             end
  1549.            
  1550.             if IsString then
  1551.                 local IsNotGlobal = true
  1552.                
  1553.                 local NewValue = type(TableVal) == "table" and F_ToVariable(F_StringToVar(TableVal,1,table.getn(TableVal))) or _G[Value]
  1554.                 if type(NewValue) ~= "nil" then
  1555.                     F_GlobalSet(Variable,NewValue) IsNotGlobal = false
  1556.                 end
  1557.                
  1558.                 if IsNotGlobal then F_GlobalSet(Variable,Value) end
  1559.             else
  1560.                 F_GlobalSet(Variable,tonumber(Value))
  1561.             end
  1562.         end
  1563.     elseif Type == "_L " then
  1564.         -- this was merely hypothetical even though i implemented it correctly according to https://www.lua.org/pil/23.1.1.html
  1565.         if type(Variable) == "string" then
  1566.             local Index = 1
  1567.             while true do
  1568.                 local Name,Val = debug.getlocal(2,Index)
  1569.                 if not Name then break end
  1570.                
  1571.                 if Name == Variable then
  1572.                     for i,Exp in ipairs(ArgExpressions) do
  1573.                         if Value == Exp[1] then
  1574.                             debug.setlocal(2,Index,Exp[2]) Identified = true
  1575.                             break
  1576.                         end
  1577.                     end
  1578.                    
  1579.                     if not Identified then
  1580.                         if TableVal then
  1581.                             local Arithmetic = F_Arithmetical(TableVal,Value)
  1582.                             if Arithmetic ~= nil then
  1583.                                 debug.setlocal(2,Index,Arithmetic) break
  1584.                             end
  1585.                         end
  1586.                        
  1587.                         local STRINGS,IsString = {
  1588.                             "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
  1589.                             "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," "
  1590.                         },false
  1591.                         for i,v in ipairs(STRINGS) do
  1592.                             if string.find(Value,v,1) then
  1593.                                 IsString = true
  1594.                             end
  1595.                         end
  1596.                        
  1597.                         if IsString then
  1598.                             local IsNotGlobal = true
  1599.                            
  1600.                             local NewValue = type(TableVal) == "table" and F_ToVariable(F_StringToVar(TableVal,1,table.getn(TableVal))) or _G[Value]
  1601.                             if type(NewValue) ~= "nil" then
  1602.                                 debug.setlocal(2,Index,NewValue) IsNotGlobal = false
  1603.                             end
  1604.                            
  1605.                             if IsNotGlobal then debug.setlocal(2,Index,F_StringToObj(Value) or Value) end
  1606.                         else
  1607.                             debug.setlocal(2,Index,tonumber(Value))
  1608.                         end
  1609.                     end
  1610.                 end
  1611.                
  1612.                 Index = Index + 1
  1613.                 Wait(0)
  1614.             end
  1615.         else
  1616.             ER_MESSAGE("string expected for _L",2)
  1617.         end
  1618.     else
  1619.         ER_MESSAGE("expected '_G' or '_L'",2)
  1620.     end
  1621. end
  1622.  
  1623. function F_TableToVar(Table)
  1624.     if type(Table) == "table" then
  1625.         local TotalArg = table.getn(Table)
  1626.         for i = 1,table.getn(Table) do
  1627.             for Number = 1,5000 do
  1628.                 if Table[i] == tostring(Number) then
  1629.                     Table[i] = Number
  1630.                 end
  1631.             end
  1632.         end
  1633.        
  1634.         if TotalArg == 2 then
  1635.             return _G[Table[1]][Table[2]]
  1636.         elseif TotalArg == 3 then
  1637.             return _G[Table[1]][Table[2]][Table[3]]
  1638.         elseif TotalArg == 4 then
  1639.             return _G[Table[1]][Table[2]][Table[3]][Table[4]]
  1640.         elseif TotalArg == 5 then
  1641.             return _G[Table[1]][Table[2]][Table[3]][Table[4]][Table[5]]
  1642.         elseif TotalArg == 6 then
  1643.             return _G[Table[1]][Table[2]][Table[3]][Table[4]][Table[5]][Table[6]]
  1644.         elseif TotalArg == 7 then
  1645.             return _G[Table[1]][Table[2]][Table[3]][Table[4]][Table[5]][Table[6]][Table[7]]
  1646.         elseif TotalArg == 8 then
  1647.             return _G[Table[1]][Table[2]][Table[3]][Table[4]][Table[5]][Table[6]][Table[7]][Table[8]]
  1648.         elseif TotalArg == 9 then
  1649.             return _G[Table[1]][Table[2]][Table[3]][Table[4]][Table[5]][Table[6]][Table[7]][Table[8]][Table[9]]
  1650.         elseif TotalArg == 10 then
  1651.             return _G[Table[1]][Table[2]][Table[3]][Table[4]][Table[5]][Table[6]][Table[7]][Table[8]][Table[9]][Table[10]]
  1652.         else
  1653.             ER_MESSAGE("error: table is unreachable",2)
  1654.         end
  1655.     else
  1656.         ER_MESSAGE("expected argument of type table, got "..type(Table),2)
  1657.     end
  1658.    
  1659.     return nil
  1660. end
  1661.  
  1662. function F_TableToStr(Table)
  1663.     local Text,PrevIsNumber = "",false
  1664.     for i = 1,table.getn(Table) do
  1665.         if i == table.getn(Table) then
  1666.             if PrevIsNumber then Text,PrevIsNumber = Text.."]"..Table[i],false
  1667.             else
  1668.                 Text = Text.."."..Table[i]
  1669.             end
  1670.         else
  1671.             local IsNumber = false
  1672.             for number = 1,5000 do
  1673.                 if Table[i] == tostring(number) then
  1674.                     Text,PrevIsNumber,IsNumber = Text.."["..Table[i],true,true
  1675.                     break
  1676.                 end
  1677.             end
  1678.            
  1679.             if not IsNumber then
  1680.                 if PrevIsNumber then Text,PrevIsNumber = Text.."]"..Table[i],false
  1681.                 else
  1682.                     if i ~= 1 then Text = Text.."."..Table[i]
  1683.                     else
  1684.                         Text = Text..""..Table[i]
  1685.                     end
  1686.                 end
  1687.             end
  1688.         end
  1689.     end
  1690.    
  1691.     return Text
  1692. end
  1693.  
  1694. function F_StringToVar(Table,Min,Max)
  1695.     local Separator,NewTable,Text = {},{},""
  1696.     for TableNumber = Min,Max do
  1697.         Text = Text..""..Table[TableNumber]
  1698.         table.insert(NewTable,Table[TableNumber])
  1699.     end
  1700.    
  1701.     if (string.find(Text,"[",1) and string.find(Text,"]",1)) or string.find(Text,".",1) then
  1702.         Text = {}
  1703.         for Number = 1,table.getn(NewTable) do
  1704.             if NewTable[Number] == "." or NewTable[Number] == "[" or NewTable[Number] == "]" then
  1705.                 table.insert(Separator,Number)
  1706.             end
  1707.         end
  1708.        
  1709.         local TEMP_Var,Current = "",0
  1710.         while true do
  1711.             Current = Current + 1
  1712.            
  1713.             if Current > table.getn(NewTable) then
  1714.                 break
  1715.             else
  1716.                 if Current > 1 then
  1717.                     local SkipThisOne = false
  1718.                     for i = 1,table.getn(Separator) do
  1719.                         if Current == Separator[i] then
  1720.                             table.insert(Text,TEMP_Var)
  1721.                            
  1722.                             TEMP_Var,SkipThisOne = "",true
  1723.                         end
  1724.                     end
  1725.                    
  1726.                     if not SkipThisOne then
  1727.                         TEMP_Var = TEMP_Var..""..NewTable[Current]
  1728.                        
  1729.                         if Current == table.getn(NewTable) then
  1730.                             table.insert(Text,TEMP_Var)
  1731.                         end
  1732.                     end
  1733.                 else
  1734.                     TEMP_Var = NewTable[Current]
  1735.                 end
  1736.             end
  1737.         end
  1738.     end
  1739.    
  1740.     return Text
  1741. end
  1742.  
  1743. function F_StringToArg(Table,String)
  1744.     local ArgExpressions,Identified = {
  1745.         {"true",true},{"not false",true},{"false",false},{"not true",false},{"nil",nil},{"not nil",true},{"{}",{}},
  1746.     },false
  1747.     for i,Exp in ipairs(ArgExpressions) do
  1748.         if String == Exp[1] then
  1749.             return Exp[2]
  1750.         end
  1751.     end
  1752.    
  1753.     local Arithmetic = F_Arithmetical(Table,String)
  1754.     if Arithmetic ~= nil then
  1755.         return Arithmetic
  1756.     end
  1757.    
  1758.     local STRINGS,IsString = {
  1759.         "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
  1760.         "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," "
  1761.     },false
  1762.     for i,v in ipairs(STRINGS) do
  1763.         if string.find(String,v,1) then
  1764.             IsString = true
  1765.         end
  1766.     end
  1767.    
  1768.     if IsString then
  1769.         local Value = type(Table) == "table" and F_ToVariable(F_StringToVar(Table,1,table.getn(Table))) or _G[String]
  1770.         if type(Value) ~= "nil" then
  1771.             return Value
  1772.         end
  1773.        
  1774.         local Thing = F_StringToObj(String)
  1775.         if Thing ~= nil then
  1776.             return Thing
  1777.         end
  1778.        
  1779.         return String -- the real string
  1780.     else
  1781.         return tonumber(String)
  1782.     end
  1783. end
  1784.  
  1785. function F_Arithmetical(Table,String)
  1786.     local Math,IsArithmeticOperation = {
  1787.         Char = {"*","/","+","-"},Separator = {},Table = {},Temp = {},NewSequence = {},Result = {},
  1788.         Calculate = function(V1,Char,V2)
  1789.             local Operation = {
  1790.                 {"*",V1 * V2},{"/",V1 / V2},{"+",V1 + V2},{"-",V1 - V2}
  1791.             }
  1792.             for I,V in ipairs(Operation) do
  1793.                 if Char == V[1] then
  1794.                     return V[2]
  1795.                 end
  1796.             end
  1797.            
  1798.             ER_MESSAGE("unexpected symbol char '"..Char.."'",2)
  1799.             return nil
  1800.         end
  1801.     },false
  1802.     for Index = 1,table.getn(Math.Char) do
  1803.         if string.find(String,Math.Char[Index],1) then
  1804.             IsArithmeticOperation = true
  1805.         end
  1806.     end
  1807.    
  1808.     if IsArithmeticOperation then
  1809.         local Text = ""
  1810.         for Index = 1,table.getn(Table) do
  1811.             if type(Math.Table[table.getn(Math.Separator) + 1]) ~= "table" then
  1812.                 Math.Table[table.getn(Math.Separator) + 1] = {}
  1813.             end
  1814.            
  1815.             if Table[Index] == "*" or Table[Index] == "/" or Table[Index] == "+" or Table[Index] == "-" then
  1816.                 for I,Char in ipairs(Math.Char) do
  1817.                     if Table[Index] == Char then
  1818.                         table.insert(Math.Separator,{Char,Index})
  1819.                     end
  1820.                 end
  1821.                
  1822.                 table.insert(Math.Temp,Text)
  1823.                 Text = ""
  1824.             else
  1825.                 Text = Text..""..Table[Index]
  1826.                
  1827.                 table.insert(Math.Table[table.getn(Math.Separator) + 1],Table[Index])
  1828.                 if Index == table.getn(Table) then
  1829.                     table.insert(Math.Temp,Text)
  1830.                 end
  1831.             end
  1832.         end
  1833.        
  1834.         for Index = 1,table.getn(Math.Separator) do
  1835.             if Math.Separator[Index][1] == "*" or Math.Separator[Index][1] == "/" then
  1836.                 table.insert(Math.NewSequence,Index)
  1837.             end
  1838.         end
  1839.        
  1840.         local F_AddNewResults = function(Int)
  1841.             local Alphabet,ProbablyMathLib = {
  1842.                 "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
  1843.                 "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
  1844.             },{false,false}
  1845.             for I,V in ipairs(Alphabet) do
  1846.                 if string.find(Math.Temp[Int],V,1) then
  1847.                     ProbablyMathLib[1] = true
  1848.                 elseif string.find(Math.Temp[Int + 1],V,1) then
  1849.                     ProbablyMathLib[2] = true
  1850.                 end
  1851.             end
  1852.            
  1853.             local Value = {}
  1854.             local F_GetResults = function(Index,TableIndex)
  1855.                 if ProbablyMathLib[Index] then
  1856.                     local Var = F_ToVariable(
  1857.                         ((string.find(Math.Temp[TableIndex],"[",1) and string.find(Math.Temp[TableIndex],"]",1)) or string.find(Math.Temp[TableIndex],".",1)) and Math.Table[TableIndex] or Math.Temp[TableIndex]
  1858.                     )
  1859.                     return Var ~= nil and tonumber(Var) or F_MathLib(Math.Table[TableIndex],Math.Temp[TableIndex])
  1860.                 end
  1861.                
  1862.                 return nil
  1863.             end
  1864.            
  1865.             Value[1] = F_GetResults(1,Int) or tonumber(Math.Temp[Int])
  1866.             Value[2] = F_GetResults(2,Int + 1) or tonumber(Math.Temp[Int + 1])
  1867.            
  1868.             if table.getn(Math.NewSequence) > 1 and Math.Separator[Int][1] == "*" or Math.Separator[Int][1] == "/" then
  1869.                 if Value[1] == 0 then
  1870.                     Value[1] = type(Math.Result[table.getn(Math.Result)]) ~= "nil" and Math.Result[table.getn(Math.Result)] or Value[1]
  1871.                 end
  1872.                
  1873.                 Math.Result[table.getn(Math.Result)] = Value[1] ~= 0 and 0 or Math.Result[table.getn(Math.Result)]
  1874.             end
  1875.            
  1876.             table.insert(Math.Result,
  1877.                 Math.Calculate(
  1878.                     Value[1],Math.Separator[Int][1],Value[2]
  1879.                 )
  1880.             )
  1881.             Math.Temp[Int],Math.Temp[Int + 1] = 0,0 -- reset the temporary results to get a minus number in subtraction
  1882.         end
  1883.        
  1884.         if table.getn(Math.NewSequence) > 0 then
  1885.             for i = 1,table.getn(Math.NewSequence) do
  1886.                 F_AddNewResults(Math.NewSequence[i])
  1887.             end
  1888.         end
  1889.        
  1890.         if table.getn(Math.Separator) > table.getn(Math.NewSequence) then
  1891.             for I = 1,table.getn(Math.Separator) do
  1892.                 if table.getn(Math.NewSequence) > 0 then
  1893.                     for K = 1,table.getn(Math.NewSequence) do
  1894.                         if I ~= Math.NewSequence[K] then F_AddNewResults(I) end
  1895.                     end
  1896.                 else
  1897.                     F_AddNewResults(I)
  1898.                 end
  1899.             end
  1900.         end
  1901.        
  1902.         local Output = 0
  1903.         for K = 1,table.getn(Math.Result) do
  1904.             Output = Output + Math.Result[K]
  1905.         end
  1906.        
  1907.         return Output
  1908.     else
  1909.         return F_MathLib(Table,String) or nil
  1910.     end
  1911. end
  1912.  
  1913. function F_MathLib(Table,String)
  1914.     -- sin, cos, tan, arcsin, arccos, arctan, square root, ceil, floor, degree, radian
  1915.     local Reference,Index = {
  1916.         {Func = "asin",Spell = {"a","s","i","n"}},
  1917.         {Func = "acos",Spell = {"a","c","o","s"}},
  1918.         {Func = "atan",Spell = {"a","t","a","n"}},
  1919.         {Func = "sin",Spell = {"s","i","n"}},
  1920.         {Func = "cos",Spell = {"c","o","s"}},
  1921.         {Func = "tan",Spell = {"t","a","n"}},
  1922.         {Func = "sqrt",Spell = {"s","q","r","t"}},
  1923.         {Func = "ceil",Spell = {"c","e","i","l"}},
  1924.         {Func = "floor",Spell = {"f","l","o","o","r"}},
  1925.         {Func = "deg",Spell = {"d","e","g"}},
  1926.         {Func = "rad",Spell = {"r","a","d"}},
  1927.     },nil
  1928.    
  1929.     for I = 1,table.getn(Reference) do
  1930.         if string.find(String,Reference[I].Func,1) then
  1931.             Index = I
  1932.            
  1933.             for K = 1,table.getn(Table) do
  1934.                 if K > table.getn(Reference[I].Spell) then
  1935.                     break
  1936.                 else
  1937.                     if Reference[I].Spell[K] ~= Table[K] then Index = nil break end
  1938.                 end
  1939.             end
  1940.         end
  1941.     end
  1942.    
  1943.     if type(Index) == "number" then
  1944.         if table.getn(Reference[Index].Spell) ~= table.getn(Table) then
  1945.             local Value = ""
  1946.             for I = table.getn(Reference[Index].Spell) + 1,table.getn(Table) do
  1947.                 Value = Value..""..Table[I]
  1948.             end
  1949.            
  1950.             return math[Reference[Index].Func](tonumber(Value))
  1951.         else
  1952.             ER_MESSAGE("expected number after '"..Reference[Index].Func.."'",2)
  1953.         end
  1954.     end
  1955.    
  1956.     -- factorial, http://www.codecodex.com/wiki/Calculate_the_factorial_of_a_number
  1957.     if string.find(String,"!",-1) then
  1958.         local F_Factorial = function(Number)
  1959.             if math.floor(Number) == Number then
  1960.                 local Result = 1
  1961.                 for Mul = 2,Number do
  1962.                     Result = Result * Mul
  1963.                 end
  1964.                
  1965.                 return Result
  1966.             else
  1967.                 ER_MESSAGE("expected an integer value",2)
  1968.                 return nil
  1969.             end
  1970.         end
  1971.        
  1972.         local Value = ""
  1973.         for I = 1,table.getn(Table) - 1 do
  1974.             Value = Value..""..Table[I]
  1975.         end
  1976.        
  1977.         return F_Factorial(tonumber(Value))
  1978.     end
  1979.    
  1980.     -- Pi
  1981.     if String == "Pi" or String == "pi" then
  1982.         return math.pi
  1983.     end
  1984.    
  1985.     return nil
  1986. end
  1987.  
  1988. function F_ToggleSwitchBoolean(Var)
  1989.     local VariableType = type(F_ToVariable(Var))
  1990.    
  1991.     if VariableType ~= "boolean" then
  1992.         ER_MESSAGE("expected argument of type boolean, got "..VariableType,2)
  1993.     else
  1994.         SET_VARIABLES("_G ",Var,tostring(not F_ToVariable(Var)))
  1995.     end
  1996. end
  1997.  
  1998. function F_ToVariable(Item)
  1999.     local Type = type(Item)
  2000.    
  2001.     if Type == "table" or Type == "string" then
  2002.         if Type == "table" then
  2003.             return F_TableToVar(Item)
  2004.         end
  2005.        
  2006.         return _G[Item]
  2007.     end
  2008.    
  2009.     ER_MESSAGE("unexpected type '"..Type.."'",2)
  2010.     return nil
  2011. end
  2012.  
  2013. function F_ToString(Variable)
  2014.     local Type = type(Variable)
  2015.    
  2016.     if Type == "table" or Type == "string" then
  2017.         if Type == "table" then
  2018.             return F_TableToStr(Variable)
  2019.         end
  2020.        
  2021.         return Variable
  2022.     end
  2023.    
  2024.     ER_MESSAGE("unexpected type '"..Type.."'",2)
  2025.     return nil
  2026. end
  2027.  
  2028. function F_ImportTable(Table)
  2029.     local NewTable = {}
  2030.    
  2031.     if type(Table) == "table" then
  2032.         for i = 1,table.getn(Table) do
  2033.             table.insert(NewTable,Table[i])
  2034.         end
  2035.        
  2036.         return NewTable
  2037.     end
  2038.    
  2039.     ER_MESSAGE("expected argument of type table, got "..type(Table),2)
  2040.     return nil
  2041. end
  2042.  
  2043. function F_BooleanToString(Boolean)
  2044.     if Boolean then
  2045.         return "ON"
  2046.     end
  2047.    
  2048.     return "OFF"
  2049. end
  2050.  
  2051. -------------------------------------------------------------------------------
  2052. -- Other utilities
  2053. -------------------------------------------------------------------------------
  2054.  
  2055. function F_CreateAnIndependentLoop(Loop)
  2056.     for _threadindex = 1,1000 do
  2057.         if type(_G["EXT_SCRIPT_".._threadindex]) ~= "function" then
  2058.             _G["EXT_SCRIPT_".._threadindex] = function()
  2059.                 Loop()
  2060.             end
  2061.        
  2062.             CreateThread("EXT_SCRIPT_".._threadindex) break
  2063.         end
  2064.     end
  2065. end
  2066.  
  2067. function F_Wait(MS,Skippable)
  2068.     local Timer = GetTimer()
  2069.     if MS ~= 0 then
  2070.         while Timer + MS > GetTimer() do
  2071.             if Skippable and IBBP(7,0) then break end Wait(0)
  2072.         end
  2073.     else
  2074.         Wait(0)
  2075.     end
  2076. end
  2077.  
  2078. function ER_MESSAGE(Text,Duration)
  2079.     local T = GetTimer()
  2080.     while T + (Duration * 1000) > GetTimer() do
  2081.         CC_Print(Text,0,1) Wait(0)
  2082.     end
  2083. end
  2084.  
  2085. -------------------------------------------------------------------------------
  2086. -- Key button
  2087. -------------------------------------------------------------------------------
  2088.  
  2089. function F_Navigate(tab,opt,prev,nxt,ctrl)
  2090.     if not IBP(9,0) then
  2091.         if F_Controller(prev,ctrl) or F_Scroll(prev,ctrl) then
  2092.             return F_Selection(tab,opt,0)
  2093.         elseif F_Controller(nxt,ctrl) or F_Scroll(nxt,ctrl) then
  2094.             return F_Selection(tab,opt,1)
  2095.         end
  2096.     end
  2097.    
  2098.     return opt
  2099. end
  2100.  
  2101. function F_Scroll(b,c)
  2102.     if IBP(b,c) then
  2103.         if gConsole.ScrollFaster + 800 <= GetTimer() then
  2104.             return true
  2105.         end
  2106.     end
  2107.    
  2108.     if IBBR(b,c) then
  2109.         gConsole.ScrollFaster = GetTimer()
  2110.     end
  2111.     return false
  2112. end
  2113.  
  2114. function F_Controller(b,c)
  2115.     if IBBP(b,c) then
  2116.         SoundPlay2D("ButtonDown")
  2117.        
  2118.         gConsole.ScrollFaster = GetTimer()
  2119.         return true
  2120.     end
  2121.     return false
  2122. end
  2123.  
  2124. function F_Selection(tab,var,pm)
  2125.     if pm == 1 then
  2126.         var = var + 1
  2127.         if var > table.getn(tab) then var = 1 end
  2128.     elseif pm == 0 then
  2129.         var = var - 1
  2130.         if var < 1 then var = table.getn(tab) end
  2131.     end
  2132.    
  2133.     return var
  2134. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement