• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Snippet] WidgetType

Level 7
Joined
Apr 30, 2011
Messages
359
JASS:
//========================================================================================
//      
//      Widget Type
//      -*- overcold_ice -*-
//      
//     -[*] Requirements:
//          - JNGP
//          - latest version of JassHelper
//      
//     -[*] Optional Requirements:
//          - ObjectMerger script: LUA_GET_VAR_OBJECT       [url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-lua_get_var_object-185944/[/url]
//      
//          For your additional WidgetType needs
//      This system provides additional IsWidgetType checker functions, primarily ones
//      that the natives haven't have. Included: IsWidgetBridge, IsWidgetTree, and
//      IsWidgetWard. You can add more types, and they can be a dynamic one.
//      
//     -[*] Note:
//          - Doesn't support player-related checks (enemy, ally, friend, etc)
//      
//     -[*] API:
//      
//      function IsWidget$TYPE$ takes widget w returns boolean
//          returns true if widget(w) is targeted as $TYPE$
//          this uses an ability to check the widget
//      
//      $TYPE$:
//          - Bridge
//          - Tree
//          - Ward
//      
//     -[*] ObjectMerger Script
/*
//! externalblock extension=lua ObjectMerger $FILENAME$
    //====================================================================================
    //  C A L I B R A T I O N   S E C T I O N
    //====================================================================================
    
    //  Level of the ability
    //  higher level will enable more detections
    //! i local LEVEL = "3"
    
    //  Detections in a level
    //  you can have as many detections in a single level
    //  number inside those '[ ]' represents the ability level
    //! i local DETECT = {}
    
    //! i local DETECT [1] = "bridge"
    //! i local DETECT [2] = "tree"
    //! i local DETECT [3] = "ward"
    //====================================================================================
    
    //! runtextmacro LUA_FILE_HEADER()
    //! i dofile("GetVarObject")
    
    //! i local id = getvarobject("Afod", "abilities", "WIDGET_TYPE_CHECKER_ID", true)
    //! i createobject("Afod", id)
    
    //! i makechange(current, "abpx", "0")
    //! i makechange(current, "abpy", "0")
    //! i makechange(current, "aart", "ReplaceableTextures\\WorldEditUI\\DoodadPlaceholder.blp")
    //! i makechange(current, "alig", "")
    //! i makechange(current, "atat", "")
    //! i makechange(current, "alev", LEVEL)
    //! i makechange(current, "arac", "unknown")
    //! i makechange(current, "ansf", "")
    //! i makechange(current, "ahky", "")
    //! i makechange(current, "anam", "Widget Type Checker")
    //! i makechange(current, "Nfd1", "1", "0")
    //! i makechange(current, "Nfd2", "1", "0")
    //! i makechange(current, "Nfd3", "1", "0")
    //! i makechange(current, "acdn", "1", "0")
    //! i makechange(current, "atp1", "1", "")
    //! i makechange(current, "aub1", "1", "")
    
    //! i for i=1, LEVEL do
        //! i makechange(current, "aran", i, "99999")
        //! i makechange(current, "atar", i, DETECT [i])
    //! i end
    
    //! i updateobjects()
//! endexternalblock
*/
//========================================================================================
library WidgetType
    
    //====================================================================================
    //  C A L I B R A T I O N   S E C T I O N
    //====================================================================================
    globals
        //  your dummy unit's rawcode
        private constant integer DUMMY_ID           = 'dumy'
        //  widget checker ability's rawcode
        private constant integer ABILITY_CHECKER_ID = 'wtcs'
        
        //  variables related to the ability's level
        //  and especially the functions itself
        //  (see textmacros at the bottom of this script)
        private constant integer BRIDGE             = 1
        private constant integer TREE               = 2
        private constant integer WARD               = 3
    endglobals
    //====================================================================================
    
    globals
        private unit dummy
    endglobals
    
    //====================================================================================
    //  A P I
    //====================================================================================
    //! textmacro WidgetType___MakeAPI takes NAME, VAR        
        function IsWidget$NAME$ takes widget w returns boolean
            call SetUnitAbilityLevel(dummy, ABILITY_CHECKER_ID, $VAR$)
            
            return IssueTargetOrder(dummy, "fingerofdeath", w) and IssueImmediateOrder(dummy, "stop")
        endfunction
    //! endtextmacro
    
    //  Results
    //      Name                : IsWidget$xXXXXx$
    //      Variable Used       :                   $xXXx$
    //! runtextmacro WidgetType___MakeAPI("Bridge", "BRIDGE")
    //! runtextmacro WidgetType___MakeAPI(  "Tree", "TREE")
    //! runtextmacro WidgetType___MakeAPI(  "Ward", "WARD")
    //====================================================================================
    
    private module InitM
        private static method onInit takes nothing returns nothing
            set dummy = CreateUnit(Player(15), DUMMY_ID, 0, 0, 0)
            call UnitAddAbility(dummy, ABILITY_CHECKER_ID)
        endmethod
    endmodule
    
    private struct InitS
        implement InitM
    endstruct
endlibrary
 

Attachments

  • Widget Type Checker.w3x
    19.5 KB · Views: 57
Last edited:

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
The most useful one is for checking if a widget is "bridge" because then you can filter out bridges from being destroyed by "pick all destructables in rect".

Everything else you can already check using other means.

I recommend shortening this resource to be called "IsDestructableBridge". I would definitely approve it provided that it works, because that would be really good.

Also, keep in mind that abilities over 4 levels can't be converted to .slk files and will make your map size way bigger.
 
This is actually an awesome system idea :eek:

In my opinion, Bridge, ward, organic, mechanical and tree are the best ;)
Maybe you can call this WidgetType, and make 5 different libraries containing modules for it :O
Then, in the system, you'd have nothing but optional module imports that also generate the required objects :D

For tree, you could use this:

JASS:
function IsWidgetTree takes widget w returns boolean
    return IssueTargetOrderById(DUMMY, ORDER_eattree, w) and IssueImmediateOrderById(DUMMY, ORDER_stop)
endfunction

This is a very intelligent way to detect trees ;)

edit
Also, it would be better if you use several abilities rather than one with 29 levels :O (or 5 in this case)

This way, your textmacro would look like this:

JASS:
//! textmacro WidgetType__func takes name, orderId
    function IsWidget$name$ takes widget w returns boolean
        return IssueTargetOrderById(DUMMY, $orderId$, w) and IssueImmediateOrderById(DUMMY, ORDER_stop)
    endfunction
//! endtextmacro

Isn't that epic? : D
It'll inline ^.^
 
Level 4
Joined
Jun 9, 2011
Messages
91
my suggestion:
JASS:
//! textmacro WidgetType___MakeAPI takes NAME, VAR
	function IsWidget$NAME$ takes widget w returns boolean
		call SetUnitOwner(DUMMY, Player(15), false)
		call SetUnitAbilityLevel(DUMMY, ABILITY_CHECKER_ID, $VAR$)
		if IssueTargetOrder(DUMMY, "fingerofdeath", w) then
			return IssueImmediateOrder(DUMMY, "stop")
		endif
		return false
	endfunction
//! endtextmacro
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,468
JASS:
    //The following highlighted doesn't belong in this library:
    @function IsWidgetDead takes widget w returns boolean
        return GetWidgetLife(w) <= 0
    endfunction
    function IsWidgetAlive takes widget w returns boolean
        return not IsWidgetDead(w)
    endfunction
    function IsUnitDead takes unit u returns boolean
        return IsUnitType(u, UNIT_TYPE_DEAD) and GetUnitTypeId(u) == 0@
        //You did this check wrong, too, IsUnitAlive should be the main function
        //here, and it should be "not IsUnitType and GetUnitTypeId != 0"
    @endfunction
    function IsUnitAlive takes unit u returns boolean
        return not IsUnitDead(u)
    endfunction@
    
    //This needs to be a module initializer:
    private function Init takes nothing returns nothing
        call UnitAddAbility(DUMMY, ABILITY_CHECKER_ID)
    endfunction
 
Level 7
Joined
Apr 30, 2011
Messages
359
ready for approval i guess :)
fixed the code . . .
+ IsWidget$TYPE$FromPlayer -> for checks that requires player (enemy, ally, etc)
+ attached map
 
Level 7
Joined
Apr 30, 2011
Messages
359
big prob >.< !!!!!!!

the system doesn't work for Unit that targeted as bridge/tree
they will return that they are wards
but works on ward . . .
this is a confusing thing to think ~.~

and i added invulnerable + vulnerable to the allowed targets (solve many things)
changed base ability to channel, with Universal Spell mode (ignores spell immunity)

edit: added the map (BETA)
 

Attachments

  • Widget Type Checker.w3x
    28.9 KB · Views: 89
Top