best way to know if an unitid is valid or not ?

Troll-Brain

You can change this now in User CP.
Reaction score
85
Because of this bug it isn't so easy.

JASS:
library IsUnitIdValid

globals
   private unit U
endglobals

function IsUnitIdValid takes integer i returns boolean
    if IsGameLoaded() then // ofc i plan to store the result, to avoid the creation of the unit all the time, when it was already checked
                           // but i'm waiting for hashtables available on the official patch
        set U = CreateUnit(Player(0),i,0.,0.,0.) // yeah i should use a dummy player and constants reals X/Y instead
        
        if GetWidgetLife(U) != 0 then
            call RemoveUnit(U)
            return true
        else
            return false
        endif
        
    else
    
        return UnitId2String(i) != null
    endif
endfunction

endlibrary


Better ideas ?

PS : I don't want to store a boolean manually for each unitid possible on the map

EDIT : It seems that IssueBuildOrderById() always returns true while the arguments are "valids" (existent unit and order).
I mean it returns true for any existent order, "move" for example ...
 

Tom Jones

N/A
Reaction score
437
I've read the entire thread from the hyperlink, and I still don't understand the bug? Anyways:
JASS:
function ... takes integer id returns boolean
     return GetObjectName(id) == null
endfunction
You can't input null strings as object names as far as I remember.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
I've read the entire thread from the hyperlink, and I still don't understand the bug? Anyways:
JASS:
function ... takes integer id returns boolean
     return GetObjectName(id) == null
endfunction
You can't input null strings as object names as far as I remember.

Erf.
I hope you will understand :
http://www.wc3c.net/showpost.php?p=1060727&postcount=38
Donwload the test map, give orders, save the game, load it , give orders.

And GetObjectName is not bugged but using it, you can't know if an order is a build order or not.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
@Faust :
Sorry, but where is the better idea ?
IsUnit maybe ? I don't have the editor now, but if this exist, sure i will use it instead of checking the life.
But still the worst thing is the unit creation, maybe there is not any other way.

@Jesus4Lyf :
If it's a sarcasm, the point is to know if an order is a training one or not.
If you're serious then explain more ...
 
Reaction score
341
Well if you worried about speed of the unit creation, you can do something like this;

JASS:
globals
    private unit u
    private hashtable hash = InitHashtable()
endglobals

function ValidId takes integer id returns boolean
    local boolean ret
    if not HaveSavedBoolean(hash, id, 0) then
        set u = CreateUnit(....)
        set ret = (GetWidgetLife(u) < 0.405) // IsUnit takes two arguments?
        call RemoveUnit(u)
        call SaveBoolean(hash, id, 0, ret)
        return ret
    endif
    return LoadBoolean(hash, id, 0)
endfunction


Wrote that in the quick reply box, so sorry if theres any errors.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Well if you worried about speed of the unit creation, you can do something like this;

JASS:

globals
    private unit u
    private hashtable hash = InitHashtable()
endglobals

function ValidId takes integer id returns boolean
    local boolean ret
    if not HaveSavedBoolean(hash, id, 0) then
        set u = CreateUnit(....)
        set ret = (GetWidgetLife(u) < 0.405) // IsUnit takes two arguments?
        call RemoveUnit(u)
        call SaveBoolean(hash, id, 0, ret)
        return ret
    endif
    return LoadBoolean(hash, id, 0)
endfunction


Wrote that in the quick reply box, so sorry if theres any errors.

If you had read the comments inside the code i've posted you would know that i plan to use something like that.
Speed is not the only one issue, an event "unit enter in ..." can fire for nothing and more other events.
I would prefer to avoid totally the unit creation, but maybe it's impossible unless you store at the map init all booleans for each unitid possible.
 

Jesus4Lyf

Good Idea™
Reaction score
397
the point is to know if an order is a training one or not.
Ah, I see. But a train order isn't about to happen while the map is loading, is it? So does the bug really matter?

(Obviously for a train order to be issued on map init, it would need to be triggered, which means you don't need to detect it because, well, you already made it happen yourself and could just script the effect to happen there.)
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Ah, I see. But a train order isn't about to happen while the map is loading, is it? So does the bug really matter?
Because it's a public resource, yes it does matter :p

(Obviously for a train order to be issued on map init, it would need to be triggered, which means you don't need to detect it because, well, you already made it happen yourself and could just script the effect to happen there.)
I plan to finish GetWorker (the unit which is making the build).
And in the process i need to catch building orders, but don't interact with them.
I don't understand why you are talking about map init. :confused:
 

jwallstone

New Member
Reaction score
33
Actually one way to tell if it's valid is to just look at the integer itself. All unit id's begin with h, o, u, e, or n. Now, I've seen a post somewhere that talks about this, but all unit id's are essentially just base 256 representations of the integer, so you could just do a simple mathematical test in this case.

EDIT: Base 256, with 94 valid chars apparently.
http://www.wc3c.net/showthread.php?t=106982

So, one simple solution is to just write code to display the following:
JASS:
call BJDebugMsg(I2S('h000'))
call BJDebugMsg(I2S('o000'))
call BJDebugMsg(I2S('e000'))
call BJDebugMsg(I2S('u000'))
call BJDebugMsg(I2S('n000'))


Then, to test if it's a valid unit id, just mod out all the lower digits (modulo the int you're testing with whatever '1000' is, and subtract that remainder from the original int). Then, if the remaining integer is one of the 5 values you displayed above, it's a valid unit id.
 
Reaction score
341
Actually one way to tell if it's valid is to just look at the integer itself. All unit id's begin with h, o, u, e, or n. Now, I've seen a post somewhere that talks about this, but all unit id's are essentially just base 256 representations of the integer, so you could just do a simple mathematical test in this case.

People make custom units :nuts:
 

jwallstone

New Member
Reaction score
33
Yeah, and all custom units also begin with one of those letters. Or have you never looked at the id's of custom units yourself?

Think before you make sarcastic comments.
 

Jesus4Lyf

Good Idea™
Reaction score
397
to test if it's a valid unit id, just mod out all the lower digits (modulo the int you're testing with whatever '1000' is, and subtract that remainder from the original int).
Just divide? By '1000' or whatever? :p

Also, heroes are H, O, U, E or N I believe.

There's a good chance this would work. But I believe rawids can use anything, even v for example ('v000'). In which case there's no chance this would work. :p

I would opt for caching the success of CreateUnit unless you can use some of those natives to test attributes of unittypes. Actually, could you test for the "dead" attribute of a unit type using IsUnit or whatever it is? Because if that worked... You could inline to a native. XD
 

saw792

Is known to say things. That is all.
Reaction score
280
Just to clear this up for both Jesus and Troll, the post Troll linked to was testing whether the map had been saved and reloaded, not whether the map was currently at the loading screen.

Also, any 4 digit code should be valid for an object id when set through Newgen.
 
Reaction score
341
Also, any 4 digit code should be valid for an object id when set through Newgen.

Yea but I think he wants to know if the entered id is a unit. For example, the id 'ratf' is Claws of attack (item). If someone inputs that value in the function it will return false because it's not a unit id.
 

Jesus4Lyf

Good Idea™
Reaction score
397
use some of those natives to test attributes of unittypes. Actually, could you test for the "dead" attribute of a unit type using IsUnit or whatever it is? Because if that worked... You could inline to a native. XD
Try something like this...
JASS:
function IsRawcodeUnitType takes integer rawcode returns boolean
    return IsUnitIdType(rawcode,UNIT_TYPE_FLYING)!=IsUnitIdType(rawcode,UNIT_TYPE_GROUND)
endfunction

Edit: Doesn't work yet, I'm still trying.
Edit: Gosh, it's hopeless. None of the classifications apply to statis wards. :(

Edit: MEH...
JASS:
function IsUnitTypeId takes integer id returns boolean
    set bj_lastCreatedUnit=CreateUnit(Player(15),id,0,0,0)
    if bj_lastCreatedUnit==null then
        return false
    endif
    call RemoveUnit(bj_lastCreatedUnit)
    return true
endfunction

Tested and works. <_<
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Well, so i guess i will keep the code like that. (already posted in the first post of this thread).
And do the little optimisation suggested by kingkingyyk3
Anyway thx for tryings.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top