// Credit to Deaod, edited by Maker
private function CreateUnitWithoutShadow takes player owner, integer uid, real facing, string shadowfile returns unit
local image i = CreateImage(shadowfile, 1, 1, 0, 0, 0, 0, 1, 1, 0, 3) // creates a dummy image
if GetHandleId(i) == -1 then // if the new shadow is invalid, abort, it can screw up the game
debug call BJDebugMsg("CreateUnitWithShadow: Invalid path for new shadow!") // it could also be caused by an imageType of 0, but thats a less common cause
return null // since the image is invalid, we dont need to destroy it
endif
call DestroyImage(i) // destroy the dummy.
set u = CreateUnit(owner, uid, CREATE_X, CREATE_Y, facing) // create the unit. this also creates a new image which functions as the shadow of the unit. The shadow will use the ID of the dummy image.
call DestroyImage(i) // destroy the shadow of the unit
call CreateImage(shadowfile, 1, 1, 0, 0, 0, 0, 1, 1, 0, 3) // this creates the new shadow for the unit, note that i dont need to overwrite "i" as the id this image will get is predictable
call SetImageRenderAlways(i, false) // Hides the shadow
call SetImageColor(i, 0, 0, 0, 0) // Makes the shadow invisible
// no need to null "i", as images dont use ref-counting
return u
endfunction