SHARE
TWEET

encounters.lua

a guest Dec 17th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. api_version = "1.9.0.0"
  2.  
  3. AI_ACTORS_TABLE_POINTER = nil
  4. AI_ENCOUNTERS_TABLE_POINTER = nil
  5. AI_ENCOUNTERS = {}
  6.  
  7. function OnScriptLoad()
  8.     AI_ACTORS_TABLE_POINTER = read_dword(sig_scan("8B0D??????0056034134578BF033C0B917") + 2)
  9.     AI_ENCOUNTERS_TABLE_POINTER = read_dword(sig_scan("578B3D??????008B7F3466") + 3)
  10.    
  11.     register_callback(cb['EVENT_GAME_START'], "OnGameStart")
  12.     register_callback(cb['EVENT_COMMAND'], "OnCommand")
  13. end
  14.  
  15. function OnGameStart()
  16.     local scenario_metaid = read_dword(0x40440004)
  17.     local scenario_tag = lookup_tag(scenario_metaid)
  18.     local scenario_data = read_dword(scenario_tag + 0x14)
  19.    
  20.     local ai_encounters_count = read_dword(scenario_data + 0x42C)
  21.     local ai_encounters_data = read_dword(scenario_data + 0x430)
  22.    
  23.     AI_ENCOUNTERS = {}
  24.     for i=0,ai_encounters_count-1 do
  25.         AI_ENCOUNTERS[read_string(ai_encounters_data + i*176)] = i
  26.     end
  27. end
  28.  
  29. function OnCommand(PlayerIndex, Command)
  30.     Command = Command:lower()
  31.     if(Command == "test") then
  32.         set_encounter_team("huntermajor", 13)
  33.         return false
  34.     end
  35. end
  36.  
  37. function set_encounter_team(EncounterName, TeamIndex)
  38.     local encounter_index = AI_ENCOUNTERS[EncounterName]
  39.     if(encounter_index == nil) then
  40.         cprint("Could not find encounter: " .. EncounterName)
  41.         return
  42.     end
  43.    
  44.     local ai_encounter_table = read_dword(AI_ENCOUNTERS_TABLE_POINTER)
  45.     local ai_encounter_table_data = read_dword(ai_encounter_table + 0x34)
  46.    
  47.     local encounter_data = ai_encounter_table_data + encounter_index*108
  48.     write_word(encounter_data + 0x2, TeamIndex)
  49.    
  50.     local ai_actors_table = read_dword(AI_ACTORS_TABLE_POINTER)
  51.    
  52.     local ai_actors_count = read_word(ai_actors_table + 0x2C)
  53.     local ai_actors_data = read_dword(ai_actors_table + 0x34)
  54.     for i=0,ai_actors_count-1 do
  55.         local actor_encounter = read_word(ai_actors_data + i*1828 + 0x34)
  56.         if(actor_encounter == encounter_index) then
  57.             local object_id = read_dword(ai_actors_data + i*1828 + 0x18)
  58.             local object = get_object_memory(object_id)
  59.             if(object ~= 0 and object ~= 0xFFFFFFFF) then
  60.                 write_word(object + 0xB8, TeamIndex)
  61.             end
  62.         end
  63.     end
  64. end
  65.  
  66. function OnScriptUnload() end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top