| 09-18-2007, 10:16 AM | #1 |
Basically its an item ability that creates waves or electrical energy behind the attacked unit. Just 2 questions. One the casterdummies however sometimes move, which looks good actually because they move together and such however why do they do that? And 2 it works just fine however is there anything that I should do to it or is it fine as is? JASS:function damage takes nothing returns nothing call IssueTargetOrder( GetLastCreatedUnit(), "chainlightning", GetEnumUnit() ) endfunction function Trig_coccast_Actions takes nothing returns nothing local location attacker local location attacked local real pi local real angle local location temppt local unit attacker_U local player damager local integer I local integer O local real tempangle local real dist local unit tmpunt local group g = CreateGroup() set I = 1 set O = 0 set attacker_U = GetAttacker() set damager = GetOwningPlayer(attacker_U) set pi = 3.14159 set attacker = GetUnitLoc(attacker_U) set attacked = GetUnitLoc(GetTriggerUnit()) set angle = AngleBetweenPoints(attacker, attacked) if angle > 180 then set angle = angle + 180 endif set dist = 50 set temppt = PolarProjectionBJ(attacked, dist, angle) set tmpunt = CreateUnitAtLoc( damager, 'h002', temppt, bj_UNIT_FACING ) call RemoveLocation(temppt) call UnitApplyTimedLife( 5.00, 'BTLF', tmpunt ) call PolledWait(0.25) loop exitwhen I == 5 set I = I + 1 set O = 0 set dist = dist + 50 loop exitwhen O == I + 2 set O = O + 1 set tempangle = (angle - 45) + ( (O-1) * (45/I) ) set temppt = PolarProjectionBJ(attacked, dist, tempangle) set tmpunt = CreateUnitAtLoc( damager, 'h002', temppt, bj_UNIT_FACING ) set g = GetUnitsInRangeOfLocAll(50.00, GetUnitLoc(GetLastCreatedUnit())) call ForGroupBJ( g , function damage ) call RemoveLocation(temppt) call UnitApplyTimedLife( 2.00, 'BTLF', tmpunt ) call DestroyGroup(g) endloop call PolledWait(0.25) endloop endfunction function Trig_coccast_Conditions takes nothing returns boolean return (UnitHasItemOfTypeBJ(GetAttacker(), 'I000') and GetUnitTypeId(GetAttacker()) == 'Ntin') endfunction //=========================================================================== function InitTrig_coccast takes nothing returns nothing set gg_trg_coccast = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_coccast, EVENT_PLAYER_UNIT_ATTACKED ) call TriggerAddCondition( gg_trg_coccast, Condition( function Trig_coccast_Conditions ) ) call TriggerAddAction( gg_trg_coccast, function Trig_coccast_Actions ) endfunction |
| 09-18-2007, 01:30 PM | #2 |
A couple of things to optimize/oragnize your code: 1. You can set the value of locals when you declare them. For instance: JASS:set attacker_U = GetAttacker() can be written as JASS:local unit attacker_U = GetAttacker() Two command I wished I learned earlier are: JASS:GetUnitX(whichunit) GetUnitY(whichunit) |
| 09-18-2007, 02:19 PM | #3 |
I actually wrote it the first time without the BJ's but then i found AngleBetweenPoints which saved me a lot of math so I went with it :P ill change the declarations in the beginning as well |
| 09-18-2007, 11:17 PM | #4 |
And instead of the big 2 if's you can just use "return CONDITION" |
| 09-19-2007, 12:15 AM | #5 |
what do you mean? |
| 09-19-2007, 05:33 AM | #6 |
You could search on Wc3JASS.com and find this handy-dandy function: JASS:function AngleBetweenPointsXY takes real X1, real Y1, real X2, real Y2 returns real return Atan2((Y2-Y1),(X2-X1))*bj_RADTODEG endfunction He's saying that instead of this: JASS:function Trig_coccast_Conditions takes nothing returns boolean if ( not ( UnitHasItemOfTypeBJ(GetAttacker(), 'I000') == true ) ) then return false endif if ( not ( GetUnitTypeId(GetAttacker()) == 'Ntin' ) ) then return false endif return true endfunction JASS:function Trig_coccast_Conditions takes nothing returns boolean return (UnitHasItemOfTypeBJ(GetAttacker(), 'I000') and GetUnitTypeId(GetAttacker()) == 'Ntin') endfunction Oh, and your code has a major flaw in that it runs off the "Attacked" event. That event actually fires when a unit begins the attack. Try it by continually ordering a unit to attack the same target with A+Click and you'll see that even fire over and over again without any damage occurring. |
| 09-20-2007, 04:51 AM | #7 |
actually I tried that and it didn't continually fire I thought it would but i tested it multipul times and it never did. I believe this is because this unit has 0.00 backswing EDIT: I changed the BJ's however still the PolarProjectionBJ and the ForGroupBJ seem just fine, I did notice there is a built in ability to destroy groups in the ForGroupBJ so how would I use that or is it just pointless? I dont see how a "Atan2((Y2-Y1),(X2-X1))*bj_RADTODEG" is any different then the "bj_RADTODEG * Atan2(GetLocationY(locB) - GetLocationY(locA), GetLocationX(locB) - GetLocationX(locA))" considering I would have to call the GetLocation X,Y in the parent function to use that so there is no difference in the number of function calls... I would understand a point to doing that if Atan2 was Atan2BJ but its not... Also wouldn't it take actually MORE memory to pass 4 values to a function instate of 2 points? |
| 09-21-2007, 02:07 AM | #8 |
Locations. Are. Bad. Drill it in to your brain now and never forget it. You should always work in X/Y coordinates except in special cases (like maybe when using GetLocationZ(...)). |
| 09-21-2007, 03:57 AM | #9 |
Why. Are. Locations. Bad? You should know me well enough to know I would want to know the why :P oh and nice punctuation ^.^ |
| 09-21-2007, 04:55 AM | #10 |
And if I am right, there is a constant bj_PI you can use, saving an innocent variable ;P BTW, for question one, maybe the dummies have attack and they try to engage the enemies? If that is the case then you should disable the attack. |
| 09-21-2007, 04:57 AM | #11 |
they are based off the peon unit and ONLY started doing this move thing when I made them cast chain lightning instade of just doing a triggered damage |
| 09-21-2007, 06:07 AM | #12 |
Locations are slow, inflexible, and are handles that must be cleaned when used. It's best to avoid the creation of new handles whenever possible. |
| 09-21-2007, 08:10 AM | #13 |
but...but...but... i like locations waaaa!!! :P ne ways any ideas on the moving units thing? its kinda interesting that they move together but to a degree that they are from units that are nearby (but not in) the area of effect EDIT also they only started it when i decided to have them cast chain lightning instate of just doing triggered damage |
