[Log in / Register]
| News | Chat | Pastebin | Donations | Tutorials | Rules | Forums |
| Maps | Skins | Icons | Models | Spells | Tools | Jass | Packs | Hosted Projects | Starcraft II Modding | Starcraft II Resources | Galaxy Wiki |
(Keeps Hive Alive)
Go Back   The Hive Workshop > Warcraft III Modding > JASS Resources > Submissions > "Graveyard"


"Graveyard" Resources which were not approved are moved to this section.

 
 
Thread Tools
Old 02-24-2010, 07:45 PM   #1 (permalink)
Registered User Freyleyes
Gota stop 'em all
 
Freyleyes's Avatar
 
Join Date: Jun 2008
Posts: 781
Freyleyes is just really nice (371)Freyleyes is just really nice (371)Freyleyes is just really nice (371)Freyleyes is just really nice (371)
IsUnitMoving()

This is a little code snippet I created for a map I am creating. I could not find a working one anywhere.

Description :

This little piece of code checks if a unit is moving.

Requires :
  • JNGP

Show Code

Jass:
library IsUnitMoving initializer init

globals

    private group   CHECKUNITS  = CreateGroup()
    private trigger MAINTRIGGER = CreateTrigger()
    private integer counter     = 0
    MoveData array ARRMove

endglobals

struct MoveData

    unit witchunit = null
    real cX        = 0
    real cY        = 0
    real nX        = 0
    real nY        = 0
    boolean moving = false

endstruct

private function GetIndex takes unit u returns integer

    local integer i = 0
   
    loop
   
        set i = i + 1
       
            if ARRMove[i].witchunit == u then
                return i
            endif
       
        exitwhen i == counter
   
    endloop

    return 0
   
endfunction

function IsUnitMoving takes unit u returns boolean

    local integer i = GetIndex(u)

    return ARRMove[i].moving

endfunction

private function EnumUnits takes nothing returns nothing

    local integer i = GetIndex(GetEnumUnit())
   
    set ARRMove[i].cX = GetUnitX(GetEnumUnit())
    set ARRMove[i].cY = GetUnitY(GetEnumUnit())
   
    if (ARRMove[i].cX == ARRMove[i].nX) and (ARRMove[i].cY == ARRMove[i].nY) then
        set ARRMove[i].moving = false
    else
        set ARRMove[i].moving = true
    endif
   
    set ARRMove[i].nX = GetUnitX(GetEnumUnit())
    set ARRMove[i].nY = GetUnitY(GetEnumUnit())

endfunction

private function onLoop takes nothing returns nothing

    call ForGroup(CHECKUNITS, function EnumUnits)

endfunction

function AddUnit takes unit u returns nothing

    set counter = counter + 1
    set ARRMove[counter] = MoveData.create()
    set ARRMove[counter].witchunit = u
    set ARRMove[counter].cX = GetUnitX(u)
    set ARRMove[counter].cY = GetUnitY(u)
   
    call GroupAddUnit(CHECKUNITS, u)

endfunction

private function init takes nothing returns nothing

    call TriggerRegisterTimerEvent(MAINTRIGGER, 0.05, true)
    call TriggerAddAction(MAINTRIGGER, function onLoop)

endfunction

endlibrary


Use
Jass:
AddUnit(WichUnit)
to add a unit to the check list and use
Jass:
IsUnitMoving( unit WitchUnit)
to check if that unit is moving.
__________________
Freyleyes is offline  
Old 02-25-2010, 10:11 AM   #2 (permalink)
Registered User Anachron
Hello old friend.
 
Anachron's Avatar
 
Join Date: Sep 2007
Posts: 6,392
Anachron has much of which to be proud (1083)Anachron has much of which to be proud (1083)Anachron has much of which to be proud (1083)Anachron has much of which to be proud (1083)Anachron has much of which to be proud (1083)
Hosted Project of the Year - 2009: Diablo III Warcraft 
You don't need a timer at all.
Just register order issues, and change boolean on event.
Anachron is offline  
Old 02-25-2010, 08:06 PM   #3 (permalink)
Registered User TriggerHappy
 
TriggerHappy's Avatar
 
Join Date: Jun 2007
Posts: 1,269
TriggerHappy is a name known to all (736)TriggerHappy is a name known to all (736)TriggerHappy is a name known to all (736)TriggerHappy is a name known to all (736)TriggerHappy is a name known to all (736)
PayPal Donor: This user has donated at least $20 to The Hive. Zephyr Challenge #6 - Winner: Dune Worm 
I'm sorry, this cannot be approved.
  • You use O(n) searches which are very slow and are limited to 8190 registered units.
  • Like Anachron said, you could just trigger order events.
  • The fact you even need to register units is lame.
  • You don't even have recycling.
  • You're calling GetEnumUnit() five times when you could just store it in a local.
  • "AddUnit" is a to generic name.
  • What's the point of using the timer event? Why not just use a timer?
  • The struct should be private.
  • You could inline IsUnitMoving.
__________________
Quote Database *Updated*
Chatroom
TriggerHappy is offline  
Old 02-26-2010, 02:24 AM   #4 (permalink)
Forum Moderator PurgeandFire
ʕ•͡ᴥ•ʔ
 
PurgeandFire's Avatar
Resource & Tutorial Moderator
 
Join Date: Nov 2006
Posts: 3,664
PurgeandFire has much of which to be proud (1144)PurgeandFire has much of which to be proud (1144)PurgeandFire has much of which to be proud (1144)PurgeandFire has much of which to be proud (1144)PurgeandFire has much of which to be proud (1144)PurgeandFire has much of which to be proud (1144)PurgeandFire has much of which to be proud (1144)
You could just register order events, but that wouldn't detect SetUnitX/SetUnitY.

EDIT: Although you could probably just hook SetUnitX/SetUnitY/SetUnitPosition and set the boolean to true. The rest you could probably just register the order events.
EDIT2: Then again, you also need to know when the SetUnitXY/Pos stops. =P
PurgeandFire is offline  
Old 02-26-2010, 06:17 AM   #5 (permalink)
Registered User Anachron
Hello old friend.
 
Anachron's Avatar
 
Join Date: Sep 2007
Posts: 6,392
Anachron has much of which to be proud (1083)Anachron has much of which to be proud (1083)Anachron has much of which to be proud (1083)Anachron has much of which to be proud (1083)Anachron has much of which to be proud (1083)
Hosted Project of the Year - 2009: Diablo III Warcraft 
Yes, additionally hook the SetUnitX/SetUnitY() natives and then use a timer with the delay of how long the unit is counted as being moved.
Anachron is offline  
Old 02-26-2010, 10:07 PM   #6 (permalink)
Registered User azlier
aзлиэр - уофлиян
 
azlier's Avatar
 
Join Date: Oct 2008
Posts: 349
azlier is a jewel in the rough (150)
Please... never hook SetUnitX/Y. Those have to be, like, the most frequently called natives ever.

Hooking those makes projectile systems and the like much slower. I prefer manual registry.

Needs fixing.
azlier is offline  
Old 02-27-2010, 03:18 PM   #7 (permalink)
Registered User Anachron
Hello old friend.
 
Anachron's Avatar
 
Join Date: Sep 2007
Posts: 6,392
Anachron has much of which to be proud (1083)Anachron has much of which to be proud (1083)Anachron has much of which to be proud (1083)Anachron has much of which to be proud (1083)Anachron has much of which to be proud (1083)
Hosted Project of the Year - 2009: Diablo III Warcraft 
Oh yes, didn't thought of the high usage in such systems.
Anachron is offline  
Old 03-01-2010, 06:33 PM   #8 (permalink)
Registered User Freyleyes
Gota stop 'em all
 
Freyleyes's Avatar
 
Join Date: Jun 2008
Posts: 781
Freyleyes is just really nice (371)Freyleyes is just really nice (371)Freyleyes is just really nice (371)Freyleyes is just really nice (371)
I will update the Script asap. I am reality new at using vJass and don't really understand every thing yet. Thanks for the feedback, will try to make it right :D
__________________
Freyleyes is offline  
Old 03-12-2010, 05:41 PM   #9 (permalink)
Registered User TriggerHappy
 
TriggerHappy's Avatar
 
Join Date: Jun 2007
Posts: 1,269
TriggerHappy is a name known to all (736)TriggerHappy is a name known to all (736)TriggerHappy is a name known to all (736)TriggerHappy is a name known to all (736)TriggerHappy is a name known to all (736)
PayPal Donor: This user has donated at least $20 to The Hive. Zephyr Challenge #6 - Winner: Dune Worm 
It's been nearly two weeks so I am going to graveyard this. Send me a message when/if you're ready to revive it.
__________________
Quote Database *Updated*
Chatroom
TriggerHappy is offline  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 11:05 PM.





Powered by vBulletin
Copyright 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.5.1 PL2
Copyright © Ralle