How to make a simple fishing system?

Sevion

The DIY Ninja
Reaction score
413
All you have to do is a terrain check and then an animation set with a timer that runs and on ending that timer, it does a chance check, if it hits, then you give him a fish.
 

.Itap

New Member
Reaction score
0
Is possible you made a demo map?

Is possible made a demo simple fishing system demo map for me ?
 

Sevion

The DIY Ninja
Reaction score
413
Here, try this code.

I just decided to make it.

How to use it:

1. Make a trigger named Fish
2. Convert it to Custom Text (Edit -> Convert To Custom Text)
3. Paste this in there
4. Create a trigger that fires on map initialization.
5. In that trigger, make custom scripts that add your item types.
6. Example:
Trigger:
  • Custom Script: call Fish.addFish('afac')

7. To find your itemtype id's, go to the object editor and do Control + D to display raw data.
8. The itemtype id is the 4 character code on the left of the item's name.
9. To make a unit fish, simply make a custom script like so:
Trigger:
  • Custom Script: call Fish.start(UNIT,CHANCE,TIME,ANIMATION,BOOLEAN)

(Check the documentation for more info)

OR

1. Download the UI files located here: View attachment 1279311703.
2. Extract them to your Warcraft III Directory.
3. Add items to the fish stack via the GUI action:
Trigger:
  • Unit - Add fish

4. Start fishing with units via the GUI action:
Trigger:
  • Unit - Start fish


JASS:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~ 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, 'Apak') < 1 and GetUnitAbilityLevel(whichUnit, 'AInv') < 1 and GetUnitAbilityLevel(whichUnit, 'Aien') < 1 and GetUnitAbilityLevel(whichUnit, 'Aion') < 1 and GetUnitAbilityLevel(whichUnit, 'Aihn') < 1 and GetUnitAbilityLevel(whichUnit, 'Aiun') < 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 doesn'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
 

.Itap

New Member
Reaction score
0
Make a simple fishing system in GUI or MUI?

I'm Not Jass...

Make a simple fishing system in GUI or MUI please?

Sorry My English :(
 

Smilis

TH.net Regular
Reaction score
7
I'm Not Jass...

Make a simple fishing system in GUI or MUI please?

Sorry My English :(

or MUI? MUI and GUI isn't the same thing...

well, can try to make one for you :)

will edit this post with a map in a few hours :)
 

mapguy

New Member
Reaction score
46
try this:

BEWARE, HAND MADE:
Code:
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.
Change the terrain type underwater to an unique type of terrain:
Code:
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.

This is the most simple system I can think...Of course this is shit. But this is simple.
 

Sevion

The DIY Ninja
Reaction score
413
I'm Not Jass...

Make a simple fishing system in GUI or MUI please?

You don't need to know JASS to use this. Just use the functions I showed you. Here, let me quick make a GUI api for it...

Okay, just unzip UI.zip to your WC3 directory and wallah. You have a GUI api for Fish.

It's at the very bottom of the Actions list.

Add your items to the list and then start fishing.

NOTE: ONLY ADD ITEMS TO THE LIST ONCE!
 

Attachments

  • UI.zip
    168.2 KB · Views: 213

Sevion

The DIY Ninja
Reaction score
413
I think is you... :rolleyes:

also that work like EGUI, right? :p I love what you do things like that for gui users x)

Minutes' work o_o'

Not really a whole lot.

(Working on a tool to make it from minutes to seconds <3)
 

.Itap

New Member
Reaction score
0
Fishing System GUI!

Quote : Minutes' work o_o'

Not really a whole lot.

(Working on a tool to make it from minutes to seconds )


GUI MAP ????? SIMPLE FISHING SYSTEM PLEASE !!!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top