• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJass] Sw*ne Flu ! 1.1b

it even infected hive ? o_O



Each unit which comes in range of this unit has a chance of getting infected by the Swine Flu and take damage over time. Each infected unit also has a lower chance to infect others. The Flu disappears after some seconds if the unit is not reinfected. The chance of Infection raises per level.



v1.01
-fixed tooltips
-added a change for infecting units
-specified various adjustable values for infection
-improved scrip


Why does the Spell lasts longer than the tooltip says?
-The effect will only disappear if the unit is not reinfected, means groups will reinfect themselfs

Whats about the bounty? Who does get the kill ?
-the owner of the beginning of the epidemic will be saved in the unit and transported that nothing gets messed up. Means if your hero infects a unit which will reinfect many others you will get bounty for them.

Why does this unit is not getting affected?
-There is a condition for the infection. Also you cannot infect units with the Swine Flu Skill like the test hero.

Can i infect other units which got infected before of an other player?
- Yes thats possible but only if your Flu has a higher level than the already infected. Else you must wait till its effect wears of.



JASS:
//////////////////////////////////////Globals with important values////////////////////////////////////////

scope SwineFlu

globals
    // The interval all units get checkes of bein infected / reinfected, higher values will increse the possible spread speed
    private real TimerPeriod = 0.5
    
    //your passive Swine Flu spell the hero must have
    private integer SwineFluSpell = 'A000'
    
    //The effect spell which is casted on enemys and causes their pain
    private integer SwineFluSpellEffect = 'A002'
    
    //The id of a dummy used to cast the spell above when a unit gets infected/ reinfected
    private integer CastDummyID =  'h002'
    
    //The buff an infected uni got of the effect spell 
    private integer SwineFluBuffCode = 'B000'
    
    //The order id of the effect spell
    private string EffectOrderID = "unholyfrenzy"
    
    // Do not change the following
    private group Infected = CreateGroup()
    private group g = CreateGroup()
    private timer t = CreateTimer()
    private boolexpr filter = null
endglobals


///////////////////////////////////Defining most relevant Values////////////////////////////////////////////////

//Defines how long an infection will last without any reinfactions
private function DurationPerLevel takes integer level returns integer
    return 2 + level
endfunction

//Defines the infection range of the hero spreading the flu
private constant function InfectionRange takes real level returns real
    return 175 + 25 * level 
endfunction

//Defines the infection range of an infected unit
private constant function InfectedInfectionRange takes real level returns real
    return 175 + 25 * level 
endfunction

//Defines the chance per interval to infect a unit with the hero 
private constant function InfectionChance takes real level returns real
    return 0.2+0.15*level
endfunction

//Defines the chance per interval of an infected unit to infect another 
private constant function InfectedInfectionChance takes real level returns real
    return 0.12
endfunction

//The conditions a unit can be infected 
private function InfectCondition takes unit a, player p returns boolean
    return not(IsUnitType(a, UNIT_TYPE_MECHANICAL)) and not(IsUnitType(a, UNIT_TYPE_MAGIC_IMMUNE)) and (GetWidgetLife(a) > 0) and IsPlayerEnemy(GetOwningPlayer(a),p) // The condition if a unit is infected
endfunction

 //The condition if trigger should run (refers to the event : EVENT_PLAYER_HERO_SKILL)
private function RunCondition takes nothing returns boolean
    return (GetUnitAbilityLevel(GetTriggerUnit(),SwineFluSpell) != 0)
endfunction

//////////////////////////////////Main Struckt//Do not change//////////////////////////////////////////////

private struct Infection
    static integer Index = 0
    static Infection array Data
    integer left 
    unit u = null
    player p 
    integer level 
    static method create takes nothing returns Infection
        local Infection data = Infection.allocate()
        set Infection.Data[Infection.Index] = data
        set Infection.Index = Infection.Index + 1
        return data
    endmethod
endstruct

////////////////////////////////Main script// Do not edit unless you understand it////////////////////////////////

private function AddSwineFlu takes unit target, integer level, player a returns nothing
    local unit dummy = CreateUnit(a,CastDummyID,GetUnitX(target),GetUnitY(target),0)
    call UnitAddAbility(dummy,SwineFluSpellEffect)
    call SetUnitAbilityLevel(dummy,SwineFluSpellEffect,level)
    call UnitApplyTimedLife(dummy, 'BTLF', 0.75)
    call IssueTargetOrder( dummy,  EffectOrderID,target)
    set dummy = null
endfunction

private function GetStructOfUnit takes unit u returns integer
    local Infection data
    local integer i = 0
    loop
        exitwhen i >= Infection.Index
        set data = Infection.Data[i]
        if data.u == u then 
            return i
        endif
        set i = i +1
    endloop
    return 0        
endfunction

private constant function NullFilter takes nothing returns boolean
    return true
endfunction

function Callback takes nothing returns nothing
    local Infection data
    local integer i = 0
    local integer ii = 0
    local integer level = 0
    local unit b 
    local unit a
    local real x 
    local real y
    local real c 
    local integer max = Infection.Index
    loop //looping through all structs
        exitwhen i >= max
        set data = Infection.Data[i]
        set a = data.u
        if (GetWidgetLife(a) > 0) and (data.left != 0) then //buff gets removed +  struct destroey if the unit is dead or its infection timer expires
            if data.left != -1 then
                set data.left = data.left-1 // decreases infection timer , -1 means its forever (in this case for your hero)
            endif
            set level = data.level
            set x = GetUnitX(a)
            set y = GetUnitY(a)
            if GetOwningPlayer(a) == data.p then
                call GroupEnumUnitsInRange(g, x, y,InfectionRange(I2R(data.level)), filter) 
            else
                call GroupEnumUnitsInRange(g, x, y,InfectedInfectionRange(I2R(data.level)), filter) 
            endif
            call GroupRemoveUnit(g,a)
            loop //looping through all units in range
                set b = FirstOfGroup(g)            
                exitwhen b == null
                call GroupRemoveUnit(g,b)
                set ii = GetStructOfUnit(b)
                set c = GetRandomReal(0.00,1.00)
                if ((c < InfectionChance(data.level) and GetOwningPlayer(a) == data.p) or (c < InfectedInfectionChance(data.level) and GetOwningPlayer(a) != data.p)) and InfectCondition(b,data.p) == true and ((Infection.Data[ii].left != -1) or not(IsUnitInGroup(b,Infected)))then
                    if not(IsUnitInGroup(b,Infected)) then
                        //Infecting the target 
                        call GroupAddUnit(Infected,b)   
                        call AddSwineFlu(b,data.level,data.p)
                        call Infection.create()
                        set Infection.Data[Infection.Index-1].u = b
                        set Infection.Data[Infection.Index-1].p = data.p
                        set Infection.Data[Infection.Index-1].level = data.level
                        set Infection.Data[Infection.Index-1].left = R2I(I2R(DurationPerLevel(data.level))/TimerPeriod)                        
                    else
                        //Reinfecting the target
                        if Infection.Data[ii].level < data.level then
                            set Infection.Data[ii].level = data.level
                            set Infection.Data[ii].p = data.p
                            call AddSwineFlu(b,data.level,data.p)
                            set Infection.Data[ii].left = R2I(I2R(DurationPerLevel(data.level))/TimerPeriod)    
                        else 
                            set Infection.Data[ii].left = R2I(I2R(DurationPerLevel(data.level))/TimerPeriod)    
                        endif
                    endif 
                endif
            endloop
        else 
            //detroying struct + removing buff
            call UnitRemoveAbility(data.u, SwineFluBuffCode)
            call GroupRemoveUnit(Infected,data.u)
            set data.u = null
            set data.p = null
            call Infection.destroy(data)
            set ii = i
            loop                
                exitwhen ii == Infection.Index
                set Infection.Data[ii] = Infection.Data[ii+1]
                set ii = ii + 1
            endloop
            set i = i -1
            set Infection.Index = Infection.Index - 1
            set max = max - 1            
        endif
        set i = i + 1
        set ii = 0
        set level = 0
    endloop
    set a = null
    set b = null
endfunction

function Swine_Flu_Actions takes nothing returns nothing
    local integer i
    local unit u = GetTriggerUnit()
    if IsUnitInGroup(u,Infected) then 
        //modifing the current struct if the unit had Swineflue before
        set i = GetStructOfUnit(u)
        set Infection.Data[i].p = GetOwningPlayer(u)
        set Infection.Data[i].level = GetUnitAbilityLevel(u,SwineFluSpell)
    else
        //creating the struct and adding the hero
        call GroupAddUnit(Infected,u)
        call Infection.create()
        set Infection.Data[Infection.Index-1].u = u
        set Infection.Data[Infection.Index-1].left = -1
        set Infection.Data[Infection.Index-1].p = GetOwningPlayer(u)
        set Infection.Data[Infection.Index-1].level = GetUnitAbilityLevel(u,SwineFluSpell)
        if Infection.Data[Infection.Index-1].Index == 1 then
            call TimerStart(t, TimerPeriod, true, function Callback)
        endif
    endif
    set u = null
endfunction

//===========================================================================
function InitTrig_Swine_Flu takes nothing returns nothing
    local integer index
    local boolexpr cond = Condition( function RunCondition )
    set filter = Filter(function NullFilter)
    set gg_trg_Swine_Flu = CreateTrigger(  )
    set index = 0
    loop
        call TriggerRegisterPlayerUnitEvent(gg_trg_Swine_Flu, Player(index),EVENT_PLAYER_HERO_SKILL, filter)
        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
    call TriggerAddCondition( gg_trg_Swine_Flu, cond )
    call TriggerAddAction( gg_trg_Swine_Flu, function Swine_Flu_Actions )
    set cond = null
endfunction

endscope

Keywords:
Swine, Flu, Epidemic, Infect, Infection, Pig, JonNny, vJass
Contents

Noch eine WARCRAFT-III-Karte (Map)

Reviews
17:55, 7th Oct 2009 TriggerHappy187: Im approving this though there could still be some improvements.
Level 4
Joined
Mar 14, 2009
Messages
98
It's not like disease cloud at all. Well, I guess it's similar, being a DoT with the same special effects and all. However, this spell is more like that Plague spell from DotA -- those who get infected can infect other units.

Good work!
 
Level 15
Joined
Jul 19, 2007
Messages
618
lol XD Swine Flu!

anyway nicely done, here few coding things:

1. I2R(level)*I2R(level) can be I2R(level*level)
2. Would be that i noticed you are using your own Infection.Data[] index system but you still use .allocate for that.

In order to reduce variables generated by struct as well as allocator and destructor make your struct extend array

JASS:
struct some extends array
    integer i
    real x
    static integer CurrId = 0

     static method create takes nothing returns thistype
         local thistype this = thistype(thistype.CurrId+1)
         
         set this.i = 6
         set this.x = 3.14159
         set thistype.CurrId = integer(this)

          return (this)
     endmethod

     public method free takes nothing returns nothing
         local thistype last = thistype(thistype.CurrId)
         set this.i = last.i
         set this.x = last.x
         set last.i = 0
         set last.x = 0.
         set thistype.CurrId = integer(last) - 1
     endmethod
endstruct

local some s = some.create()
local some array sarr
local integer i = 1
set s.i = 53
set sarr[0] = some.create()
set sarr[1] = some.create()
set sarr[1].i = sarr[0].i * 3

loop
exitwhen (i > some.CurrId)
    call BJDebugMsg(I2S(some(i).i))
    set i = i + 1
endloop

// this up will display:
53
6
18
// continue code

call s.free()
call sarr[0].free()
call sarr[1].free()

if you do all that structs do not need extra variables and you dont need that array variable + vjass does not generate destroy and allocate methodes.

i think you will find great use of this!


Other then that spell is good works fine is MUI, Leakfree, Bugfree, Speed is good enough 0.5 or 2 FPS is really fast so people with slow CPU will have no lagg...

well 5/5!
Greets!
~Dark Dragon
 
Level 15
Joined
Jan 31, 2007
Messages
502
no funny lol ppl can die from swine flu! OH NOES!

My intention was not to make fun about the illness itself. Sure its a serous theme and we should think about it but it still gave me the idea to create this... I think too many people do not really think about it. i mean.. the tourists rates in mexica only decreased by 30% or sth.. thats a perfect way to spread it all over thw world. i hope it will end up like BSE or sth.
If some people dislike the name i can rename it because basicly its a simple disease

Septimus said:
Sounds like abomination disease cloud ability.
hmm.. right.. i never really played undead.. its quie similar .. but it has major differences.
yes it infects units which will take damage over time but they will be able reinfect others. Also the strengh of this spell is to infect groups which will reinfect their selves and keep the infection alive.


hmm.. thx, Dark_Dragon
Thats a quite nice aspect.. i will think about using such a similar thing ...
 
Level 6
Joined
Sep 13, 2008
Messages
261
I really like the idea of a swine flu ability, but I think you should make it so a unit casts it and the pig should stampede forth across the field infecting everyone. Then it's usable by other units and still makes since.
 
Level 8
Joined
Apr 7, 2008
Messages
176
Spell works great. I love it. It even lets the higher levels takeover the lower levels as stated. And actually kills units, I got on Yahoo this morning and found out that Swine Flu can kill Americans! OH NO!
It would cool if it caused some sort of panic within the groups of units that are infected. Like randomly some of them become Feared and begin to run around all crazy and some people dont care. Just an idea. Kinda like the RL.
 
Level 15
Joined
Jan 31, 2007
Messages
502
Hmm.. funny idea but the main part of this spell should be the disease itself and not other special scripted effects. But the Spell effect for the disease is free editable, means you could instead spread a silence or whatever


hmm.. this brought me to the idea that this with could easily changed into a motivation spell with edited tooltips, a commander hero and a positive effect speading over allies only :p would be a 2 min edit time
sth like "Teamwork" or whatever, that the commander motivades his allies which got a damage bonus and will be able to motivade others. Then the effect would wear off after being alone for some time loosing the motivation...
rofl that would also be awesome, now even i could have a use of it for my survival xD
 
Level 12
Joined
Jan 6, 2009
Messages
848
I guess the spell is nice but...
People can react very strongly to this, as the Swine Flu is an existing FATAL disease...
Anyways, nice job^^
 
Level 12
Joined
Feb 11, 2008
Messages
809
Yea its a nice spell ill give it a 5/5 but at the same time i had swine flu a while back and am now over it i had to take a ton of antibiotics and stuff and this spell is a perfect description of what the swine flu does since i gave it to everyone else in my household lmao.
 
Level 8
Joined
Aug 1, 2008
Messages
420
This is just wrong on so many levels >.>

Anyway, i thought the spell was alright, nothing very good going on though.
 
Level 15
Joined
Jan 31, 2007
Messages
502
many people are getting killed by katanas , no joke

i could name it BSE or whatever i guess then noone would be so serious about it
I think media make everythink worse than it actually is (does not mean that it IS not sad that people die of it and i never said its fun)

yesterday it was bird flu , today its swine flu.. maybe tomorrow its cat flu
but if i got time and motivation ill overwork and rename such things...
 
Level 12
Joined
Jan 6, 2009
Messages
848
Hey, you're right o_O
People get killed everyday(i guess) and their family and friends get permanent emotional scars, and in warcraft units are killed en masse, but no1 complains :O
 
Code critique.

  • local boolexpr cond = Condition( function RunCondition ) <- is useless, it just adds two extra lines.
  • You don't need to inline the event, the BJ is perfectly fine.
  • You may want to think of only using a condition thread instead of combining actions/conditions. It creates one less thread and saves a function call. Like this;
    JASS:
    private function Actions takes nothing returns boolean
        if YOUR_CONDITION then
            // Do actions
        endif
        return false
    endfunction
    
    private function onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterSomeEvent(t)
        call TriggerAddCondition(t, Condition(function Actions))
    endfunction
  • In your callback function, set b = null is unneeded. It will be null anyways (exitwhen b == null)
  • All these O(n) searches could be replaced with an attachment system, though if you want your spell to be system independant I understand.
 
Level 5
Joined
Apr 19, 2009
Messages
165
the map does not work with wc3 v1.24 and i tried to copy and paste and fix it up so it works in my tes map but there were countless errors....

edit: was not using newgen XD
 
Last edited:
Top