• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Preventing unit crashes for out of bounds with get/set x & y

Status
Not open for further replies.
Level 4
Joined
Sep 25, 2005
Messages
71
Alright. I don't have code for this exactly because I'm not sure where to start.

Say I want to start using get/set unitX/unitY to move stuff around as has been suggested. For example, I could use a spell that on cast, creates x dummy units over the target unit in a random spot in a area within x distance units from the target's point, is issued an order to attack ground, then expires. If the unit is close to the edge so that x is outside, we have an issue. Additionally, if a unit is moving via a triggered get/set x & y, it can go outside bounds if it's not held back, and that can crash, right?

Where do I start to set these limitations to these example spells? I'm really hesitant to just implement someone elses' system because I don't feel like I'd really learn that kinda' stuff for myself and that bothers me. Worst case I would, but I'd prefer how to make rudimentary, functional, "don't go outside and crash the game" code.
 
This is what you're looking for:
http://www.wc3c.net/showthread.php?t=102576

To import it, first you must download JASS NewGen Pack. Then you will just copy and paste that code in a new trigger. From there, it will monitor your unit's to make sure they don't leave the playable map area (or rather, the camera boundaries + a little distance).

It won't work if you try to create a unit off the map, though. But as far as setting position goes, it will work.

EDIT: I read your post. To understand how it works, it first detects when a unit leaves the camera bounds + a little margin. It forms a rect out of that, and registers the "Unit leaves a rect" event. On initialization, it stores the min X, max X, min Y, and max Y of the rect. Every time the event is fired, it will check where the unit was moved past, and set its new position within the limit. (if it is greater than max X, set the unit's X position to the max X. if it is less than min X, set the unit's X position to the min X.. etc. for Y coordinates) That is all there is to it.

I understand that you may not want to use other people's code since you won't learn anything. However, as long as you have an understanding of how it works, you should be fine with using it. If you need more info on it, feel free to ask.
 
Status
Not open for further replies.
Top