//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~ Fish ~~ By Sevion ~~ Version 1.0.0.0 ~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// What is Fish?
// -Fish is an easy way to make units "fish" for items.
//
// API:
// -struct Fish extends array
// -real chance
// The chance to "fish" an item.
//
// -real time
// The duration of the "fishing".
//
// -animation
// The animation to play while "fishing".
//
// - static method start takes unit whichUnit, real chance, real time, string animation, boolean checkOnTick returns thistype
// Creates a fishing instance.
//
// - static method stop takes unit whichUnit returns nothing
// Stops a fishing instance.
//
// - method destroy takes nothing returns nothing
// Stop a fishing instance.
//
// - static method addFish takes integer id returns nothing
// Add a fish to the stack.
//
// - static method removeFish takes integer id returns nothing
// Remove a fish from the stack.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
native UnitAlive takes unit whichUnit returns boolean
library Fish
globals
private constant real PERIOD = 0.0325
endglobals
private struct FishArray extends array
public static integer instanceCount = 0
private static integer array recycle
private static integer recycleCount = 0
public thistype next
public thistype prev
public integer type
public static method create takes nothing returns thistype
local thistype this
if ( recycleCount != 0 ) then
set recycleCount = recycleCount - 1
set this = recycle[recycleCount]
else
set instanceCount = instanceCount + 1
set this = instanceCount
endif
set thistype(0).next.prev = this
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
return this
endmethod
public method destroy takes nothing returns nothing
set recycle[recycleCount] = this
set recycleCount = recycleCount + 1
set this.next.prev = this.prev
set this.prev.next = this.next
endmethod
endstruct
struct Fish extends array
private static integer instanceCount = 0
private static integer array recycle
private static integer recycleCount = 0
private static timer timer = CreateTimer()
private static hashtable hash
private thistype next
private thistype prev
private unit unit
private real chanceX
private real timeX
private real increment
private real tick
private string animX
private boolean bool
private static method periodic takes nothing returns nothing
local thistype this = thistype(0).next
if ( this == 0 ) then
call PauseTimer(thistype.timer)
return
endif
loop
exitwhen this == 0
if ( not UnitAlive(this.unit) ) then
call this.destroy()
endif
set this.tick = this.tick + PERIOD
call SetUnitAnimation(this.unit, this.animX)
if ( this.bool ) then
if ( GetRandomReal(0, 1.00) <= this.chanceX ) then
call UnitAddItem(this.unit, CreateItem(FishArray(GetRandomInt(1, FishArray.instanceCount)).type, GetUnitX(this.unit), GetUnitY(this.unit)))
endif
elseif ( this.tick >= this.timeX ) then
if ( GetRandomReal(0, 1.00) <= this.chanceX ) then
call UnitAddItem(this.unit, CreateItem(FishArray(GetRandomInt(1, FishArray.instanceCount)).type, GetUnitX(this.unit), GetUnitY(this.unit)))
endif
endif
if ( this.tick > this.timeX ) then
call this.destroy()
endif
set this = this.next
endloop
endmethod
public method operator chance takes nothing returns real
return this.chanceX
endmethod
public method operator time takes nothing returns real
return this.timeX
endmethod
public method operator animation takes nothing returns string
return this.animX
endmethod
public method operator chance= takes real chance returns nothing
set this.chanceX = chance
endmethod
public method operator time= takes real time returns nothing
set this.timeX = time
endmethod
public method operator animation= takes string animation returns nothing
set this.animX = animation
endmethod
public static method start takes unit whichUnit, real chance, real time, string animation, boolean checkOnTick returns thistype
local thistype this
debug if ( FishArray(0).next == 0 ) then
debug call BJDebugMsg("Error (Fish): No fish in the stack!")
debug return 0
debug endif
debug if ( not UnitAlive(whichUnit) ) then
debug call BJDebugMsg("Error (Fish): Specified unit is dead!")
debug return 0
debug endif
debug if ( GetUnitAbilityLevel(whichUnit, 039;Apak039;) < 1 and GetUnitAbilityLevel(whichUnit, 039;AInv039;) < 1 and GetUnitAbilityLevel(whichUnit, 039;Aien039;) < 1 and GetUnitAbilityLevel(whichUnit, 039;Aion039;) < 1 and GetUnitAbilityLevel(whichUnit, 039;Aihn039;) < 1 and GetUnitAbilityLevel(whichUnit, 039;Aiun039;) < 1 ) then
debug call BJDebugMsg("Error (Fish): Unit has no inventory!")
debug return 0
debug endif
if ( recycleCount != 0 ) then
set recycleCount = recycleCount - 1
set this = recycle[recycleCount]
else
set instanceCount = instanceCount + 1
set this = instanceCount
endif
set thistype(0).next.prev = this
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
call SaveInteger(thistype.hash, GetHandleId(whichUnit), 0, this)
set this.unit = whichUnit
set this.chanceX = chance
set this.timeX = time
set this.tick = 0
set this.animX = animation
set this.bool = checkOnTick
call ResumeTimer(thistype.timer)
return this
endmethod
public static method stop takes unit whichUnit returns nothing
debug if ( whichUnit == null ) then
debug call BJDebugMsg("Error (Fish): Specified unit doesn039;t exist!")
debug return
debug endif
call thistype(LoadInteger(thistype.hash, GetHandleId(whichUnit), 0)).destroy()
endmethod
public method destroy takes nothing returns nothing
call SetUnitAnimation(this.unit, "stand")
set recycle[recycleCount] = this
set recycleCount = recycleCount + 1
set this.next.prev = this.prev
set this.prev.next = this.next
endmethod
public static method addFish takes integer id returns nothing
local FishArray this = FishArray.create()
set this.type = id
call SaveInteger(thistype.hash, id, 1, this)
endmethod
public static method removeFish takes integer id returns nothing
call FishArray(LoadInteger(thistype.hash, id, 1)).destroy()
endmethod
private static method onInit takes nothing returns nothing
call TimerStart(thistype.timer, PERIOD, true, function thistype.periodic)
set thistype.hash = InitHashtable()
endmethod
endstruct
endlibrary
I'm Not Jass...
Make a simple fishing system in GUI or MUI please?
Sorry My English
A unit starts the effect of an ability
Ability beeing cast equal to fishing.
Set random_fish = random number between 1 and 3
If random_fish equal to 1 then add red fish to triggering unit inventory.
If random_fish equal to 2 then add blue fish to triggering unit inventory.
If random_fish equal to 3 then add yellow fish to triggering unit inventory.
A unit beguins casting an ability
ability beeing cast equal to fishing
set X = target point of ability beeing cast.
If terrain type at X not equal to (YOUR TERRAIN) then do actions.
------Pause triggering unit
------Order triggering unit to stop
------Unpause triggering unit.
I'm Not Jass...
Make a simple fishing system in GUI or MUI please?
Who?
I think is you...
also that work like EGUI, right? I love what you do things like that for gui users x)