Snippet R-Functions

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Just a few simple function to help you do things faster - I'll keep this updated since every function that I will write and find useful I'll add here.

JASS:
// if SubString(l-1,l) is just annoying
function RF_IsEven takes integer subject returns boolean
    local integer check = subject / 2
    local integer test = check * 2
    
    if test < subject or subject < 2 then
        return false
    endif
    
    return true
endfunction

function RF_R2I takes real subject returns integer
    local real check = subject - .5
    local integer test = R2I(subject)
    
    if test >= check then
        return test
    endif
    
    return test + 1
endfunction

// Too bad we can't return two reals
function RF_Destination takes unit subject, real wait returns location
    local real facing = GetUnitFacing(subject)
    local real speed = GetUnitMoveSpeed(subject)
    local real distance = wait * speed
    local location current = GetUnitLoc(subject)
    local location returned = PolarProjectionBJ(current,distance,facing)

    // Leakz
    call RemoveLocation(current)
    set current = null
    
    return returned
endfunction

//Forced by WE - Not relevant
function InitTrig_RFunctions takes nothing returns nothing
endfunction


RF_IsEven - If an integer is even it will return true, else return false. 0 is considered odd (false).

RF_R2I - Converts a real to integer, however unlike the regular conversion, it won't be rounded down, but rounded to the closet integer (e.g. 3.1 = 3, 3.7 = 4). X.5 = X.

RF_Destination - Assuming the unit will keep walking in the same direction this will return the location it will reach after "wait" number of seconds.

Very little so far, but I hope soon enough more functions will be added, anyway, have fun with it.
 

Attachments

  • R-Functions.w3m
    12.4 KB · Views: 268

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>X.5 = X
arent .5 being rounded will become 1?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
What?

1.5 = 1 if you use my function. In the same manner:

2.5 = 2, 3.5 = 3, 4.5 =4 ... n.5 = n
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
> AceHart

Hmmm... Care do explain what you want to say in that post? ;)

> Unverified

Are you quite sure this is a legitimate word?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
> That there's most likely an easy way to shorten those functions to one-liners.

Bah - those are too simple for my mind which likes to do things more complicated than they should.

> Yes.

Then it is not included in my dictionary.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
my meaning is...

0.0, 0.1, 0.2, 0.3, 0.4 should be 0 when being rounded
0.5, 0.6, 0.7, 0.8, 0.9 should be 1 when being rounded...
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
> 0.5, 0.6, 0.7, 0.8, 0.9 should be 1 when being rounded...
Today 05:13 PM

Then change the function, although AceHart pretty much ruined what I did here. :p

> See verify.

Bah, I tried verifie, thanks phyrex1an, you learn something new every day. ;)
 

Master

Thou shall be helped by...The Black Adder!
Reaction score
72
Well nothin's ruined...it's quite good, Rheias +rep.

You are incompetable.

Look in dictionary -> incompetability
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
> RF_IsEven - If an integer is even it will return true, else return false. 0 is considered odd (false).

This can be accomplished very simply using the mod function.

JASS:
if (<Number> Mod 2) Equal to 0, Then
  return true
else
  return false


That just seems a little simpler.
As for the other stuff, looks pretty good.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> That just seems a little simpler.

Once there, you notice that, basically, you're returning the result of the test, so you return the test directly and forget the "if".
At which point you can do the mod yourself, and end up with post #4.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
My function (IsEven) is basically a (very) fancy way of doing AceHart's job. As for your function, it may be a bit shorter (note that my function is long in order to make it clear) but I'm not sure it is efficient as mine (no function calls in mine, in yours there is one,which is quite slow).

Anyway, this is supposed just to be kind of a bank for functions, I hope the next ones would be more useful. ;)
 

SerraAvenger

Cuz I can
Reaction score
234
Just a few simple function to help you do things faster - I'll keep this updated since every function that I will write and find useful I'll add here.

JASS:
// if SubString(l-1,l) is just annoying
function RF_IsEven takes integer subject returns boolean
    local integer check = subject / 2
    local integer test = check * 2
    
    if test < subject or subject < 2 then
        return false
    endif
    
    return true
endfunction


RF_IsEven - If an integer is even it will return true, else return false. 0 is considered odd (false).

I'ld use
JASS:
if subject - (subject / 2) * 2 == 0 then
.

EDIT: didn't read aceharts post, sorry.

EDIT2: You can aswell write these functions in your map header. Then you aren't forced by WE to make a trigger init function. On second thought - in which way does WE force you to copy the WHOLE page, and not to skip the last two ( three ) lines?
 
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