HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

TransportPreventer

11-20-2009, 03:23 AM#1
grim001
I made this thing at PsycoMarauder's request. It seems too map-specific to submit as a resource, but I figured I'd make it public because some people may find it useful.

Collapse JASS:
library TransportPreventer initializer Init requires AutoIndex, StatusEvents, SimError
//===========================================================================
// Information:
//==============
//
//     This library prevents units from loading into / unloading from
// transports unless they are standing on a specific type of terrain.
// An error message will be displayed if loading / unloading is blocked.
//
//===========================================================================
// Configuration:
//================

globals
    private constant integer AllowedLoadingTerrainType = 1516532850
    private constant integer AllowedUnloadingTerrainType = 1516532850
    //These constants specify the terrain that loading and unloading
    //are allowed from. You can set them to any terrain type. Is is
    //set to Sunken Ruins Rough Dirt by default.
    
    private constant boolean KillUnloadingUnits = true
    //If this is set to true, units forced to unload when a transport
    //dies onto a disallowed terrain type will be killed.
    
    private constant string FailedLoadError = "Units may not be loaded from there."
    private constant string FailedUnloadError = "Units may not be unloaded there."
    //These error messages are displayed when a unit fails to load or unload.
endglobals

//===========================================================================

globals
    private boolean array Blocked
    private real array OldX
    private real array OldY
endglobals

private function OnLoad takes unit transport, unit passenger returns nothing
    local integer id = GetUnitId(passenger)
        if Blocked[id] then
            set Blocked[id] = false
        elseif GetTerrainType(GetUnitX(passenger), GetUnitY(passenger)) != AllowedLoadingTerrainType then
            set Blocked[id] = true
            set OldX[id] = GetUnitX(passenger)
            set OldY[id] = GetUnitY(passenger)
            call IssueTargetOrder(transport, "unload", passenger)
            call SimError(GetOwningPlayer(transport), FailedLoadError)
        endif
endfunction

private function OnUnload takes unit transport, unit passenger returns nothing
    local integer id = GetUnitId(passenger)
        if Blocked[id] then
            set Blocked[id] = false
            call SetUnitX(passenger, OldX[id])
            call SetUnitY(passenger, OldY[id])
        elseif GetTerrainType(GetUnitX(transport), GetUnitY(transport)) != AllowedUnloadingTerrainType then
            if GetWidgetLife(transport) < 0.405 then
                if KillUnloadingUnits then
                    call KillUnit(passenger)
                endif
            else
                set Blocked[id] = true
                call IssueTargetOrder(transport, "load", passenger)
                call SimError(GetOwningPlayer(transport), FailedUnloadError)
            endif
        endif
endfunction

private function Init takes nothing returns nothing
    call OnUnitLoad(OnLoad)
    call OnUnitUnload(OnUnload)
endfunction

endlibrary


A testmap showing that it works pretty seamlessly is attached.
Attached Files
File type: w3xTransportPreventer.w3x (49.6 KB)
11-20-2009, 03:25 AM#2
Rising_Dusk
That is rather map specific. I can't think of a single use for it in anything. :p
11-20-2009, 03:28 AM#3
grim001
Well, you could use a specific terrain type as a "landing pad" area.

More importantly, it demonstrates how to prevent loading/unloading seamlessly, which took a bit of experimentation to figure out.
11-20-2009, 03:45 AM#4
PsycoMarauder
I've noticed that if someone clicks on units inside the transport EXTREMELY quickly, one unit might pop out, but after that, strangely enough, it doesnt seem to happen.

Example Usage: Maps with rolling cliffs as opposed to blizz cliffs that only want ships to unload at ship ports/designated areas.
11-20-2009, 04:05 AM#5
Rising_Dusk
I feel like specifying rects would make more sense than doing it by terrain tile type, but ok.
11-20-2009, 04:13 AM#6
grim001
Quote:
Originally Posted by PsycoMarauder
I've noticed that if someone clicks on units inside the transport EXTREMELY quickly, one unit might pop out, but after that, strangely enough, it doesnt seem to happen.

I've noticed that it behaves a little differently the first time, but I've got no idea what causes it.

Quote:
Originally Posted by Rising_Dusk
I feel like specifying rects would make more sense than doing it by terrain tile type, but ok.

I'm not sure I feel like expanding it into a more general library unless someone actually intends to use it who needs something other than terrain types.
11-20-2009, 04:22 AM#7
Rising_Dusk
Nah, I wouldn't use it, just chattering about what I would've done. No big.
11-20-2009, 05:10 AM#8
PsycoMarauder
Any ideas why when I try to save this now, jasshelper pops up saying unable to find textmacro "optional" ???
11-20-2009, 05:25 AM#9
grim001
You should update your AutoIndex and StatusEvents to the versions included in the testmap or the ones currently in the scripts section. I just did an update tonight. Also try updating JassHelper to the latest version.
11-20-2009, 05:57 AM#10
PsycoMarauder
Did all three, was testing this map and saving it (without changes) using the lastest jasshelper as a test. possibly an AV error.
11-21-2009, 08:56 PM#11
PsycoMarauder
Any ideas why it still wont compile correctly?
11-22-2009, 05:26 AM#12
grim001
"unable to find textmacro optional" is an error I got when using a version of JassHelper that doesn't support optional textmacros. maybe you should double check that you're updating JassHelper correctly. other than that I have no idea.
11-22-2009, 12:48 PM#13
Rising_Dusk
This compiles fine for me. I really think you must be updating JH incorrectly.