• 🏆 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!

[JASS] Need JASS script, please help

Status
Not open for further replies.
Level 3
Joined
May 29, 2006
Messages
33
I NEED HELP!!! i need a script that will attack a unit with selected unit every time i left click mouse (or right click but left cick preferd) can anyone start me out or help at all :?: :!:
 
Level 5
Joined
May 22, 2006
Messages
150
Uh?
Let us see...

JASS:
global rect udg_tempRectangle = Rect(500,500,-500,-500)

function Trig_Conditions takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(),Player(0)) == true
endfunction

function Trig_Actions takes nothing returns nothing
local location tempLocation
if not IsUnitGroupEmptyBJ(GetUnitsSelectedAll(Player( X ))) then
set tempLocation = GetUnitLoc(GroupPickRandomUnit(GetUnitsSelectedAll(Player( X ))))
call MoveRectToLoc(udg_tempRectangle,tempLocation)
call GroupTargetOrder(GetUnitsSelectedAll(Player( X )),"attack",GroupPickRandomUnit(GetUnitsInRectMatching(udg_tempRectangle,Condition(function Trig_Conditions))))
endif
call RemoveLocation(tempLocation)
set tempLocation = null
endfunction

function InitTrig takes nothing returns nothing
set gg_trg = CreateTrigger()
call TriggerRegisterPlayerEventEndCinematic(gg_trg,Player( X ))
call TriggerAddAction(gg_trg,function Trig_Action)
endfunction

Attacks hostile units in a range of 500 to a random selected unit.

I do not know how to get an event for mouse buttons, so I chose the keyboard's "Esc"-button.
Seek the "X" in my Code and replace it with a number from 0 to 11.
I do not have the time to test it, but it should work - simply report errors.
 
Level 5
Joined
May 22, 2006
Messages
150
I knew, I forgot something. ~~

Corrected.

postscript:
Here a global rectangle accelerates the script as I do not need to create/destroy an object on each execution.
All I have to do is resetting four primitives.

... And as the rectangle itself is not used to create the desired effect,
it should even work for multiple players due to the fact,
that only one operation per time can be done by a computer.
 
Level 5
Joined
May 22, 2006
Messages
150
Erm... What do you mean with "nulling my location"?
"tempLocation = null"?
Deleting the reference to an object causes this object to get lost for the VM.
That is called "memory leak", if I am not wrong.

...

Yes, the BJ...
I am ashamed to say, but I have no idea how this function works.

JASS:
function IsUnitGroupEmptyBJ takes group g returns boolean

[...]

set bj_isUnitGroupEmptyResult = true
call ForGroup(g, function IsUnitGroupEmptyBJEnum)

[...]

return bj_isUnitGroupEmptyResult
endfunction

JASS:
function IsUnitGroupEmptyBJEnum takes nothing returns nothing
set bj_isUnitGroupEmptyResult = false
endfunction

That is nonsense in my eyes.
But it works and so I better keep my fingers away from it.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
to null, AFTER you destroy the location/whatever other handle, you set xxx = null. this prevents a leak of 4 bits of memory O.O ( unlike destroying locs, etc, this only has to be done with locals )

anyways, use CountUnitsInGroup( g ) == 0

it runs a little bit faster, though its still a BJ. the alternative for it is about as confusing to starters as that IsUnitGroupEmpty xD
 
Level 5
Joined
May 22, 2006
Messages
150
... I had a thought about it and as I remember right, the four bit emplacement in memory is not an object but a reference - in this special case the reference "location tempLocation".
A reference has a fixed size - from it's creation till it's destruction it is exactly four bites big, no matter what it grants access to.

That means, that "[object type] [identifier]=null" needs as much space as "[object type] [identifier]=[object]"...
So far, there should not be any leak, even if the refered object is deleted (in fact, an operation "delete" is never internally used - it is nearly impossible to really delete some data from the physical medium without destroying it - by turning off the power of the main memory for example) ...

On the other hand, if a reference whould not be deleted, this would cause a four bit memory leak...
But as far as I remember, there is no method or function to destroy references in Java, JASS, Visual Basic, Pascal or the C-family...
So they should be removed automatically...
Or at least I have to hope that. ^^

But of course my information is not the top of the world and so it whould be nice, if you could tell me, how (and, more important, where) you aquired knowledge about this leak.
 
Level 5
Joined
May 22, 2006
Messages
150
Well, then - there must have been a day, when you first heard about a strange kind of language called "JASS", there must have been a lot of days and nights you spend with deciphering this enigmatic piece of alteration and there must have been the day, you first heard about an operation called "nulling ones variables" and aquired the information, that this is necessary for locals to prevents four bits of leak...
And where that was or by whom it was told really interests me. As it may be true - and my scripts leak... Or it may be wrong - and I waste time with a useless function call.
And as locals are mostly used in functions, which are called very often, this loss of efficiency may even be felt.
 
Level 5
Joined
May 22, 2006
Messages
150
Well, these are some names - names I am not familiar with, but still names.
I will have to ask one of them how the idea came up.
Any idea where to meet one?

... "0.01 triggers"? What may this mean...
As a kind of "lone wolf" I worked alone for a pretty long time and so I have no idea about "scenic" expressions. ^^
 
Level 32
Joined
Oct 23, 2006
Messages
5,291
User Accounts

bada: I believe that this thread is among many old threads that were imported from another site (check the dates). It's likely that the original author's account is now "imported_bada."

Your recently created account and password should be secure.

I'll close this thread to prevent further posts in it. Send me a PM if you have any questions.

~ Thread closed.
 
Status
Not open for further replies.
Top