Snippet OffsetUnitReals

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
OffsetUnitReals
By Gtam aka SharkBait87

I dont know if anyone will find this usefull but in any way i hope someone does.

This Requires NewGen


This snippet can Offset a Units Reals with a easy function call and get the offseted Real x with a function call and y aswell.
There are some other function calls that can be usefull.
To Import Just create a new trigger name RealsOffset and replace all the text with this.

Here is the code
JASS:
library RealsOffset

//=======================================================================================\\
//=======================================================================================\\
//=                     This is created by Gtam                                         =\\
//= This library makes offsetting reals alot easier                                     =\\
//= It can offset reals, move units to the offseted reals,                              =\\
//= damage the moved unit, create a effect at the moved unit and                        =\\
//= damage and created effects to the moved unit                                        =\\
//=                                                                                     =\\
//=  GetOffsetUnitRealX() takes unit, real1, real2 returns real                         =\\
//=    This is used to get the offseted reals X                                         =\\
//=                                                                                     =\\
//=  GetOffsetUnitRealY() takes unit, real1, real2 returns real                         =\\
//=    This is ised to get the offseted reals y                                         =\\
//=                                                                                     =\\
//=  OffsetUnitRealsMove() takes unit, real1, real2 returns nothing                     =\\
//=    This will offset unit reals by real and move him there                           =\\
//=                                                                                     =\\
//=  OffsetUnitRealsMoveDamage() takes unit1, unit2, real1, real2, attacktype,          =\\
//=    damagetype, weapontype returns nothing                                           =\\
//==   This will offset unit1 reals by real 1 and move him there then cause unit2       =\\
//=    to damage unit1 by real2                                                         =\\
//=                                                                                     =\\
//=  OffsetUnitRealsMoveEffect() takes unit, real, string returns nothing               =\\
//=    This will offset unit reals by real and move him there and create a effect at    =\\
//=    unit1 current position and his offseted position                                 =\\
//=                                                                                     =\\
//=  OffsetUnitRealsMoveDamageEffect() takes unit1, unit2, real1, real2, string,        =\\
//=    attacktype, damagetype, weapontype returns nothing                               =\\
//=    This will offset unit1 reals by real 1 and move him there then cause unit2       =\\
//=    to damage unit1 by real2 and create a effect at unit1 current position and his   =\\
//=    offseted position                                                                =\\
//=                                                                                     =\\
//=======================================================================================\\
//=======================================================================================\\

globals
    private real urx
    private real ury
endglobals
    
    function GetOffsetUnitRealX takes unit u, real r, real f returns real
        set urx = GetUnitX(u) + r * Cos (f * .0175)
        return urx
    endfunction
    
    function GetOffsetUnitRealY takes unit u, real r, real f returns real
        set ury = GetUnitY(u) + r * Sin (f * .0175)
        return ury
    endfunction
    
    function OffsetUnitRealsMove takes unit u, real r, real f returns nothing
        call SetUnitPosition( u, GetOffsetUnitRealX(u,r,f), GetOffsetUnitRealY(u,r,f))
    endfunction
    
    function OffsetUnitRealsMoveDamage takes unit u, unit t, real r, real f, real d, attacktype a, damagetype b, weapontype c  returns nothing
        call OffsetUnitRealsMove(u, r, f)
        call UnitDamageTarget( t, u, d, false, false, a, b, c )
    endfunction
    
    function OffsetUnitRealsMoveEffect takes unit u, real r, real f, string s returns nothing
        call DestroyEffect( AddSpecialEffect( s, GetUnitX(u), GetUnitY(u)))
        call OffsetUnitRealsMove( u, r, f)
        call DestroyEffect( AddSpecialEffect( s, urx, ury))
    endfunction
    
    function OffsetUnitRealsMoveDamageEffect takes unit u, unit t, real r, real f, real d, string s, attacktype a, damagetype b, weapontype c returns nothing
        call DestroyEffect( AddSpecialEffect( s, GetUnitX(u), GetUnitY(u)))
        call OffsetUnitRealsMove( u, r, f)
        call DestroyEffect( AddSpecialEffect( s, urx, ury))
        call UnitDamageTarget( t, u, d, false, false, a, b, c )
    endfunction
endlibrary

Btw. This is my first jass resource. Hope its usefull

Code:
ChangeLog
v1.00 Released
v1.01 Updated to Komations suggestions
v1.02 Bugs fix and should work properly now
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, first.. Why use a struct there ? :S
It's better to use a private global :D

Also, this function:
JASS:
    function GetOffsetUnitRealY takes nothing returns real
        return RO.ury
    endfunction


Should look like this:
JASS:
    function GetOffsetUnitRealX takes unit t, real r returns real
        call OffsetUnitReals(t, r)
        return RO.ury
    endfunction


To start with :p

And, can't really see how tho last 3 functions would be useful :S
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
well ill do the private globals and thats to reduce the fumction calls since the x is always returned before the y and those last three can reduce function calls alot
 

Romek

Super Moderator
Reaction score
963
These are just a bunch of BJs, really.

It's about 100 lines of code, which in the end, does this:
JASS:
call SetUnitX(u, distance * Cos(angle) + GetUnitX(u))
call SetUnitY(u, distance * Sin(angle) + GetUnitY(u))


Ironically, the snippet is named after the only function that's inaccessible.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, you can simply remove the first function, and just do this:
JASS:
    function GetOffsetUnitRealX takes unit t, real r returns real        
        local real f = GetUnitFacing(u) - 180
        set RO.urx = GetUnitX(u) + r * Cos (f * .0175)
        return RO.urx
    endfunction
    
    function GetOffsetUnitRealY takes unit t, real r returns real        
        local real f = GetUnitFacing(u) - 180
        set RO.ury = GetUnitY(u) + r * Sin (f * .0175)
        return RO.ury
    endfunction
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
:nuts:

So your parse is like a BJ in that case. Kinda useless Imo. I'm pretty sure you could have done something way more usefull ;)
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
okay komaqtion ill do that then thx for the helping too
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
Ok i updated the Snippet to komaqtions suggestions
Thx for the Feed back komaqtion
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Sorry to say this but... I can't seem to understand what this is supposed to d o:S
I used this simple trigger to test it, and it gave the same result every time:
Trigger:
  • Offset Reals Test
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: call BJDebugMsg(R2S(GetOffsetUnitRealX(gg_unit_Hpal_0010, 100)))
      • Custom script: call BJDebugMsg(R2S(GetOffsetUnitRealX(gg_unit_Hpal_0006, 100)))


Result: -99.996

What is is supposed to do ? :S

Also, why not inline this a bit more ?
JASS:
    function OffsetUnitRealsMove takes unit u, real r returns nothing
        local real x = GetOffsetUnitRealX(u, r)
        local real y = GetOffsetUnitRealY(u, r)
        call SetUnitPosition( u, urx, ury)
    endfunction


To:
JASS:
    function OffsetUnitRealsMove takes unit u, real r returns nothing
        call SetUnitPosition( u, GetOffsetUnitRealX(u,r), GetOffsetUnitRealY(u,r))
    endfunction


And, also tested that function, and it didn't do anything :S
Trigger:
  • Offset Reals Test 2
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Custom script: call BJDebugMsg("Hello!")
      • Custom script: call OffsetUnitRealsMove(gg_unit_Hpal_0010, 100)
      • Custom script: call OffsetUnitRealsMove(gg_unit_Hpal_0006, 100)


The "Hello!" was displayed, but nothing happened :S

Again... What is this supposed to do ?
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
which function did you use for the move mine or your one and its suppose to do what the title says Offset a units reals. Ill work on it when i get home.
 

Romek

Super Moderator
Reaction score
963
"Offset a units reals" means nothing whatsoever.

As I said previously, these are just a bunch of BJs (that are actually less efficient than most BJs).

GY'd
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
offset location now this just uses reals and not a location and how are these bjs they are created by me not blizzard and i see no reason to graveyard this when its not even released properly yet
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
> ...how are these bjs they are created by me not blizzard...

And what exacly is it that makes these BJs exactly that, BJs?

> ...and i see no reason to graveyard this when its not even released properly yet


Ever heard of this little rule stating that you should not submit unfinished work?
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
its not unfinished but it still in the early versions
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
The rule generally means something should be clean, polished, and more or less finalized by community final product standards before submission. If you aren't currently releasing something 'properly', it shouldn't be being released.
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
Ok but its updated in anyway and works properly thx to Komaqtion(Again)
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Btw... You should probably give the "takes" variable more descriptive names, like angle, dmg, and such :D

Also, maybe a better description of what this system does, and what each function does :D
 

Gtam

Lerning how to write and read!! Yeah.
Reaction score
164
Do you mean the takes in the description or the functions them selves
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top