How to create a unit before GUI preplaced units are initialized?

Status
Not open for further replies.
Kind of a tricky question, but I could imagine this having a pretty simple solution:

What I want is to create a unit via Jass before preplaced units are generated on the map script.

Since the order of abilities displayed in the spellbook is determined by the order in which these abilities get first loaded into the game, I can manually arrange these abilities by just preloading them in a certain order on map init.

However, as I have lots of preplaced units on the map with certain abilities assigned to them in the object editor, things get messed up if I try to establish this order after these units get initialized.

So my solution is to just create a dummy unit before all preplaced units are generated and cycle through the list of abilities, adding/removing them one by one.

Is there a quick and easy way to do that? Do I need to actually inject code or can I abuse struct/module/library initializers for that?


EDIT: I tested it with a library initializer and it seems that library initializers run after preplaced units. So I need to inject into main() to do this?
 
Last edited:
The problem is that this tutorial raises more questions than it answers. I don't know how the original main() looks like, so I don't know how to inject a custom function into the main() without messing up anything else.

Can someone give me an example on how to inject a function call into main() before units are placed without changing anything else there?
When I do this:
JASS:
//! inject main
     call ExecuteFunc("SetupAbilLists")
     //! dovjassinit
//! endinject
It messes up the entire map (the camera bounds are not set correctly, for example). The function I called there works fine and shows the debug message I put in correctly, but it seems like the rest of main() gets messed up.

This does not work aswell:
JASS:
//! inject main
     call ExecuteFunc("SetupAbilLists")

     //! dovjassinit

     // These initialize preplaced objects in the editor
     call CreateRegions()
     call CreateCameras()
     //call CreateAllItems() ... I had to comment this out as it threw me a syntax error that it could not find this function...
     //this is probably because I don't have any preplaced items?
     call CreateAllUnits()

     // call (non-vjass) custom triggers initialization functions
     call InitCustomTriggers()
//! endinject
...which was the example given in the tutorial.
 
Last edited:
Nobody who can help with this? I have the function ready and just need to know how to inject into main() without breaking the map...

EDIT: Nevermind. I just extracted the compiled .j file and found the main function in there to replicate. It's a bummer that inject doesn't work the way you expect it (by actually injecting code instead of completely replacing the original function).
 
Last edited:
Have never tried to inject myself, but I also seem to have cam problems when copy your code.
Maybe we can find some more info somewhere.

Edit:

Try
JASS:
function A takes nothing returns nothing
    call BJDebugMsg("A")
endfunction

//! inject main
    
    call ExecuteFunc("A")
    //! dovjassinit
    
    call SetCameraBounds(-3328.0+GetCameraMargin(CAMERA_MARGIN_LEFT),-3584.0+GetCameraMargin(CAMERA_MARGIN_BOTTOM),3328.0-GetCameraMargin(CAMERA_MARGIN_RIGHT),3072.0-GetCameraMargin(CAMERA_MARGIN_TOP),-3328.0+GetCameraMargin(CAMERA_MARGIN_LEFT),3072.0-GetCameraMargin(CAMERA_MARGIN_TOP),3328.0-GetCameraMargin(CAMERA_MARGIN_RIGHT),-3584.0+GetCameraMargin(CAMERA_MARGIN_BOTTOM))
	call SetDayNightModels("Environment\\DNC\\DNCLordaeron\\DNCLordaeronTerrain\\DNCLordaeronTerrain.mdl","Environment\\DNC\\DNCLordaeron\\DNCLordaeronUnit\\DNCLordaeronUnit.mdl")
	call NewSoundEnvironment("Default")
	call SetAmbientDaySound("LordaeronSummerDay")
	call SetAmbientNightSound("LordaeronSummerNight")
	call SetMapMusic("Music",true,0)
	call InitBlizzard()
	call InitGlobals()
    
    call CreateRegions()
    call CreateCameras()
    call CreateAllItems()
    call CreateAllUnits()

    // call InitTrig's
    call InitCustomTriggers()

//! endinject
 
Have never tried to inject myself, but I also seem to have cam problems when copy your code.
Maybe we can find some more info somewhere.

Edit:

Try
JASS:
function A takes nothing returns nothing
    call BJDebugMsg("A")
endfunction

//! inject main
    
    call ExecuteFunc("A")
    //! dovjassinit
    
    call SetCameraBounds(-3328.0+GetCameraMargin(CAMERA_MARGIN_LEFT),-3584.0+GetCameraMargin(CAMERA_MARGIN_BOTTOM),3328.0-GetCameraMargin(CAMERA_MARGIN_RIGHT),3072.0-GetCameraMargin(CAMERA_MARGIN_TOP),-3328.0+GetCameraMargin(CAMERA_MARGIN_LEFT),3072.0-GetCameraMargin(CAMERA_MARGIN_TOP),3328.0-GetCameraMargin(CAMERA_MARGIN_RIGHT),-3584.0+GetCameraMargin(CAMERA_MARGIN_BOTTOM))
	call SetDayNightModels("Environment\\DNC\\DNCLordaeron\\DNCLordaeronTerrain\\DNCLordaeronTerrain.mdl","Environment\\DNC\\DNCLordaeron\\DNCLordaeronUnit\\DNCLordaeronUnit.mdl")
	call NewSoundEnvironment("Default")
	call SetAmbientDaySound("LordaeronSummerDay")
	call SetAmbientNightSound("LordaeronSummerNight")
	call SetMapMusic("Music",true,0)
	call InitBlizzard()
	call InitGlobals()
    
    call CreateRegions()
    call CreateCameras()
    call CreateAllItems()
    call CreateAllUnits()

    // call InitTrig's
    call InitCustomTriggers()

//! endinject
Yeah I solved it already by checking out how the main() was constructed in the .j file and just added the missing function calls in the inject.

It's working now and the spellbooks now finally work as intended. Awesomesauce!
 
Status
Not open for further replies.
Top