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

JASS Functions Approved JASS functions will be located here.
Remember to submit your own resources to the submission forum.

Reply
 
LinkBack Thread Tools
Old 08-02-2009, 12:16 AM   #1 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 588
YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)
Spawn and Movement System

pew pew. A very neat update in my opinion. I again rewrote the whole system to archieve even more configurability and ease the working with it.

It now features 2 struct types, one is called lane and the other is called spawn.
The lane is obviously the way a spawn moves, which still uses rects. (Since you can easily move them within the editor)
A spawn contains the data to spawn units. Each spawn requires one lane, one owner (a player), one unit type, an amount and an interval.

This features in-game changes of everything, means you can replace (or change) the lane, the player, the unit type, the amount and even the interval while the game is running.

You can also get the revertion of any lane (pretty useful for AoS maps, you just have to create half the lanes and get the reversed ones)

The functions featured are:
  • Lane:
    •     method registerWaypoint takes rect returns nothing
          method getWaypoint takes integer returns rect
          method getWaypointX takes integer returns real
          method getWaypointY takes integer returns real
          method getWaypointCount takes nothing returns integer
          method getReversed takes nothing returns Lane
          method list takes nothing returns nothing
  • Spawn:
    •     static method create takes Lane, player, integer id, integer amount, real time returns thistype
          method startSpawn takes nothing returns nothing
          method pauseSpawn takes nothing returns nothing
          method setSpawningUnit takes integer id returns nothing
          method setSpawnCount takes integer amount returns nothing
          method setOwner takes player returns nothing
          method setLane takes Lane returns nothing
          method setInterval takes real returns nothing


Enough talked, let's come to the code:
Code
library SpawnAndMove

    globals
        //Which order get's issued to spawned units
        public string ISSUED_ORDER = "attack"
        //Distance to check if the unit is near his next waypoint (Set this higher if your rects are big)
        private constant real CHECK_DISTANCE = 500.

        //Do NOT change
        private hashtable hash
    endglobals

    struct Lane
        private integer waypointCount = 0

        method registerWaypoint takes rect r returns nothing
            call SaveRectHandle(hash, this, this.waypointCount, r)
            set this.waypointCount = this.waypointCount + 1
        endmethod

        method getWaypoint takes integer index returns rect
            return LoadRectHandle(hash, this, index)
        endmethod

        method getWaypointX takes integer index returns real
            return GetRectCenterX(LoadRectHandle(hash, this, index))
        endmethod

        method getWaypointY takes integer index returns real
            return GetRectCenterY(LoadRectHandle(hash, this, index))
        endmethod

        method getWaypointCount takes nothing returns integer
            return this.waypointCount
        endmethod

        method getReversed takes nothing returns thistype
            local thistype reversed = thistype.allocate()
            local integer i = this.waypointCount-1

            loop
                call reversed.registerWaypoint(this.getWaypoint(i))

                set i = i-1
                exitwhen i < 0
            endloop

            return reversed
        endmethod

        method list takes nothing returns nothing
            local integer i = 0

            loop
                call BJDebugMsg("Rect in Pos: " + I2S(i))

                call BJDebugMsg("---")

                call BJDebugMsg("X: " + I2S(R2I(this.getWaypointX(i))))
                call BJDebugMsg("X: " + I2S(R2I(this.getWaypointY(i))))

                set i = i + 1
                exitwhen i >= this.waypointCount
            endloop
        endmethod

        private method onDestroy takes nothing returns nothing
            call FlushChildHashtable(hash, this)
        endmethod
    endstruct


    struct Spawn
        private player owner
        private integer spawned
        private integer spawnCount
        private real interval

        private Lane lane

        private timer t


        private static trigger onEnter
        private region waypoint

        private static method onInit takes nothing returns nothing
            set hash = InitHashtable()
            set thistype.onEnter = CreateTrigger()
        endmethod

        private static method enter takes nothing returns boolean
            local thistype this
            local integer cur

            local unit u = GetFilterUnit()

            if HaveSavedInteger(hash, GetHandleId(u), 0) then
                set this = LoadInteger(hash, GetHandleId(u), 1)
                set cur = LoadInteger(hash, GetHandleId(u), 0)

                if IsUnitInRangeXY(u, LoadReal(hash, GetHandleId(u), 2), LoadReal(hash, GetHandleId(u), 3), CHECK_DISTANCE) then
                    set cur = cur + 1

                    if cur >= this.lane.getWaypointCount() then
                        call FlushChildHashtable(hash, GetHandleId(u))
                        return false
                    endif

                    call SaveInteger(hash, GetHandleId(u), 0, cur)

                    call SaveReal(hash, GetHandleId(u), 2, this.lane.getWaypointX(cur))
                    call SaveReal(hash, GetHandleId(u), 3, this.lane.getWaypointY(cur))

                    call IssuePointOrder(u, ISSUED_ORDER, this.lane.getWaypointX(cur), this.lane.getWaypointY(cur))
                endif
            endif

            set u = null

            return false
        endmethod

        static method create takes Lane l, player p, integer toSpawn, integer count, real time returns thistype
            local thistype this = thistype.allocate()
            local trigger t = CreateTrigger()
            local integer i = 0

            set this.lane = l

            set this.owner = p
            set this.spawned = toSpawn
            set this.spawnCount = count
            set this.interval = time

            set this.t = CreateTimer()
            call SaveInteger(hash, GetHandleId(this.t), 0, this)

            call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
            call TriggerAddCondition(t, Filter(function thistype.flush))


            set this.waypoint = CreateRegion()
            loop
                call RegionAddRect(this.waypoint, l.getWaypoint(i))

                set i = i + 1
                exitwhen i >= l.getWaypointCount()
            endloop

            call TriggerRegisterEnterRegion(this.onEnter, this.waypoint, Filter(function thistype.enter))

            return this
        endmethod


        method startSpawn takes nothing returns nothing
            call TimerStart(this.t, this.interval, true, function thistype.spawn)
        endmethod

        method pauseSpawn takes nothing returns nothing
            call PauseTimer(this.t)
        endmethod


        method setSpawningUnit takes integer new returns nothing
            set this.spawned = new
        endmethod

        method setSpawnCount takes integer count returns nothing
            set this.spawnCount = count
        endmethod

        method setOwner takes player new returns nothing
            set this.owner = new
        endmethod

        method setLane takes Lane new returns nothing
            local integer i = 0

            set this.lane = new

            call RemoveRegion(this.waypoint)

            set this.waypoint = CreateRegion()

            loop
                call RegionAddRect(this.waypoint, this.lane.getWaypoint(i))

                set i = i + 1
                exitwhen i >= this.lane.getWaypointCount()
            endloop

            call TriggerRegisterEnterRegion(this.onEnter, this.waypoint, Filter(function thistype.enter))
        endmethod

        method setInterval takes real time returns nothing
            call PauseTimer(this.t)

            set this.interval = time

            call TimerStart(this.t, time, true, function thistype.spawn)
        endmethod

        private static method spawn takes nothing returns nothing
            local thistype this = LoadInteger(hash, GetHandleId(GetExpiredTimer()), 0)

            local integer i = 0
            local unit u

            loop
                set u = CreateUnit(this.owner, this.spawned, this.lane.getWaypointX(0), this.lane.getWaypointY(0), 0)
                call IssuePointOrder(u, ISSUED_ORDER, this.lane.getWaypointX(1), this.lane.getWaypointY(1))

                call SaveInteger(hash, GetHandleId(u), 0, 1)
                call SaveInteger(hash, GetHandleId(u), 1, this)
                call SaveReal(hash, GetHandleId(u), 2, this.lane.getWaypointX(1))
                call SaveReal(hash, GetHandleId(u), 3, this.lane.getWaypointY(1))

                set i = i + 1
                exitwhen i >= this.spawnCount
            endloop

            set u = null
        endmethod

        private static method flush takes nothing returns boolean
            if HaveSavedInteger(hash, GetHandleId(GetDyingUnit()), 0) then
                call FlushChildHashtable(hash, GetHandleId(GetDyingUnit()))
            endif
            return false
        endmethod
    endstruct

endlibrary

Last edited by YourNameHere; 12-27-2009 at 05:40 PM. Reason: even more huge update
YourNameHere is offline   Reply With Quote
Old 08-02-2009, 04:32 AM   #2 (permalink)
Forum Moderator TriggerHappy
Spell & Trigger Moderator
 
TriggerHappy's Avatar
 
Join Date: Jun 2007
Posts: 1,048
TriggerHappy is just really nice (378)TriggerHappy is just really nice (378)TriggerHappy is just really nice (378)TriggerHappy is just really nice (378)
Zephyr Challenge #6 - Winner: Dune Worm PayPal Donor: This user has donated to The Hive. 
  • Inline $NAME$TimerStart.
    call TimerStart(CreateTimer(), $HOWOFTEN$, true, function $NAME$Create )
  • TriggerRegisterTimerEventSingle - Useless BJ.
  • Who taught you how to use conditions ?
    function $NAME$Cond takes nothing returns boolean
        if GetOwningPlayer( GetEnteringUnit() ) == $PLAYER$ then
            return true
        endif
        return false
    endfunction

    // should become

    function $NAME$Cond takes nothing returns boolean
        return GetOwningPlayer( GetEnteringUnit() ) == $PLAYER$
    endfunction
  • IMO the textmacro is useless, you should have just used global functions with some timer attachment system.
  • You never null your local unit in $NAME$Create.
TriggerHappy is online now   Reply With Quote
Old 08-02-2009, 07:46 AM   #3 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 588
YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)
Ok I reworked your points.

Quote:
Originally Posted by TriggerHappy187 View Post
Who taught you how to use conditions ?
meh, I don't know, was quite late when I did it :P

Quote:
IMO the textmacro is useless, you should have just used global functions with some timer attachment system.
Yeah, that's your opinion, but IMO, it's alot easier for some people like this.
__________________
--YourNameHere
YourNameHere is offline   Reply With Quote
Old 08-02-2009, 07:53 AM   #4 (permalink)
Forum Moderator TriggerHappy
Spell & Trigger Moderator
 
TriggerHappy's Avatar
 
Join Date: Jun 2007
Posts: 1,048
TriggerHappy is just really nice (378)TriggerHappy is just really nice (378)TriggerHappy is just really nice (378)TriggerHappy is just really nice (378)
Zephyr Challenge #6 - Winner: Dune Worm PayPal Donor: This user has donated to The Hive. 
Quote:
Yeah, that's your opinion, but IMO, it's alot easier for some people like this.
Fair enough.

Quote:
Ok I reworked your points.
Remove set Create = null from the loop, it only needs to be nulled once your done using the variable. (Place it at the bottom of the function, out of the loop.)
TriggerHappy is online now   Reply With Quote
Old 08-02-2009, 08:14 AM   #5 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 588
YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)
Quote:
Originally Posted by TriggerHappy187 View Post
Fair enough.
thx :) I think alot of people who aren't so good with JASS might find this easier. Also, this doesn't need any other system to function.

Quote:
Remove set Create = null from the loop, it only needs to be nulled once your done using the variable. (Place it at the bottom of the function, out of the loop.)
meh, didn't knew. I never null anything basicly. But thanks for your help.
__________________
--YourNameHere
YourNameHere is offline   Reply With Quote
Old 08-02-2009, 11:28 AM   #6 (permalink)
Registered User maskedpoptart
aspiring programmer
 
maskedpoptart's Avatar
 
Join Date: Aug 2006
Posts: 318
maskedpoptart is on a distinguished road (70)maskedpoptart is on a distinguished road (70)
I'm pretty sure you could do this stuff in structs, and have public function which make instances of the structs (i.e. create a Spawn or a WayPoint object). If you do it right, the user could still setup a Spawn or Waypoint with one line of code, but it will reduce the size of the map dramatically; you wouldn't be copy/pasting the whole system code each time you used it.

Let me know if you would like help doing this.
__________________
My JASS resourcesMy Spells
ListFire Wall
IsUnitDead
String functions
maskedpoptart is offline   Reply With Quote
Old 08-02-2009, 12:49 PM   #7 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 588
YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)
edit2:
Code in the first post.
__________________
--YourNameHere

Last edited by YourNameHere; 08-02-2009 at 07:03 PM. Reason: Finished
YourNameHere is offline   Reply With Quote
Old 08-03-2009, 09:59 AM   #8 (permalink)
Registered User maskedpoptart
aspiring programmer
 
maskedpoptart's Avatar
 
Join Date: Aug 2006
Posts: 318
maskedpoptart is on a distinguished road (70)maskedpoptart is on a distinguished road (70)
Whenever you update, you should delete outdated code/instructions in the original post. You can keep the old code in your own files if you want.

This version is looking better, but I'm not really sure what you're doing with "MoveInteger" and "CondMoveInt". I have an idea that will make this system both easier to use, and easier to understand the code. My idea is to make a SpawnPath struct and a WayPoint struct. Each SpawnPath object will contain a list of WayPoint objects that the spawns will walk to, in the order of the Waypoints in the list. Here's the basic layout (missing a bunch of stuff):

my idea stuff
library APN requires List //a library that allows you to easily make lists
    struct WayPoint
        WayPoint nextWayPoint = 0
        private rect wpRect

        method orderToNextWayPoint takes nothing returns nothing
            //self explanatory
        endmethod

        static method create takes rect whichRect returns thistype
            //set wpRect
            //setup trigger, make action orderToNextWayPoint.
        endmethod
    endstruct

    struct SpawnPath
        IntegerList waypoints //IntegerList is a list of integers.
                             //struct instances are basically integers.
        //declare your variables like theTimer, unitType, howMany, howOften, etc.

        static method create takes integer unitType, integer howMany, ... returns thistype
            local thistype sp = thistype.allocate()
            set sp.waypoints = IntegerList.create()
            //initialize variables and start timer
            return sp
        endmethod

        method addWayPoint takes rect whichRect returns nothing
            local WayPoint newWP = WayPoint.create(whichRect)
            set WayPoint(.waypoints[.waypoints.size-1]).nextWayPoint = newWP
            //the last waypoint's next waypoint is now the waypoint we just created
            call .waypoints.addLast(newWP)
            //now the new waypoint has been added to the end of the list
        endmethod
    endstruct
Well, I hope you get the general idea. Send me a PM if you need more explanation. I am happy to help. Btw, here's the List library that you'll need.
__________________
My JASS resourcesMy Spells
ListFire Wall
IsUnitDead
String functions
maskedpoptart is offline   Reply With Quote
Old 09-01-2009, 11:35 AM   #9 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 588
YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)
Ok, huge update. (Holy shit, AoS Spawn System's shortcut is ASS :D)
__________________
--YourNameHere

Last edited by YourNameHere; 09-02-2009 at 08:41 PM.
YourNameHere is offline   Reply With Quote
Old 09-01-2009, 12:23 PM   #10 (permalink)
Registered User Anachron
^ That guy is awesome
 
Anachron's Avatar
 
Join Date: Sep 2007
Posts: 4,131
Anachron is a name known to all (629)
Hosted Project of the Year - 2009: Diablo III Warcraft 
I am currently building something like this,
which creates for 2 teams the routes and then adds information
to the unit themself, on which route they are, and which the next
point is they have to move to.
__________________
CustomInventory [Discussion - Download] - Got Directors Cut!
CustomMissle [Discussion - [Download (not yet)] - In development!
Other systems [Spawn System] [Move System] [CustomBar] [SpellBar]
Howto [install JNGP.]
Anachron is offline   Reply With Quote
Old 09-01-2009, 03:23 PM   #11 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 588
YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)
Yeah that's most likely the same after all.
__________________
--YourNameHere
YourNameHere is offline   Reply With Quote
Old 09-02-2009, 07:37 AM   #12 (permalink)
Registered User Anachron
^ That guy is awesome
 
Anachron's Avatar
 
Join Date: Sep 2007
Posts: 4,131
Anachron is a name known to all (629)
Hosted Project of the Year - 2009: Diablo III Warcraft 
So I might check this for use in my AOS, whoevers system is better.
__________________
CustomInventory [Discussion - Download] - Got Directors Cut!
CustomMissle [Discussion - [Download (not yet)] - In development!
Other systems [Spawn System] [Move System] [CustomBar] [SpellBar]
Howto [install JNGP.]
Anachron is offline   Reply With Quote
Old 09-02-2009, 08:16 AM   #13 (permalink)
Registered User maskedpoptart
aspiring programmer
 
maskedpoptart's Avatar
 
Join Date: Aug 2006
Posts: 318
maskedpoptart is on a distinguished road (70)maskedpoptart is on a distinguished road (70)
Hey I see you used my suggestions :D You are learning quickly. You should really update the original post with that code. The only thing I don't get is what the units do once they reach the second waypoint. I don't see you making any events for when the spawned units enter the rects, to order them to move to the next ones. Did you test this code to see if it works?

P.S. I like the new system name.
__________________
My JASS resourcesMy Spells
ListFire Wall
IsUnitDead
String functions
maskedpoptart is offline   Reply With Quote
Old 09-02-2009, 02:43 PM   #14 (permalink)
Registered User YourNameHere
wuts dis?
 
Join Date: Apr 2007
Posts: 588
YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)YourNameHere will become famous soon enough (118)
It's not finished yet, I'm still encountering a problem that all units are moving into the same rect at once(if you've done multiple spawns - maybe its just a failure of my setup but idk)
Anyway I updated the code, maybe someone will notice the bug.
And yes, I kind of used your suggestions :)
__________________
--YourNameHere
YourNameHere is offline   Reply With Quote
Old 09-02-2009, 02:51 PM   #15 (permalink)
Registered User Anachron
^ That guy is awesome
 
Anachron's Avatar
 
Join Date: Sep 2007
Posts: 4,131
Anachron is a name known to all (629)
Hosted Project of the Year - 2009: Diablo III Warcraft 
I also made my system!

This is an example how to call:

scope example initializer init

    private function init takes nothing returns nothing
        local WayPoint wp = 0
        local Way wy = 0
        local unit u = CreateUnit(Player(0), 'hpea', 0., 0., 270.)

        //: Instaciate a new way
        set wy = Way.create()
        //: Add a new waypoint
        call wy.addWayPoint(WayPoint.create(0., 0., 192., 192., TARGET_TOLERANCE))
        //: Add a unit to the way, starting at waypoint 0.
        call wy.addUnit(u, 0)
    endfunction

endscope

Mine does the following: You can determine whether spellcasts, stop order and hold position orders will move the unit again to the target upon finishing order.

Also its pretty easy to create waypoints and its customizeable.
You also don't need a system to move units, its doing everything on its own.

I might post mine when its finished.


edit: so back to yours, its pretty basic, but cool.
__________________
CustomInventory [Discussion - Download] - Got Directors Cut!
CustomMissle [Discussion - [Download (not yet)] - In development!
Other systems [Spawn System] [Move System] [CustomBar] [SpellBar]
Howto [install JNGP.]
Anachron is offline   Reply With Quote
Reply

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[vJass] Programming Movement CheatEnabled Triggers & Scripts 4 12-20-2008 08:44 AM
Movement System Jaijaibinx Requests 1 09-12-2008 05:58 PM
[Trigger] Movement System DredLord2 Triggers & Scripts 10 08-03-2007 03:51 AM

All times are GMT. The time now is 03:18 AM.






Hosting by SliceHost 
Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.1
Copyright©Ralle