OnGoodyHutReward event, what are the parameters?

Discussion in 'Civ6 - Creation & Customization' started by Serp, Feb 20, 2019.

  1. Serp

    Serp King

    Joined:
    Apr 1, 2015
    Messages:
    650
    If you add a function to the GoodyHutReward event and print the params, it looks like this:

    GoodyHutReward 0,131073,-2010932837,-856816033

    The first one is obviuosly the PlayerID, but what could be the other numbers and how to get the amount and reward I got from a goody hut out of those numbers?

    edit:
    The goal is to add a custom side-notification about what a player received from a goody hut.
     
    Last edited: Feb 20, 2019
  2. Cosmic Fox

    Cosmic Fox Civ 6 Addict - TB Mod Collaborator

    Joined:
    Mar 14, 2009
    Messages:
    453
    Gender:
    Male
    Location:
    Las Vegas
    Check Good Goody Huts code for help on this, it works fine with GS update too!
     
  3. Serp

    Serp King

    Joined:
    Apr 1, 2015
    Messages:
    650
    Where should I check code? I already searched all .lua scripts (I do not own GS yet) with help of notepad++ for "goody" and "reward", but nothing found. The event itself is one time used in a tutorial, but no params are used.

    By testing I found out:

    37 gold 0,196608,-2010932837,-2073396856
    37 gold 0,327680,-2010932837,-2073396856
    10 faith 0,196610,-1897648434,313124344
    double heureka 0,393220,-1068790248,1570455183
    single heureka 0,393220,-1068790248,51039867
    new scout 0,393220,1623514478,-945185595
    single inspiration 0,327680,301278043,-1593446804
    new population 0,196610,1892398955,1038837136
    10 faith 0,262147,-1897648434,313124344
    relics 0,327680,301278043,2109989822
    double inspiration 0,327680,301278043,-367235253


    first is the PlayerID, you can get player with Players[PlayerID]
    second is UnitID, you can get the unit with Players[ PlayerID ]:GetUnits():FindID(InitID);
    third may be the RewardID, but how you can find out what? (although inspiration and relics would have same value?!)
    fourth is an ID for the amount, but how to find out more?

    In xml the third and fourht might be called "GoodyHutType" and "SubTypeGoodyHut" ... and these might be in GameInfo... but really no clue how to move on...


    edit:
    or alternatively: does someone know where the game prints the goodyhut reward on screen? Maybe I can catch the goodyhutreward information there, if it is not hardcoded.

    PS: @EnlightendFox: Ah, you meant the mod "good godyhuts". Yes I already know it and improved it for personal use already, but it is only xml, and I'm aksing for lua stuff.
     
    Last edited: Feb 20, 2019
  4. Laurana Kanan

    Laurana Kanan Don’t underestimate who I am. Moderator

    Joined:
    Apr 10, 2014
    Messages:
    3,470
    Gender:
    Female
    Location:
    Near the Greatest Snow on Earth
    Is this what you're looking for:
    Code:
    GameInfo.Improvements["IMPROVEMENT_GOODY_HUT"].Index
    OnImprovementActivated(iX, iY, unitOwner, unitID, improvementType, improvementOwner, activationType)
     
    (A) likes this.
  5. Serp

    Serp King

    Joined:
    Apr 1, 2015
    Messages:
    650
    Thank you for your help :)

    The goal is to add a custom side-notification about what a player received from a goody hut.

    I think your code does not include any information about the reward.
    I'm sure it must be something with GameInfo and the stuff you find in GoodyHuts.xml , but I have no clue how to combine this, to translate those numbers into a goodyhut type string or sth that would help for the custom notification.
     
  6. Infixo

    Infixo Deity

    Joined:
    Jan 9, 2016
    Messages:
    3,830
    Gender:
    Male
    Location:
    Warsaw
    Those big integers are usually hash numbers. These are hard to decipher because they are defined in the DLL. In Lua you usually don’t use them directly but via a pre-defined table like SomePar.PAR1. Try to look through tables in the FireTuner. This is the only place where you can see those tables and hash values.

    Also, if an intereger is within thousands like xxxxxx could also be a unit id or a city id.
     
    (A) likes this.
  7. Serp

    Serp King

    Joined:
    Apr 1, 2015
    Messages:
    650
    Thanks, using Firetuner is indeed easier than adding a print into a script, starting the game, looking at the lua.log, close game, add another print, start game again and so on :D
    But it really sucks that you can not copy sth shown in the lua log,only single words...

    But with help of a for loop I printed what is in GameInfo.GoodyHuts["GOODYHUT_CULTURE"]:
    Spoiler :

    Weight
    100
    GoodyHutType
    GOODYHUT_CULTURE
    ImprovementType
    IMPROVEMENT_GOODY_HUT
    Index
    0
    rowid
    1
    ImprovementReference
    table: 000000003308D100
    PrimaryKey
    GOODYHUT_CULTURE
    Hash
    301278043
    RowId
    1
    SubTypeGoodyHutCollection
    table: 000000003446D4D0

    So we see that the third number of the GoodyHutReward Event is the hash number.
    And it seems with this hash I can also access the same data: GameInfo.GoodyHuts[301278043].

    Okay, so we have the goody hut istelf now. But still missing the SubType.
    Unfortunately GameInfo.GoodyHutSubTypes does not include a hash and GameInfo.GoodyHutSubTypes[2109989822] is nil instead of the relic subtype...
    And the "SubTypeGoodyHutCollection" table only includes the same, so also without a hash.

    Anyone an idea to get this last puzzle piece?

    Is there a way to let Firetuner search for a specific hash in all those tables? that would be perfect :D
     
    Last edited: Feb 20, 2019
  8. Serp

    Serp King

    Joined:
    Apr 1, 2015
    Messages:
    650
    Hm...

    are hashes always the same for everyone? I still find no way to translate the fourth param into the SubType, but if I test every subtype, I will know the hash, eg 2109989822 is always a relic. Or do hashes change?
     
  9. Infixo

    Infixo Deity

    Joined:
    Jan 9, 2016
    Messages:
    3,830
    Gender:
    Male
    Location:
    Warsaw
  10. Serp

    Serp King

    Joined:
    Apr 1, 2015
    Messages:
    650
    ok, tested every goodyhutreward. In case someone else also needs it some day, this is my result, while SubTypeHash is the fourth params of the Event GoodyHutReward:

    Spoiler :

    if SubTypeHash==-856816033 then -- I do not know how to translate this (maybe) SubTypeHash ... GameInfo.GoodyHutSubTypes[SubTypeHash] does not work
    GoodyHutSubType = "GOODYHUT_SMALL_GOLD"
    elseif SubTypeHash==-2073396856 then
    GoodyHutSubType = "GOODYHUT_MEDIUM_GOLD"
    elseif SubTypeHash==725818580 then
    GoodyHutSubType = "GOODYHUT_LARGE_GOLD"
    elseif SubTypeHash==2109989822 then
    GoodyHutSubType = "GOODYHUT_ONE_RELIC"
    elseif SubTypeHash==-367235253 then
    GoodyHutSubType = "GOODYHUT_TWO_CIVIC_BOOSTS"
    elseif SubTypeHash==-1593446804 then
    GoodyHutSubType = "GOODYHUT_ONE_CIVIC_BOOST"
    elseif SubTypeHash==1747194442 then
    GoodyHutSubType = "GOODYHUT_LARGE_FAITH"
    elseif SubTypeHash==173418224 then
    GoodyHutSubType = "GOODYHUT_MEDIUM_FAITH"
    elseif SubTypeHash==313124344 then
    GoodyHutSubType = "GOODYHUT_SMALL_FAITH"
    elseif SubTypeHash==-945185595 then
    GoodyHutSubType = "GOODYHUT_GRANT_SCOUT"
    elseif SubTypeHash==0 then
    GoodyHutSubType = "GOODYHUT_GRANT_UPGRADE"
    elseif SubTypeHash==-897059678 then
    GoodyHutSubType = "GOODYHUT_GRANT_EXPERIENCE"
    elseif SubTypeHash==1721956964 then
    GoodyHutSubType = "GOODYHUT_HEAL"
    elseif SubTypeHash==294222921 then
    GoodyHutSubType = "GOODYHUT_ONE_TECH"
    elseif SubTypeHash==1570455183 then
    GoodyHutSubType = "GOODYHUT_TWO_TECH_BOOSTS"
    elseif SubTypeHash==51039867 then
    GoodyHutSubType = "GOODYHUT_ONE_TECH_BOOST"
    elseif SubTypeHash==1038837136 then
    GoodyHutSubType = "GOODYHUT_ADD_POP"
    elseif SubTypeHash==-317814676 then
    GoodyHutSubType = "GOODYHUT_GRANT_BUILDER"
    elseif SubTypeHash==-2134131563 then
    GoodyHutSubType = "GOODYHUT_GRANT_TRADER"
    elseif SubTypeHash==750739574 then
    GoodyHutSubType = "GOODYHUT_GRANT_SETTLER"
    end

    My "fork" of hellblazers notification mod will include those notifications now:
    https://steamcommunity.com/sharedfiles/filedetails/?id=1528566619
     
    Last edited: Feb 21, 2019
    zzragnar0kzz likes this.
  11. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA
    If an item is listed in table types you can use
    Code:
    function GetHash(t)
    	local r = GameInfo.Types[t];
    	if(r) then
    		return r.Hash;
    	else
    		return 0;
    	end
    end
    to get the matching hash number. the problem is that GoodyHutSubTypes are not registered within table "Types", so they have no "hash" as understood under table "Types", and you cannot index the game-table with a hash most likely because it is a child table. So you have to figure them out the hard way as you've done.

    There's also this method Firaxis has used for unit commands and operations, which does work becauce Unit Commands and Unit Operations are listed as Types in table Types
    Code:
    function GetHashFromType( actionType:string )
    	local hash:number = 0;
    	if GameInfo.UnitCommands[actionType] ~= nil then
    		hash = GameInfo.UnitCommands[actionType].Hash;			
    	elseif GameInfo.UnitOperations[actionType] ~= nil then
    		hash = GameInfo.UnitOperations[actionType].Hash;
    	end
    	return hash;
    end
     
    zzragnar0kzz and Serp like this.
  12. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA
    Code:
    local tGoodySubType_HashToType = { [-856816033] = "GOODYHUT_SMALL_GOLD", [-2073396856] = "GOODYHUT_MEDIUM_GOLD", [725818580] = "GOODYHUT_LARGE_GOLD",
    	[2109989822] = "GOODYHUT_ONE_RELIC", [-367235253] = "GOODYHUT_TWO_CIVIC_BOOSTS", [-1593446804] = "GOODYHUT_ONE_CIVIC_BOOST", [1747194442] = "GOODYHUT_LARGE_FAITH",
    	[173418224] = "GOODYHUT_MEDIUM_FAITH", [313124344] = "GOODYHUT_SMALL_FAITH", [-945185595] = "GOODYHUT_GRANT_SCOUT", [0] = "GOODYHUT_GRANT_UPGRADE",
    	[-897059678] = "GOODYHUT_GRANT_EXPERIENCE", [1721956964] = "GOODYHUT_HEAL", [294222921] = "GOODYHUT_ONE_TECH", [1570455183] = "GOODYHUT_TWO_TECH_BOOSTS",
    	[51039867] = "GOODYHUT_ONE_TECH_BOOST", [1038837136] = "GOODYHUT_ADD_POP", [-317814676] = "GOODYHUT_GRANT_BUILDER", [-2134131563] = "GOODYHUT_GRANT_TRADER",
    	[750739574] = "GOODYHUT_GRANT_SETTLER" }
    
    --example use of table
    local GoodyHutSubType
    if tGoodySubType_HashToType[SubTypeHash] then
    	GoodyHutSubType = tGoodySubType_HashToType[SubTypeHash]
    end
    You can define the table once in your code and then refer to it as many times as necessary without having to type all those "elseif" clauses again.

    And if Firaxis ever adds a new Goody Hut subtype, you just add that new info to the table without needing to alter the remainder of your code.
     
    zzragnar0kzz and Serp like this.
  13. Serp

    Serp King

    Joined:
    Apr 1, 2015
    Messages:
    650
    thx, this is a good idea, will add it in next update.

    It seems GS also introduced new goody hut rewards? At least someone reported, that my mod showed "code speak", which should only happen if my mod does not know the hash.
    Currently waiting for more reports, since in this case the hash is printed in lua.log, so if someone reports this hash with addition of the rewards, I can add it...
     
  14. LeeS

    LeeS Imperator

    Joined:
    Jul 23, 2013
    Messages:
    7,241
    Location:
    Illinois, USA
    Also, if you open the actual lua.log file with Notepad, Notepad++, etc, you can copy as much of what is in the log as you desire, and paste it into a new text-only file you create in Notepad, Notepad++, etc.

    You can do so while the game is running or after you finish your game-session so long as you do not start Civ6 again. The lua.log like the database.log is preserved in the logs folder until you start the game again.
     
  15. Serp

    Serp King

    Joined:
    Apr 1, 2015
    Messages:
    650
    yes I know, thx. I was talking about the lua log from firetuner, which does not allow copy paste. So firetuner is as infixo said mostly better for debugging than the lua.log file, but not if you have to copy paste sth.
     
  16. zzragnar0kzz

    zzragnar0kzz Chieftain

    Joined:
    May 2, 2021
    Messages:
    11
    Apologies for the necro-post, but this thread was highly instrumental in my recent endeavor. For anyone else who winds up in this thread after a search, the info provided here is still good, 2+ years later. Gathering Storm added a few new rewards, which can be incorporated into the table above as follows:

    [-842336157] = "GOODYHUT_FAVOR"
    [1171999597] = "GOODYHUT_ENVOY"
    [-1140666915] = "GOODYHUT_GOVERNOR_TITLE"
    [-1085383998] = "GOODYHUT_RESOURCES"
     
  17. Gedemon

    Gedemon Modder Super Moderator

    Joined:
    Oct 4, 2004
    Messages:
    10,019
    Location:
    France
    For reference, if you need the hash of something, you can use this in Lua/Firetuner
    Code:
    DB.MakeHash("GOODYHUT_RESOURCES")
     
    zzragnar0kzz likes this.
  18. zzragnar0kzz

    zzragnar0kzz Chieftain

    Joined:
    May 2, 2021
    Messages:
    11
    So, if I'm following you correctly, this basic table could be constructed by iterating over GameInfo.GoodyHutSubTypes, with something like:

    Code:
    local tGoodySubType_HashToType = {}
    for row in GameInfo.GoodyHutSubTypes() do
        tGoodySubType_HashToType[DB.MakeHash(row.SubTypeGoodyHut)] = row.SubTypeGoodyHut
    end
    
    Is that accurate?
     
  19. Gedemon

    Gedemon Modder Super Moderator

    Joined:
    Oct 4, 2004
    Messages:
    10,019
    Location:
    France
    should be
     
  20. zzragnar0kzz

    zzragnar0kzz Chieftain

    Joined:
    May 2, 2021
    Messages:
    11
    And indeed, it is. This is a very nifty trick. Gonna turn my big stupid table into a big dynamic and smart table. Thank you!

    Is there an inverse function to DB.MakeHash? I had a hash value that I couldn't quite peg until just now, and having a way to feed it 1419298788 and receive METEOR_GRANT_GOODIES back as the result would have been useful.
     

Share This Page