• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Mount horse ability

Status
Not open for further replies.
Level 11
Joined
Sep 12, 2008
Messages
657
hey.. i'm working on a map atm..
and i've been trying to find a ui,
so i looked thru my old folders and saw a model of a villiager in horse..
and i was wondering if any 1 got time to make me a spell for it?
im too busy working on the actual spells for the map..
i need this:

a spell that creates a dummy unit (dont worry, ill add effect if you want,
im gonna use a smoke effect)
and then it replaces the caster with a mounted unit,
basicly it saves all agi/str/int/exp/level/items/abilities.
abilities gonna be hard part.. so if you cant do it, no matter..
ill just try to find a way to do so. (maybe a variable that each player the number increases by 10)
like this:

player = 1 - 10
player 2 = 11 - 20
player 3 = 21 - 30, and so on.

thanks in advance.

oh and, ill prefer vjass/jass.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
I was thinking of something like this:

JASS:
 scope MountHorse initializer MountHorse
 
    globals
    
        // The ability's rawcode
        private integer ABILITYCODE = 'A000'
        // Thenext four abilities are the hero's abilities
        private integer ABILITY1 = 'AEer'
        private integer ABILITY2 = 'AEfn'
        private integer ABILITY3 = 'AEah'
        private integer ABILITY4 = 'AEtq'
        // Unit type of mounted unit
        private integer MOUNTED = 'Emfr'
        // The effect when replacing a unit
        private string EFFECT = "Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl"
        
        private hashtable MountHash = InitHashtable()
        
    endglobals
 
    private function MountHorse_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local unit v
        local integer ut = GetUnitTypeId( u )
        // Get the ability levels of the unit that gets replaced
        local integer i1 = GetUnitAbilityLevel( u , ABILITY1 )
        local integer i2 = GetUnitAbilityLevel( u , ABILITY2 )
        local integer i3 = GetUnitAbilityLevel( u , ABILITY3 )
        local integer i4 = GetUnitAbilityLevel( u , ABILITY4 )
        local integer i5 = GetUnitAbilityLevel( u , ABILITYCODE )
        // Get unspent skill points
        local integer i6 = GetHeroSkillPoints( u )
        local player p = GetTriggerPlayer()
        local boolean b = IsUnitSelected( u , p )
        
        // This block detects whether the unit is already mounted or not
        // I used that BJ since it's good enough and I didn't want to recode things
        if ut == MOUNTED then
            call ReplaceUnitBJ( u , LoadInteger( MountHash , GetHandleId( u ) , StringHash("type") ) , 1 )
        else
            call ReplaceUnitBJ( u , MOUNTED , 1 )
            call SaveInteger( MountHash , GetHandleId(bj_lastReplacedUnit) , StringHash("type") , ut )
        endif
        
        set v = bj_lastReplacedUnit
        // Create effect
        call DestroyEffect(AddSpecialEffectTarget( EFFECT , v , "origin" ) )
        // This is jsut to make sure the hero has enough skill points to level abilities
        call UnitModifySkillPoints( v , 100 )
        
        // Then following loops make the new unit learn abilities to set them to correct level
        loop
            exitwhen (i1 == 0 )
            call SelectHeroSkill( v , ABILITY1 )
            set i1 = i1 - 1
        endloop
        
         loop
            exitwhen (i2 == 0 )
            call SelectHeroSkill( v , ABILITY2 )
            set i2 = i2 - 1
        endloop
        
         loop
            exitwhen (i3 == 0 )
            call SelectHeroSkill( v , ABILITY3 )
            set i3 = i3 - 1
        endloop
        
         loop
            exitwhen (i4 == 0 )
            call SelectHeroSkill( v , ABILITY4 )
            set i4 = i4 - 1
        endloop
        
        loop
            exitwhen (i5 == 0 )
            call SelectHeroSkill( v , ABILITYCODE )
            set i5 = i5 - 1
        endloop
        
        // Add the new unit to selection
        if b == true and GetLocalPlayer() == p then
            call SelectUnit( v , true )
        endif
        
        // Finally set the number of skill points to correct value
        call UnitModifySkillPoints( v , i6 - GetHeroSkillPoints(v))
        
        set u = null
        set v = null

    endfunction

    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == ABILITYCODE
    endfunction

    
    function MountHorse takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition( t , Condition( function Conditions ) )
        call TriggerAddAction( t , function MountHorse_Actions )
    endfunction
    
endscope

I'm not 100% sure what you're after, let me know if you want to modify it somehow.
 

Attachments

  • Mount Horse.w3x
    19.1 KB · Views: 63
Level 11
Joined
Sep 12, 2008
Messages
657
yeah.. i cant use Ability part cuz of the type of my map..
my map is a 100% create your own hero rpg. you make skills, combine powers, items, etc.
ill test it and edit =]
thanks for trying tho :D (even if its what i need, and even if its not) +rep

edit: wow.. i just looked into UnitReplaceBJ, this is how it is:

JASS:
function ReplaceUnitBJ takes unit whichUnit, integer newUnitId, integer unitStateMethod returns unit
    local unit    oldUnit = whichUnit
    local unit    newUnit
    local boolean wasHidden
    local integer index
    local item    indexItem
    local real    oldRatio

    // If we have bogus data, don't attempt the replace.
    if (oldUnit == null) then
        set bj_lastReplacedUnit = oldUnit
        return oldUnit
    endif

    // Hide the original unit.
    set wasHidden = IsUnitHidden(oldUnit)
    call ShowUnit(oldUnit, false)

    // Create the replacement unit.
    if (newUnitId == 'ugol') then
        set newUnit = CreateBlightedGoldmine(GetOwningPlayer(oldUnit), GetUnitX(oldUnit), GetUnitY(oldUnit), GetUnitFacing(oldUnit))
    else
        set newUnit = CreateUnit(GetOwningPlayer(oldUnit), newUnitId, GetUnitX(oldUnit), GetUnitY(oldUnit), GetUnitFacing(oldUnit))
    endif

    // Set the unit's life and mana according to the requested method.
    if (unitStateMethod == bj_UNIT_STATE_METHOD_RELATIVE) then
        // Set the replacement's current/max life ratio to that of the old unit.
        // If both units have mana, do the same for mana.
        if (GetUnitState(oldUnit, UNIT_STATE_MAX_LIFE) > 0) then
            set oldRatio = GetUnitState(oldUnit, UNIT_STATE_LIFE) / GetUnitState(oldUnit, UNIT_STATE_MAX_LIFE)
            call SetUnitState(newUnit, UNIT_STATE_LIFE, oldRatio * GetUnitState(newUnit, UNIT_STATE_MAX_LIFE))
        endif

        if (GetUnitState(oldUnit, UNIT_STATE_MAX_MANA) > 0) and (GetUnitState(newUnit, UNIT_STATE_MAX_MANA) > 0) then
            set oldRatio = GetUnitState(oldUnit, UNIT_STATE_MANA) / GetUnitState(oldUnit, UNIT_STATE_MAX_MANA)
            call SetUnitState(newUnit, UNIT_STATE_MANA, oldRatio * GetUnitState(newUnit, UNIT_STATE_MAX_MANA))
        endif
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_ABSOLUTE) then
        // Set the replacement's current life to that of the old unit.
        // If the new unit has mana, do the same for mana.
        call SetUnitState(newUnit, UNIT_STATE_LIFE, GetUnitState(oldUnit, UNIT_STATE_LIFE))
        if (GetUnitState(newUnit, UNIT_STATE_MAX_MANA) > 0) then
            call SetUnitState(newUnit, UNIT_STATE_MANA, GetUnitState(oldUnit, UNIT_STATE_MANA))
        endif
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_DEFAULTS) then
        // The newly created unit should already have default life and mana.
    elseif (unitStateMethod == bj_UNIT_STATE_METHOD_MAXIMUM) then
        // Use max life and mana.
        call SetUnitState(newUnit, UNIT_STATE_LIFE, GetUnitState(newUnit, UNIT_STATE_MAX_LIFE))
        call SetUnitState(newUnit, UNIT_STATE_MANA, GetUnitState(newUnit, UNIT_STATE_MAX_MANA))
    else
        // Unrecognized unit state method - ignore the request.
    endif

    // Mirror properties of the old unit onto the new unit.
    //call PauseUnit(newUnit, IsUnitPaused(oldUnit))
    call SetResourceAmount(newUnit, GetResourceAmount(oldUnit))

    // If both the old and new units are heroes, handle their hero info.
    if (IsUnitType(oldUnit, UNIT_TYPE_HERO) and IsUnitType(newUnit, UNIT_TYPE_HERO)) then
        call SetHeroXP(newUnit, GetHeroXP(oldUnit), false)

        set index = 0
        loop
            set indexItem = UnitItemInSlot(oldUnit, index)
            if (indexItem != null) then
                call UnitRemoveItem(oldUnit, indexItem)
                call UnitAddItem(newUnit, indexItem)
            endif

            set index = index + 1
            exitwhen index >= bj_MAX_INVENTORY
        endloop
    endif

    // Remove or kill the original unit.  It is sometimes unsafe to remove
    // hidden units, so kill the original unit if it was previously hidden.
    if wasHidden then
        call KillUnit(oldUnit)
        call RemoveUnit(oldUnit)
    else
        call RemoveUnit(oldUnit)
    endif

    set bj_lastReplacedUnit = newUnit
    return newUnit
endfunction

thats 1 piece of code..
im gonna replace that on my own, and btw..
it'll be easy to edit spells, since ill use a global to declare abilities.. so i guess thats fine =]

thanks, it works perfect.. but 1 question..
i used spell on the un-mounted hero a few times, then i went to mounted hero,
switched him, and he dissapeared? (the second hero, the 1 that starts mounted)
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Yeah, I looked at ReplaceUnitBJ also and it is indeed long. I can create shorter ReplaceUnit if needed.

The one that starts as mounted should not be there. I forgot to remove the unit. If you start mounted when you cast the spell the first time, it won't work, but I can fix that too.
 
Level 11
Joined
Sep 12, 2008
Messages
657
kk, i've remade replace.. mind telling me wth is wrong? (it just channels, then does nothing)

JASS:
 scope MountHorse initializer MountHorse
 
    globals
    
        // The ability's rawcode
        private integer ABILITYCODE = 'A000'
        // Thenext four abilities are the hero's abilities
        private integer ABILITY1 = 'AEer'
        private integer ABILITY2 = 'AEfn'
        private integer ABILITY3 = 'AEah'
        private integer ABILITY4 = 'AEtq'
        // Unit type of mounted unit
        private integer MOUNTED = 'Emfr'
        // The effect when replacing a unit
        private string EFFECT = "Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl"
        
        private integer ItemsAmount = 0
        private item Item
        private integer array ItemCharges
        private integer array ItemId
        
        private hashtable MountHash = InitHashtable()
        
    endglobals
    
    private function SaveItems takes unit u returns nothing
        local integer c = 0
        set ItemsAmount = UnitInventoryCount(u)
            
            loop
            set c = c + 1
                set ItemId[c] = GetItemTypeId(UnitItemInSlot(u, c))
                set ItemCharges[c] = GetItemCharges(UnitItemInSlot(u, c))
            exitwhen c == ItemsAmount
            endloop
    endfunction
    
    private function GetItems takes unit who returns nothing
        local integer c = 0
            
            if ItemsAmount > 0 then
                loop
                set c = c + 1
                    set Item = CreateItem(ItemId[c], GetUnitX(who), GetUnitY(who))
                    call SetItemCharges(Item, ItemCharges[c])
                    call IssueTargetItemOrder(who, "smart", Item)
                    set ItemId[c] = 0
                    set ItemCharges[c] = 0
                    set Item = null
                exitwhen c == ItemsAmount
                endloop
            endif
            
    endfunction
    
    
    private function ReplaceHorse takes unit u returns nothing
        local real life = GetUnitState(u, UNIT_STATE_LIFE)
        local real mana = GetUnitState(u, UNIT_STATE_MANA)
        local integer level = GetUnitLevel(u)
        local integer agi = GetHeroAgi(u, false)
        local integer str = GetHeroStr(u, false)
        local integer int = GetHeroInt(u, false)
        local string name = GetHeroProperName(u)
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local real f = GetUnitFacing(u)
        local player p = GetOwningPlayer(u)
        local string Effect = ""
        local integer id = GetHandleId(u)
        call SaveItems(u)
            call DestroyEffect(AddSpecialEffect(Effect, x, y))
            call RemoveUnit(u)
            set u = CreateUnit(p, LoadInteger( MountHash , id , StringHash("type") ), x, y, f)
        call GetItems(u)
        set u = null
        set p = null
    endfunction
    
    private function ReplaceHuman takes unit u returns nothing
        local real life = GetUnitState(u, UNIT_STATE_LIFE)
        local real mana = GetUnitState(u, UNIT_STATE_MANA)
        local integer level = GetUnitLevel(u)
        local integer agi = GetHeroAgi(u, false)
        local integer str = GetHeroStr(u, false)
        local integer int = GetHeroInt(u, false)
        local string name = GetHeroProperName(u)
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local real f = GetUnitFacing(u)
        local player p = GetOwningPlayer(u)
        local string Effect = ""
        call SaveItems(u)
            call DestroyEffect(AddSpecialEffect(Effect, x, y))
            call RemoveUnit(u)
            set u = CreateUnit(p, MOUNTED, x, y, f)
        call GetItems(u)
        set u = null
        set p = null
    endfunction
    
    private function MountHorse_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local unit v
        local integer ut = GetUnitTypeId( u )
        // Get the ability levels of the unit that gets replaced
        local integer i1 = GetUnitAbilityLevel( u , ABILITY1 )
        local integer i2 = GetUnitAbilityLevel( u , ABILITY2 )
        local integer i3 = GetUnitAbilityLevel( u , ABILITY3 )
        local integer i4 = GetUnitAbilityLevel( u , ABILITY4 )
        local integer i5 = GetUnitAbilityLevel( u , ABILITYCODE )
        // Get unspent skill points
        local integer i6 = GetHeroSkillPoints( u )
        local player p = GetTriggerPlayer()
        local boolean b = IsUnitSelected( u , p )
        
        // This block detects whether the unit is already mounted or not
        // I used that BJ since it's good enough and I didn't want to recode things
        if ut == MOUNTED then
            call ReplaceHorse(u)
        else
            call ReplaceHuman(u)
            call SaveInteger( MountHash , GetHandleId(bj_lastReplacedUnit) , StringHash("type") , ut )
        endif
        
        set v = bj_lastReplacedUnit
        // Create effect
        call DestroyEffect(AddSpecialEffectTarget( EFFECT , v , "origin" ) )
        // This is jsut to make sure the hero has enough skill points to level abilities
        call UnitModifySkillPoints( v , 100 )
        
        // Then following loops make the new unit learn abilities to set them to correct level
        loop
            exitwhen (i1 == 0 )
            call SelectHeroSkill( v , ABILITY1 )
            set i1 = i1 - 1
        endloop
        
         loop
            exitwhen (i2 == 0 )
            call SelectHeroSkill( v , ABILITY2 )
            set i2 = i2 - 1
        endloop
        
         loop
            exitwhen (i3 == 0 )
            call SelectHeroSkill( v , ABILITY3 )
            set i3 = i3 - 1
        endloop
        
         loop
            exitwhen (i4 == 0 )
            call SelectHeroSkill( v , ABILITY4 )
            set i4 = i4 - 1
        endloop
        
        loop
            exitwhen (i5 == 0 )
            call SelectHeroSkill( v , ABILITYCODE )
            set i5 = i5 - 1
        endloop
        
        // Add the new unit to selection
        if b == true and GetLocalPlayer() == p then
            call SelectUnit( v , true )
        endif
        
        // Finally set the number of skill points to correct value
        call UnitModifySkillPoints( v , i6 - GetHeroSkillPoints(v))
        
        set u = null
        set v = null

    endfunction

    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == ABILITYCODE
    endfunction

    
    function MountHorse takes nothing returns nothing
        local trigger t = CreateTrigger(  )
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddCondition( t , Condition( function Conditions ) )
        call TriggerAddAction( t , function MountHorse_Actions )
    endfunction
    
endscope

edit: friend invited me for a 2v2 game, ill finish it and come.. (custom game, so it might take a while =[ i gotta see what i did wrong, thanks! :D)
 
Status
Not open for further replies.
Top