HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Percent to hit

10-07-2006, 05:19 AM#1
Nubcookie
Hola! I'm making a spell that has a chance to miss based on the distance between the two units. The max range of the spell is 500, which would equal 0% chance to hit. At the range of 100, or less, the spell would have a 100% chance to hit. Here's what I have so far:
Trigger:
Cheap Shot
Collapse Events
Unit - A unit Finishes casting an ability
Collapse Conditions
(Ability being cast) Equal to Cheap Shot
Collapse Actions
Set CheapShot_Distance[(Player number of (Triggering player))] = ((Integer((Distance between (Position of (Triggering unit)) and (Position of (Target unit of ability being cast))))) - 100)
Set CheapShot_Accuracy[(Player number of (Triggering player))] = (CheapShot_Distance[(Player number of (Triggering player))] / 4)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
CheapShot_Accuracy[(Player number of (Triggering player))] Less than or equal to (Random integer number between 0 and 100)
Collapse Then - Actions
Do nothing
Collapse Else - Actions
Floating Text - Create floating text that reads |cff0000Miss!|r above (Triggering unit) with Z offset 0.00, using font size 9.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Floating Text - Change (Last created floating text): Disable permanence
Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
Floating Text - Change the fading age of (Last created floating text) to 0.00 seconds
Floating Text - Set the velocity of (Last created floating text) to 15.00 towards 90.00 degrees
Skip remaining actions
-------- Damage and other affects --------
Will this work? Or is there a better way to go about it?
10-07-2006, 07:27 AM#2
Pheonix-IV
should work, but it leaks a couple of locations and it won't cause the spell to miss.
10-07-2006, 07:33 AM#3
Captain Griffen
Of course, JASS and X and Y co-ordinates as well as locals would be far better.

Though if you are worried about performance, get rid of the location leaks and have only one call to get the player number (then use a temp global), as that is quite a slow call.

If you could, it would also be better to avoid the SquareRoot function in getting the distance. Probably some way of doing it without needing it.
10-07-2006, 09:41 AM#4
arpha_storm
EDIT: Now hits when distance <= 100

Collapse JASS:
function CheapShot_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
    // This is the same as using (Ability being cast) Equal to Cheap Shot
    // A000 is the rawcode of the Cheap Shot ability in your Object Editor.
    // You probably know this.
endfunction

function CheapShot takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target = GetSpellTargetUnit()
    local real dx = (GetUnitX(target) - GetUnitX(caster))
    local real dy = (GetUnitY(target) - GetUnitY(caster))
    local real distance = SquareRoot(dx * dx + dy * dy) // sorry, but it's a necessary evil, unless there's some other way
    local integer rand = GetRandomInt(1, 100)
    local integer accuracy = ((R2I(distance) - 100) / 4)

    if ((accuracy >= 1) and (accuracy <= rand)) or (distance <= 100) then
        // do damage stuff here
        call UnitDamageTarget(caster, target, 500.0, true, true, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    else
        call AddFadingTextTag("Miss!", 9.0, GetUnitX(caster), GetUnitY(caster), 40.0, 3, 255, 0, 0, 255)
    endif
    set caster = null
    set target = null
endfunction

//===========================================================================
function InitTrig_CheapShot takes nothing returns nothing
    set gg_trg_CheapShot = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_CheapShot, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_CheapShot, Condition(function CheapShot_Conditions))
    call TriggerAddAction(gg_trg_CheapShot, function CheapShot)
endfunction

This will miss when distance between caster and target is less than 100 (0% accuracy). You can change your accuracy formula though.

Also, add this to your custom script section (when using the JASSed CheapShot):
Hidden information:
Collapse JASS:
function AddFadingTextTag takes string text, real fontsize, real x, real y, real height, real lifespan, integer red, integer green, integer blue, integer alpha returns nothing
    local texttag t = CreateTextTag()
    call SetTextTagText(t, text, fontsize * 0.024 / 10)
    call SetTextTagPos(t, x, y, height)
    call SetTextTagColor(t, red, green, blue, alpha)
    call SetTextTagVelocity(t, 0, 0.03)
    call SetTextTagVisibility(t, true)
    call SetTextTagFadepoint(t, 2)
    call SetTextTagLifespan(t, lifespan)
    call SetTextTagPermanent(t, false)
    set t = null
endfunction


It's made by Blade.dk, though I edited some of it, so give credit to Blade (if you use it).

Sorry, can't help you in GUI >_<
10-07-2006, 01:01 PM#5
zen87
Quote:
Originally Posted by Nubcookie
Hola! I'm making a spell that has a chance to miss based on the distance between the two units. The max range of the spell is 500, which would equal 0% chance to hit. At the range of 100, or less, the spell would have a 100% chance to hit. Here's what I have so far:
Trigger:
Cheap Shot
Collapse Actions
Set CheapShot_Distance[(Player number of (Triggering player))] = ((Integer((Distance between (Position of (Triggering unit)) and (Position of (Target unit of ability being cast))))) - 100)
Will this work? Or is there a better way to go about it?
the [Player number of (Triggering player)] wont work, i guess, again, it should be [Player number of (owner of (triggering unit))]
10-07-2006, 01:22 PM#6
darkwulfv
Quote:
the [Player number of (Triggering player)] wont work, i guess, again, it should be [Player number of (owner of (triggering unit))]
Your're right, it should be [Player number of (owner of (triggering unit))], as there are no player events.
10-08-2006, 02:41 AM#7
Nubcookie
Thank you for the help! +rep <3