Janne252 / coh3-scar-types

Type definitions for developing CoH3 SCAR scripts in VS Code with extension "sumneko.lua"
1 stars 2 forks source link

Squad_Precache() / Misc_GetMouseOnTerrain() #1

Closed sw5163 closed 3 months ago

sw5163 commented 3 months ago

Hi Janne252, Much love your CheatCommands Mod!

Squad_Precache() will solve the red box issue:

ResourceContainer_CreateCache("g_cheat_cache", 256)
Squad_Precache(BP_GetSquadBlueprint("unit_villager_1_eng"),0,Game_GetLocalPlayer(),"g_cheat_cache",0,0)
Entity_Precache(BP_GetEntityBlueprint("holy_site"),0,Game_GetLocalPlayer(),"g_cheat_cache",0,0)

Also do you have any idea why Misc_GetMouseOnTerrain() doesn't work? I assume you are using Camera_GetPivot() instead.

Janne252 commented 3 months ago

Thanks, I haven't looked into programmatic "pre-caching" models from other factions. This could indeed work as on-demand "pre-caching".

Also do you have any idea why Misc_GetMouseOnTerrain() doesn't work? I assume you are using Camera_GetPivot() instead.

No idea. CheatCommands Mod currently uses a bit hacky approach to get the actual camera target position:

function Camera_GetTargetPositionCenter()
    -- Camera_GetCurrentTargetPos / Camera_GetTargetPos / Camera_GetCurrentPos are weird; not screen-centered like in CoH2
    local pos = Pos_OnTerrain(Camera_GetTargetPos())
    local target = Pos_OnTerrain(Camera_GetCurrentTargetPos())

    return Pos_GetOffsetPositionTowards(pos, target, (World_DistancePointToPoint(pos, target) / 2), true)
end

It's probably a dirty estimation but it has worked well enough so far 😅

sw5163 commented 3 months ago

No idea. CheatCommands Mod currently uses a bit hacky approach to get the actual camera target position:

From my test, Camera_GetPivot() returns the screen center pos. I wonder if there's a way to check the source code of Misc_GetMouseOnTerrain() 🤔

Janne252 commented 3 months ago

From my test, Camera_GetPivot() returns the screen center pos.

Thanks, I may have originally ignored Camera_GetPivot due to its name. Having not read the SCARDOC I must have assumed it's related to getting one of the rotation axis.

I wonder if there's a way to check the source code of Misc_GetMouseOnTerrain() 🤔

Searching across all of the game's SCAR/lua files for occurrences of Misc_GetMouseOnTerrain indicates that it's related to internal testing / "cheat menu". Perhaps it requires -dev mode or somthing similar 🤔

sw5163 commented 3 months ago

Searching across all of the game's SCAR/lua files for occurrences of Misc_GetMouseOnTerrain indicates that it's related to internal testing / "cheat menu". Perhaps it requires -dev mode or somthing similar 🤔

I am in -dev mode, it always return (0,0,0) both in COH3 and AOE4, seems broken. And I've just checked the cheatmenu.lua, its source code not in there.

Looks like your camera target hack is the simplest way to get a spawn point until there's a way to fix Misc_GetMouseOnTerrain(), thanks! 🙂