| 08-04-2011, 08:41 AM | #2 |
That's because you're using things like (Target unit of ability being cast) after a wait period. You could be using variables/hashtables in order to track event responses better. |
| 08-04-2011, 10:12 AM | #3 |
As Bribe pointed out, due to a WC3 bug the cast event responses do not work after a wait. Is that wait really necessary, though? You only wait for 0.01 seconds (actually, closer to 0.2 seconds because WC3 waits are not that accurate). If you must have a wait, you should set the two variables after it, not before it. In fact, you should set your P1_Rnd variable inside the loop, else the code will keep checking the same slot. Aside from that, your if/then/else statements seem oddly structured. You only remove an item from a slot if there is no item in the slot, which does nothing, while you increase the DiscardCardCounter if an item is found, but you don't remove it. I get that DiscardSlotChecker is supposed to mark already checked slots but it won't work correctly on subsequent casts if you don't set it to false before doing the loop. Even if you were to correct these issues, making 6 random checks does not mean you will check all six slots in random order, you might check some slots multiple times while not checking others, so you could end up not removing a single item even if the unit has them. A simpler way to do this would be to use an item array to create a list of all items carried by the unit. Simply loop through slots 1 to 6 and if the unit has an item in that slot, add it to the array and increase an integer variable that marks how many items you found (make sure you set that variable to 0 before you start the loop). Then, if any items were found, get a random number between 1 and the number of items and remove the item stored in the array under that number. Repeat the process to remove another item. Edit: I just noticed that ItemUtils includes a UnitGetRandomItem function which already does what I described above. |
| 08-04-2011, 09:35 PM | #4 | |
Quote:
Thank you so much, I did this and it works perfectly now! I also learned a bit more about triggering (I've just started mapping again from a loooong break), thanks again |
