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

Problems enforcing desired condition

Status
Not open for further replies.
Level 4
Joined
Apr 19, 2013
Messages
86
Hey everyone,

I'm still slaving away at Anachron's Inventory system, just trying to make it suitable for my map's play style. Right now I want to place a restriction on the type of items that the system handles. I want it to ignore power-up class items.

I'm positive this is the right area of code to restrict that, because I already set a unit classification condition where structures also don't use the system (I have a shop). So, altogether, no structures or power up item's will trigger any action, that is my aim.

While the structure condition was successful, the power up item class condition is not, Anachron's system keeps trying to run after I acquire a power up item.

Is there something wrong with my code?

This is in the trigger: CIEvents, if any of you happen to have this system

JASS:
library CIEvents
endlibrary

module CIEvents
    public method pick takes CustomItem ci returns boolean
        if .checkPickup(ci) and IsUnitType(.carrier,UNIT_TYPE_STRUCTURE)== false and IsItemPowerup(ci.getHandle()) == false then
            call ci.pick(.carrier)
            call .addItem(ci)
            return true
        endif
        
        return false
    endmethod

if the code is ok, what else could be the problem?

I want to make an invulnerability effect where I create a power up item and instantly trigger the hero to consume it (invulnerability potion), resulting in temporary invulnerability. Of course if Anachron's system takes it into it's custom inventory, the trigger will not work (because his system destroys the real item, and creates a destructible in full screen inventory -- which is awesome, but why is it sooo hard to modify) :(

thanks for reading!
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
Powerup items are items that are used automatically on acquisition (runes, glyphs, etc), which is obviously not the case for potions and therefore the IsPowerUp func returns a false. You could attach a boolean to those items' id to 'mark' them and check it in the condition. That is how I would do it.
 
Level 4
Joined
Apr 19, 2013
Messages
86
Cool, thanks for the tip, I'll let you know if I figure out how to limit by item id. +rep

EDIT: Umm.. I'm just not adept enough, setting conditions in Vjass is so strange to me, the closest I got was:

JASS:
    public method pick takes CustomItem ci returns boolean
        if .checkPickup(ci) and IsUnitType(.carrier,UNIT_TYPE_STRUCTURE)== false and GetItemType(ci.getHandle()) == false then

It's not even complete, I don't know where to put the item's raw code "I00G" or make it a negative or not equal to function.

the TESH feature helped a little, but if someone can spell it out for me, I'd really appreciate it.
 
Level 4
Joined
Apr 19, 2013
Messages
86
ok, but how to I make it a boolean though? Would it be like

JASS:
GetItemTypeID(ci.getHandle()) == "I00G" == false

So I want the following functions to run only if the item isnt "I00G"
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
no just like this
JASS:
GetItemTypeID(ci.getHandle()) == 'I00G'
if its equal it returns true. u dont need true or false in jass. also pay attention to the different keys. this ( ' ) is ascii value ( an integer). this ( " ) is a string key.
u can change this
JASS:
and IsUnitType(.carrier,UNIT_TYPE_STRUCTURE)== false
to this and its more efficient this way.
JASS:
and not IsUnitType(.carrier,UNIT_TYPE_STRUCTURE)
 
Level 4
Joined
Apr 19, 2013
Messages
86
Sorry I should have included more script. When I try that way it gives me compile errors. Cannot convert integer to boolean and cannot compare variables of different primitives.

JASS:
public method pick takes CustomItem ci returns boolean
        if .checkPickup(ci) and IsUnitType(.carrier,UNIT_TYPE_STRUCTURE)== false and not GetItemTypeId(ci.getHandle()) == 'I00G' then
            call ci.pick(.carrier)

I think I have to keep the boolean nature of the function. but how do I make it so that the item condition restricts correctly? All I want to do is make sure the function doesn't do anything if the item is 'I00G'

thanks again!
 
Level 8
Joined
Feb 3, 2013
Messages
277
EDIT: sorry nm, late at night my mistake

I'm gonna dl the system and look at it rite nao

JASS:
public method pick takes CustomItem ci returns boolean
    if .checkPickup(ci) then
        if GetItemTypeId(ci.getHandle()) == 'I00G' and IsUnitType(.carrier,UNIT_TYPE_STRUCTURE) == false then   
        else
            call ci.pick(.carrier)
            // Whatever else it, this method should do.
            return true
        endif
    endif

    return false    
endmethod
 
Last edited:
Level 4
Joined
Apr 19, 2013
Messages
86
Ok, the whole structure boolean thing was my addon, its in the CI Events Trigger, towards the top of the trigger in its original state
 
Level 8
Joined
Feb 3, 2013
Messages
277
Ok, the whole structure boolean thing was my addon, its in the CI Events Trigger, towards the top of the trigger in its original state

yeah I saw, all it does it check if the item is legit whether or not you already have it - it's a safety kind of thing

but that should do it, if the itemtype of the item handle is 'I00G' and .carrier is not a structure(I'm not sure if you need the second boolean or not) the it won't do anything and eventually return false. Else, it'll do whatever the method should originally be doing and return true.
 
Level 8
Joined
Feb 3, 2013
Messages
277
Well, it won't do anything - if the first condition is met. Unless you call more functions/natives outside the if statement. So it should work as you want it to.

DiggetyBo said:
Sorry I should have included more script. When I try that way it gives me compile errors. Cannot convert integer to boolean and cannot compare variables of different primitives.

Btw, if Condition1 is a boolean expression (function that returns true/false) this is probably because you did Condition1 instead of Condition1().

something like this will work
JASS:
function Condition1 takes item i, unit u returns boolean
    return GetItemTypeId(i) == 'I00G' and IsUnitType(u, UNIT_TYPE_STRUCTURE) == false
endfunction

public method pick takes CustomItem ci returns boolean
    if .checkPickup(ci) then
        if Condition1(ci.getHandle(), .carrier) then   
        else
            call ci.pick(.carrier)
            // Whatever else it, this method should do.
            return true
        endif
    endif

    return false    
endmethod
 
Level 4
Joined
Apr 19, 2013
Messages
86
Ok cool, now I understand. I'll try it out in a bit, thanks a lot. +rep

EDIT: got some errors I've never seen before... Error function inside struct? and Error struct declaration.

Here is what I tried:

JASS:
module CIEvents
function Condition1 takes item i, unit u returns boolean
    return GetItemTypeId(i) == 'I00G' and IsUnitType(u, UNIT_TYPE_STRUCTURE) == false
endfunction    
    public method pick takes CustomItem ci returns boolean
        if .checkPickup(ci)
            call ci.pick(.carrier)
            call .addItem(ci)
            return true
        endif
        
        return false
    endmethod

I'm soooo cllose now, sooo close.

Any ideas?
 
Last edited:
Status
Not open for further replies.
Top