| 08-20-2008, 11:17 AM | #1 | |
Condition System
kthxbye? Yes, finally, it's done. I had larger problems with the AddAllConditions(...) function, and I found out that if done through another function, I mean adding all conditions, it screws up, but if done manually, it doesn't. EDIT: That function works now. Oh yeah, I think it's MUI, but if someone figures out that I'm wrong, then I'm wrong, probably. Requires NewGen, TimerUtils. Da whoopy code; JASS://************************************************************************************************** // C O N D I T I O N S Y S T E M * // By Vestras * // * // Credit Vestras if you use this. * // * // * // Pros: * // * // - Completely MUI. * // - Got 7 conditions. (more wouldn't be nice, too confusing) * // - Adds a good feeling to the map. * // * // Cons: * // * // - Maximum of 7 conditions per unit. (Stupid Blizzard) * // - No bugs so far, if you find some, please report. * // * // * // Function list: * // * // call AddCondition(unit whichUnit, integer whichBuff)<--Adds a specified buff to the unit. * // * // call AddTimedCondition(unit whichUnit, integer whichBuff, real duration)<--Same as above, just * // timed. * // * // call AddAllConditions(unit whichUnit)<--Adds all possible conds to the specified unit. * // * // call AddAllConditionsTimed(unit whichUnit, real duration)<--Same as above, just timed. * // * // call RemoveCondition(unit whichUnit, integer whichBuff)<--Removes a specified buff from the * // unit. * // * // call RemoveAllConditions(unit whichUnit)<--Simple, removes all conds from a specified unit. * // * // Function list: (this time the return boolean conditions) * // * // call UnitHasConditionOfType(unit whichUnit, string whichBuff)<--Checks if the unit has the buff.* // * // call UnitHasAnyConditions(unit whichUnit)<--Checks if the unit just has any condition. * // * // call UnitHasAllConditions(unit whichUnit)<-- Checks if the unit has all the possible conditions.* // * // * // Condition list: * // * // Blind - Gives the unit a chance to miss on attack. * // Burn - Damage over time to the unit. * // Cripple - Reduces movement and attack speed of the unit. * // Dazed - Reduces movement speed of the unit. * // Maim - Reduces the attack speed of the unit. * // Silence - Makes the unit unable to cast spells. * // Sunder - Reduces the armor of the unit. * // * // Enjoy! * // - Vestras. * //************************************************************************************************** library ConditionSystem requires TimerUtils // The default globals; globals private constant integer DUMMYID = 'h000' // The dummy unit's raw code // Here comes the constant integers which defines which conditions are which. (Blind = 1, Sunder = 7 etc., etc.) constant integer STARTARRAY = 1 // This one is where the array starts. This should always be the same as your first condition. constant integer BLIND = 1 constant integer BURN = 2 constant integer CRIPPLE = 3 constant integer DAZED = 4 constant integer MAIM = 5 constant integer SILENCE = 6 constant integer SUNDER = 7 constant integer ENDARRAY = 7 // This one is where array ends. This should always be the same as your last condition. endglobals // The array globals, you can set these further down. globals integer array CONDITIONABILITIES integer array CONDITIONBUFFS string array CONDITIONRODERS // The dummy, don't edit private unit DUMMY=null endglobals function InitTrig_ConditionSystem takes nothing returns nothing // Abilities set CONDITIONABILITIES[1] = 'A008' // Blind set CONDITIONABILITIES[2] = 'A009' // Burn set CONDITIONABILITIES[3] = 'A00A' // Cripple set CONDITIONABILITIES[4] = 'A00D' // Dazed set CONDITIONABILITIES[5] = 'A00B' // Maim set CONDITIONABILITIES[6] = 'A00E' // Silence set CONDITIONABILITIES[7] = 'A00F' // Sunder // Buffs set CONDITIONBUFFS[1] = 'B000' // Blind set CONDITIONBUFFS[2] = 'B003' // Burn set CONDITIONBUFFS[3] = 'B002' // Cripple set CONDITIONBUFFS[4] = 'B006' // Dazed set CONDITIONBUFFS[5] = 'B005' // Maim set CONDITIONBUFFS[6] = 'B001' // Silence set CONDITIONBUFFS[7] = 'B004' // Sunder // Orders set CONDITIONRODERS[1] = "curse" // Blind set CONDITIONRODERS[2] = "innerfire" // Burn set CONDITIONRODERS[3] = "cripple" // Cripple set CONDITIONRODERS[4] = "slow" // Dazed set CONDITIONRODERS[5] = "bloodlust" // Maim set CONDITIONRODERS[6] = "silence" // Silence set CONDITIONRODERS[7] = "acidbomb" // Sunder // Don't edit this one set DUMMY=CreateUnit(Player(13),DUMMYID,0,0,0) endfunction private struct CondSys integer id timer tmr unit target private method onDestroy takes nothing returns nothing call ReleaseTimer(.tmr) set .target=null set .tmr=null endmethod endstruct function RemoveCondition takes unit whichUnit, integer id returns nothing call UnitRemoveAbility(whichUnit,CONDITIONBUFFS[id]) endfunction function RemoveAllConditions takes unit whichUnit returns nothing call RemoveCondition(whichUnit,BLIND) call RemoveCondition(whichUnit,BURN) call RemoveCondition(whichUnit,CRIPPLE) call RemoveCondition(whichUnit,DAZED) call RemoveCondition(whichUnit,MAIM) call RemoveCondition(whichUnit,SILENCE) call RemoveCondition(whichUnit,SUNDER) endfunction function AddCondition takes unit u, integer id returns nothing call UnitAddAbility(DUMMY,CONDITIONABILITIES[id]) if id==SILENCE then call IssuePointOrder(DUMMY,CONDITIONRODERS[id],GetUnitX(u),GetUnitY(u)) else call IssueTargetOrder(DUMMY,CONDITIONRODERS[id],u) endif call UnitRemoveAbility(DUMMY,CONDITIONABILITIES[id]) endfunction private function RemoveTimedCondition takes nothing returns nothing // This one isn't for outside system use. local CondSys d=GetTimerData(GetExpiredTimer()) call RemoveCondition(d.target,d.id) call d.destroy() endfunction function AddTimedCondition takes unit u, integer id, real duration returns nothing local CondSys d=CondSys.create() set d.tmr=NewTimer() set d.target=u set d.id=id call AddCondition(u,id) call SetTimerData(d.tmr,d) call TimerStart(d.tmr,duration,false,function RemoveTimedCondition) endfunction function AddAllConditions takes unit u returns nothing local integer i=STARTARRAY loop exitwhen i>ENDARRAY call AddCondition(u,i) set i=i+1 endloop endfunction function AddAllConditionsTimed takes unit u, real duration returns nothing local integer i=STARTARRAY loop exitwhen i>ENDARRAY call AddTimedCondition(u,i,duration) set i=i+1 endloop endfunction function UnitHasConditionOfType takes unit whichUnit, integer id returns boolean return GetUnitAbilityLevel(whichUnit,CONDITIONBUFFS[id])>0 endfunction function UnitHasAnyCondition takes unit whichUnit returns boolean local integer i=STARTARRAY loop exitwhen i>ENDARRAY if UnitHasConditionOfType(whichUnit,i) then return true endif set i=i+1 endloop return false endfunction function UnitHasAllConditions takes unit whichUnit returns boolean return UnitHasConditionOfType(whichUnit,BLIND) and UnitHasConditionOfType(whichUnit,BURN) and UnitHasConditionOfType(whichUnit,CRIPPLE) and UnitHasConditionOfType(whichUnit,DAZED) and UnitHasConditionOfType(whichUnit,MAIM) and UnitHasConditionOfType(whichUnit,SILENCE) and UnitHasConditionOfType(whichUnit,SUNDER) endfunction endlibrary Da screenshot;
Wellz, I hope you are the enjoying. Oh yeah, give creditxz to me (Vestras) when using and all that shiz. |
| 08-20-2008, 11:38 AM | #2 |
No vJASS or NewGen needed? w00t! |
| 08-20-2008, 11:43 AM | #3 |
You wish. "library ConditionSystem". kekekekeke ^_^ |
| 08-20-2008, 12:20 PM | #4 |
You have no documentation on what each condition does. Some of your conditions don't stack with others, that's a huge design flaw. I don't see why you need the string constants, why can't people just use the integer constants directly, their names are descriptive enough? You should provide a way for users to apply conditions for a specific duration. |
| 08-20-2008, 12:37 PM | #5 |
> You have no documentation on what each condition does. Gonna add that then. > Some of your conditions don't stack with others, that's a huge design flaw. What do you mean? > I don't see why you need the string constants, why can't people just use the integer constants directly, their names are descriptive enough? Somehow, when I called IssueTargetOrderById(...) nothing happened. And I need the CONDITION_STRING_NAME_XXX because, that if I used the XXX_ORDER_STRING for that, it would screw totally up. Also tried using the integers, didn't work either. > You should provide a way for users to apply conditions for a specific duration. Yeah, thought of that too, gonna do it, cause it's goddamnit annoying to apply waits all the time. |
| 08-20-2008, 12:51 PM | #6 | ||
Quote:
Quote:
|
| 08-20-2008, 12:57 PM | #7 |
> You have three based on cripple and two based on inner fire. Custom buff spells based on the same spell don't stack. You need to fix this. Of course, what should I base them on? > It should work. Sure, "blind" is faster to type than CONDITION_TYPE_BLIND, but seriously, adding another constant just for that is lame. I mean, if you're going to have another set of variables, at least make them array indexes and make all the other variables into arrays, at least that will shorten your code considerably. In fact, I don't see how I could approve a system that doesn't do that. You should be using structs for condition types, it's the only sane way to code this. Why should I use structs? Well, I guess I can use arrays. I think I'm gonna create a nice, big update now. |
| 08-20-2008, 01:59 PM | #8 |
Cripple, Poison, Slow. That's 3 dfferent slow buffs. |
| 08-20-2008, 02:28 PM | #9 |
Well, to his defence, some conditions like silence or curse can't really be achieved by adding passive abilities to the unit, you need dummy casters. |
| 08-20-2008, 02:31 PM | #10 | ||
Quote:
Why shouldn't I? As Ani said; Quote:
Updated. Big time. |
| 08-20-2008, 02:42 PM | #11 |
Your library does not compile. |
| 08-20-2008, 02:52 PM | #12 |
Uhm... What do you mean? Syntax errors? |
| 08-20-2008, 03:02 PM | #13 |
UnitHasConditionOfType may not match up to the buffs actually on it. WTH is up with your indenting? You should really be recycling timers and dummy units. If SUNDER isn't the last one, it doesn't work right. There is no support for conditions by adding abilities to the unit, doing trigger actions, etc. DummyID should be DUMMY_ID or something, as it is a constant. AddTimedCondition should attach the timer to the unit or something. As it is, it is flawed. |
| 08-20-2008, 03:10 PM | #14 |
> UnitHasConditionOfType may not match up to the buffs actually on it. Uhm... Wha? > WTH is up with your indenting? Nothing? > You should really be recycling timers and dummy units. Why? Can't I just use the struct right now? > If SUNDER isn't the last one, it doesn't work right. That's right, I'll fix it. > There is no support for conditions by adding abilities to the unit, doing trigger actions, etc. What do you mean? > DummyID should be DUMMY_ID or something, as it is a constant. Why? > AddTimedCondition should attach the timer to the unit or something. As it is, it is flawed. Why? |
| 08-20-2008, 04:03 PM | #15 | |||
Quote:
Quote:
Quote:
Also, the library still doesn't compile for me. |
