| 03-13-2008, 03:03 AM | #1 |
Here is my code: It is a modified version of some very messy Gui code I recently converted. It had alot of boolean functions at the top so I replaced most with one line of code in the ifs. After set a few locals to my needs to make it Mui I got the error "Expected a Name" at the first line in the second function from the top. (Local real x = ....) This trigger is meant to check for all units in an area in front of a unit to damage them if they are within a certain angle near the caster. JASS:function Trig_Basic_Attack_UnitGroupIf takes nothing returns boolean return ( IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(GetSpellAbilityUnit())) == true ) endfunction function Trig_Basic_Attack_Func004A takes nothing returns nothing local real x = ( GetLocationX(GetUnitLoc(GetEnumUnit())) - GetLocationX(GetUnitLoc(udg_Heroes[index])) ) local real y = ( GetLocationY(GetUnitLoc(GetEnumUnit())) - GetLocationY(GetUnitLoc(udg_Heroes[index])) ) set udg_AtkAng[index] = AtanBJ(( y / x )) if ( x > 0.00 ) then if ( y > 0.00 ) then else set udg_AtkAng[index] = ( 360.00 + udg_AtkAng[index] ) endif else set udg_AtkAng[index] = ( 180.00 + udg_AtkAng[index] ) endif if ( And( udg_AtkAng[index] < ( GetUnitFacing(udg_Heroes[index]) + 22.50 ) , udg_AtkAng[index] > ( GetUnitFacing(udg_Heroes[index]) - 22.50 ) ) then call AddSpecialEffectLocBJ( GetUnitLoc(GetEnumUnit()), "Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl" ) call UnitDamageTargetBJ( udg_Heroes[index], GetEnumUnit(), 80.00, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL ) set udg_num = GetRandomInt(1, 6) call PlaySoundOnUnitBJ( udg_sounds[udg_num], 100, udg_Heroes[index] ) else endif endfunction function Trig_Basic_Attack_Actions takes nothing returns nothing local integer index = GetOwningPlayer(GetSpellAbilityUnit()) - 1 call PlaySoundOnUnitBJ( gg_snd_BristleBackMissileLaunch3, 100, udg_Heroes[index] ) call StartTimerBJ( udg_AtkTimer[index], false, 0.90 ) if ( udg_upcheck[index] == true ) then set udg_upcheck[index] = false set udg_uptemp[index] = true else if ( udg_downcheck[index] == true ) then call SetUnitTimeScalePercent(udg_Heroes[index], 100 ) call SetUnitAnimationByIndex(udg_Heroes[index], 1) set udg_downcheck[index] = false set udg_downtemp[index] = true else endif endif call ForGroupBJ( GetUnitsInRangeOfLocMatching(250.00, GetUnitLoc(udg_Heroes[index]), Condition(function Trig_Basic_Attack_UnitGroupIf)), function Trig_Basic_Attack_Func004A ) endfunction //=========================================================================== function InitTrig_Basic_Attack takes nothing returns nothing set gg_trg_Basic_Attack = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Basic_Attack, EVENT_PLAYER_UNIT_SPELL_CAST ) call TriggerAddCondition( gg_trg_Basic_Attack, Condition( GetSpellAbilityId() == 'A001' ) ) call TriggerAddAction( gg_trg_Basic_Attack, function Trig_Basic_Attack_Actions ) endfunction This is giving me quite a headache so any assistance would be greatly appreciated. Also because I am learning any comments on style, neatness and leaks would be welcomed. |
| 03-13-2008, 03:10 AM | #2 |
You forgot a ")" in this line: if ( And( udg_AtkAng[index] < ( GetUnitFacing(udg_Heroes[index]) + 22.50 ) , udg_AtkAng[index] > ( GetUnitFacing(udg_Heroes[index]) - 22.50 ) ) ) then You also have an undefined variable: index |
| 03-13-2008, 04:10 AM | #3 | |
Quote:
OH wow, I'm tired that must be why... And no index is defined in the first part of the trigger. Thanks though for that simple fix. |
| 03-13-2008, 05:13 PM | #4 | |
Quote:
|
| 03-13-2008, 05:59 PM | #5 | |
Quote:
That presents a problem... But to fix it need to make it take an integer variable that I can pass to it? : "function Trig_Basic_Attack_Func004A takes integer index returns nothing" Sry, I'm new to this so, what would the other line look like? : "call Trig_Basic_Attack_Func004A (index)" Is that right? It seemed to work, but that line with the brackets you fixed before is now giving me another problem. It says "Invalid Argument Type (Boolean)" Could you please help with this as well? The line I am referring to: "if ( And( udg_AtkAng[index] < ( GetUnitFacing(udg_Heroes[index]) + 22.50 ) , udg_AtkAng[index] > ( GetUnitFacing(udg_Heroes[index]) - 22.50 ) ) ) then" |
| 03-13-2008, 06:38 PM | #6 |
You could do it that way, but man, your BJ function littered code is really hard to follow. Invest in some better function naming, for starters. (Oh, also, your inittrig declaration won't compile) Actually, you have LOADS of compilation errors. JASS:local integer index = GetOwningPlayer(GetSpellAbilityUnit()) - 1 JASS:function Basic_Attack_Condition takes nothing returns boolean return GetSpellAbilityId() == 'A001' endfunction function Basic_Attack_Check takes nothing returns boolean return IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(GetSpellAbilityUnit())) endfunction function Basic_Attack_Actions takes nothing returns nothing local unit u = GetSpellAbilityUnit() local unit s = null local integer i = GetPlayerId(GetOwningPlayer(u)) local boolexpr b = Condition(function Basic_Attack_Check) local group g = CreateGroup() local real xi = GetUnitX(u) local real yi = GetUnitY(u) local real xf local real yf local real a = 0. //Your calling above of a timer doesn't specify a function callback, so I've no idea what to call. //call TimerStart(udg_AtkTimer[index], 0.9, false, function ...) call PlaySoundOnUnitBJ(gg_snd_BristleBackMissileLaunch3, 100, u) if udg_upcheck[i] then set udg_upcheck[i] = false set udg_uptemp[i] = true elseif udg_downcheck[i] then call SetUnitTimeScale(u, 1.00) call SetUnitAnimationByIndex(u, 1) set udg_downcheck[i] = false set udg_downtemp[i] = true endif call GroupEnumUnitsInRange(g, xi, yi, 250, b) loop set s = FirstOfGroup(g) exitwhen s == null set xf = GetUnitX(s) set yf = GetUnitY(s) set a = 59.29583*Atan2(yf-yi, xf-xi) //That bj v // I have absolutely no idea what you're trying to achieve right now, man. // This doesn't make sense to me, what angle are you trying to get? You are // more than likely doing it wrong. if xf > 0.00 then if yf < 0.00 then set a = (360.00 + a) endif else set a = (180.00 + a) endif if a < GetUnitFacing(u) + 22.50 and a > GetUnitFacing(u) - 22.50 then call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl", xf, yf)) call UnitDamageTarget(u, s, 80., false, false, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL, null) call PlaySoundOnUnitBJ(udg_sounds[GetRandomInt(1,6)], 100, udg_Heroes[index]) endif call GroupRemoveUnit(g, s) endloop call GroupClear(g) call DestroyGroup(g) call DestroyBoolExpr(b) set g = null set b = null set u = null endfunction function InitTrig_Basic_Attack takes nothing returns nothing set gg_trg_Basic_Attack = CreateTrigger() call TriggerRegisterAnyUnitEventBJ(gg_trg_Basic_Attack, EVENT_PLAYER_UNIT_SPELL_CAST) call TriggerAddCondition(gg_trg_Basic_Attack, Condition(function Basic_Attack_Condition)) call TriggerAddAction(gg_trg_Basic_Attack, function Basic_Attack_Actions) endfunction |
| 03-13-2008, 06:58 PM | #7 | |
Quote:
Im gui this trigger worked perfectly to my needs with the exception that I changed certain things from the gui converted code. 1. The "GetConvertedPlayerId" was there first and I misread the function and thought all it did was subtract one from the "GetownedPlayer" but I'll change it to the proper code. 2. Do I have to have the triggers conditions in another function? Even though it is only one condition? 3. Is it faster to set all those locals first? or is it just neater and easier to edit? 4. The callback of the timer (I'm not sure what callback means but I assume it means what it does when it's done) is set in another trigger that sets a few variables to reset all the movement booleans (upcheck,downcheck etc) and resets the animation to walk when the attack animation is done. Could I do this all in one trigger, if so how? 5. The angle is to check for units in about a 45 degree arc in front of the caster. 22.5 degrees on one side 22.5 on the other. Because it is arctangent I have to check for the x and y being in a special spot, otherwise I would get incorrect data when the caster is facing certain directions. Okay, thanks again. As you can see i need more experience in jass but this helps, Thank you. |
| 03-13-2008, 07:03 PM | #8 | |||
Quote:
Quote:
Quote:
|
| 03-13-2008, 08:09 PM | #10 | |||
Quote:
Quote:
Quote:
I recommend my tutorial on timers for further reference into how timers work and should be used. |
| 03-13-2008, 09:17 PM | #11 | |
Quote:
Awsome thank you again. Jeez I've said that alot, but truly thank you! :p It's all well and good but In your tutorial it seems like adding my index variable to the callback function is going to be trouble. But couldn't I just make it part of the function: "function End_Attack takes integer index returns nothing" or is the only method using cache and such? |
| 03-13-2008, 09:58 PM | #12 | ||
Quote:
Quote:
|
| 03-13-2008, 11:32 PM | #13 | |
Quote:
I want to do it your method (tutorial) but what are the dangers? Is there anything special I need to know about game cache or handles to do this? If so where could I find a tutorial for this? Thanks. |
| 03-13-2008, 11:48 PM | #14 | |
Quote:
If for whatever reason you still want the game cache handle functions, you can find them all here. |
| 03-15-2008, 09:23 AM | #15 |
