wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Tutorials > JASS/AI scripts tutorials
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 03-24-2007, 03:48 AM   #1
Hero12341234
User
 
Hero12341234's Avatar
 
Join Date: Feb 2006
Posts: 111

Submissions (1)

Hero12341234 is on a distinguished road (10)

Default Tutorial: Creating a Tree Revival System

Tutorial: Creating a Tree Revival System

This will show you how to write a Tree Revival System in JASS.

Please Give Some Kind of Credit if you use this system.

Question:
I don't know JASS can you make a GUI one?

Answer:
If you don't know JASS it's ok..I explained everything...you can't possibly make a mistake..if you do try to copy and paste. Or use the sample map located below all this text.

Copy and Paste these functions below into your map's custom header.


Collapse JASS:
constant function TreeRegrowTime takes nothing returns real
    return 10.00 //the amount of time you want before the tree respawns
endfunction

To add more trees press CTRl+D while looking at the Object Editor
then follow the same format and add your tree's RAWCODE inside single quotes (Example ' ' )

function IsDesTree takes destructable a returns boolean
    local integer d=GetDestructableTypeId(a)
    if d =='ATtr' then
      return true
    elseif d=='BTtw' then
      return true
    elseif d=='KTtw' then
      return true
    elseif d=='YTft' then
      return true
    elseif d=='JTct' then
      return true
    elseif d=='YTst' then
      return true
    elseif d=='YTct' then
      return true
    elseif d=='YTwt' then
      return true
    elseif d=='JTwt' then
      return true
    elseif d=='DTsh' then
      return true
    elseif d=='FTtw' then
      return true
    elseif d=='CTtr' then
      return true
    elseif d=='ITtw' then
      return true
    elseif d=='NTtw' then
      return true
    elseif d=='OTtw' then
      return true
    elseif d=='ZTtw' then
      return true
    elseif d=='WTst' then
      return true
    elseif d=='LTlt' then
      return true
    elseif d=='GTsh' then
      return true
    elseif d=='Xtlt' then
      return true
    elseif d=='WTtw' then
      return true
    elseif d=='Attc' then
      return true
    elseif d=='BTtc' then
      return true
    elseif d=='CTtc' then
      return true
    elseif d=='ITtc' then
      return true
    elseif d=='NTtc' then
      return true
    elseif d=='ZTtc' then
      return true
    else 
    return false
endif
endfunction

function RegrowTrees takes nothing returns nothing
    local destructable tree=GetDyingDestructable()
    call TriggerSleepAction(TreeRegrowTime())
    call DestructableRestoreLife( tree, GetDestructableMaxLife(tree), true )
    set tree=null
endfunction

function Trig_Int_Tree_Revival takes nothing returns nothing
    local trigger t
    if IsDesTree(GetEnumDestructable())==true then
    set t=CreateTrigger()
    call TriggerRegisterDeathEvent( t, GetEnumDestructable() )
    call TriggerAddAction(t,function RegrowTrees)
endif
endfunction

function Int_Tree_Revive takes nothing returns nothing
    call EnumDestructablesInRectAll( GetPlayableMapRect(), function Trig_Int_Tree_Revival )
endfunction

Ok..may look kinda confusing but I will explain what it does..
Collapse JASS:
function Int_Tree_Revive takes nothing returns nothing
    call EnumDestructablesInRectAll( GetPlayableMapRect(), function Trig_Int_Tree_Revival )
endfunction


This is VERY vital to the system. It starts it all. How does it do it you ask?
Simple it Picks Every Destructible In The Playable Map...and then it calls the function Trig_Int_Tree Revival.

Collapse JASS:
function IsDesTree takes destructable a returns boolean
    local integer d=GetDestructableTypeId(a)
    if d =='ATtr' then
      return true
    elseif d=='BTtw' then
      return true
    elseif d=='KTtw' then
      return true
    elseif d=='YTft' then
      return true
    elseif d=='JTct' then
      return true
    elseif d=='YTst' then
      return true
    elseif d=='YTct' then
      return true
    elseif d=='YTwt' then
      return true
    elseif d=='JTwt' then
      return true
    elseif d=='DTsh' then
      return true
    elseif d=='FTtw' then
      return true
    elseif d=='CTtr' then
      return true
    elseif d=='ITtw' then
      return true
    elseif d=='NTtw' then
      return true
    elseif d=='OTtw' then
      return true
    elseif d=='ZTtw' then
      return true
    elseif d=='WTst' then
      return true
    elseif d=='LTlt' then
      return true
    elseif d=='GTsh' then
      return true
    elseif d=='Xtlt' then
      return true
    elseif d=='WTtw' then
      return true
    elseif d=='Attc' then
      return true
    elseif d=='BTtc' then
      return true
    elseif d=='CTtc' then
      return true
    elseif d=='ITtc' then
      return true
    elseif d=='NTtc' then
      return true
    elseif d=='ZTtc' then
      return true
    else 
    return false
endif
endfunction
This is the rawcode for every single tree in Warcraft...you can add your own easily by pressing CTRl+D while looking at the Object Editor
//then follow the same format and add your tree's RAWCODE inside single quotes (Example ' ' )

Collapse JASS:
function Trig_Int_Tree_Revival takes nothing returns nothing
    local trigger t
    if IsDesTree(GetEnumDestructable())==true then
    set t=CreateTrigger()
    call TriggerRegisterDeathEvent( t, GetEnumDestructable() )
    call TriggerAddAction(t,function RegrowTrees)
endif
endfunction

This is pretty simple also. It is called at Map Initialization. What it does is create a local trigger IF the destructible is a tree..this is found out by using the function IsDesTree which is found in this tutorial, "t" in this case. It adds the Event a Destructable dies and adds an action. Actually it will call function RegrowTrees everytime the event is activated.

Collapse JASS:
function RegrowTrees takes nothing returns nothing
    local destructable tree=GetDyingDestructable()
    call TriggerSleepAction(TreeRegrowTime())
    call DestructableRestoreLife( tree, GetDestructableMaxLife(tree), true )
    set tree=null
endfunction

What does this is it gets the dying destructable and sets it to local destructable tree. It then waits TreeRegrowTime seconds..if you don't know what this is yet...it will be explained. After the wait is done it will Revive the Destructable SHOWING birth animations. If you don't want it to show birth animations then set the TRUE to FALSE.

Collapse JASS:
constant function TreeRegrowTime takes nothing returns real
    return 10.00 //the amount of time you want before the tree respawns
endfunction

This constant function is the Wait that is used in the RegrowTrees function.
It returns 10.00 seconds to wait..This return can never change while the system is running. If you want the trees to revive after a different alloted time then edit the 10.00 to whatever number you please.

Example:
Collapse JASS:
constant function TreeRegrowTime takes nothing returns real
    return 30.00 //the amount of time you want before the tree respawns
endfunction

I just editted the 10.00 to 30.00 now after 30.00 seconds the trees will respawn instead of after 10.00 seconds.

If you followed the tutorial you should have this in your map header by now.





Now comes the easy part...

Inside your Map Initialization trigger add the action

Collapse JASS:
Custom script:   call Int_Tree_Revive()

Ok..so here is a screen shot of the Map Initialization trigger in the sample map.



Thanks for reading this tutorial. I hope it helped you learn how to create a tree revival system in JASS.

-Hero

Sample Map: Tree Revival System.w3x

Any Questions? Comments? Suggestions? Post them here.

Last edited by PitzerMike : 07-02-2007 at 12:01 AM.
Hero12341234 is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-02-2007, 01:51 AM   #2
Hero12341234
User
 
Hero12341234's Avatar
 
Join Date: Feb 2006
Posts: 111

Submissions (1)

Hero12341234 is on a distinguished road (10)

Default

Updated
  1. Only Revives Trees
  2. Added a function with all the tree's RAWCODES
  3. You can add your own Tree's RAWCODE
  4. Added some new images..
  5. Fixed some text

and bump
Hero12341234 is offline   Reply With Quote
Old 04-14-2007, 05:35 AM   #3
Anopob
Yay!
 
Anopob's Avatar
 
Join Date: May 2006
Posts: 870

Anopob has a spectacular aura about (120)

Default

Cool. Will try soon I guess.
__________________
Give +REP to people who help you with things or make good resources.
Better Ways of Requesting For Help - Race Contest #2 WIP Thread (Bone Race)
As of December 1st I have my blue rep. Yay :D
Anopob is offline   Reply With Quote
Old 04-28-2007, 09:59 AM   #4
PitzerMike
Alcopops
 
PitzerMike's Avatar


Tools & Tutorials Moderator
 
Join Date: Jan 2003
Posts: 2,791

Submissions (12)

PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)PitzerMike is a splendid one to behold (643)

Approved Map: Pitzer's Minesweeper

Default

Comments to the code:

You don't need to check for the destructable ids. Use the Ahrl (Ghul Harvest) ability to check if a destructable is a tree. (it will automatically work for custom tree ids too). Here's the sample code:

Collapse JASS:
function IsDestructableTree takes destructable d returns boolean
  local boolean i = IsDestructableInvulnerable(d)
  local unit u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE), <invisible caster>,GetWidgetX(d), GetWidgetY(d), 0)
  local boolean result = false
  call UnitAddAbility(u, 'Ahrl')
  if i then
    call SetDestructableInvulnerable(d, false)
  endif
  set result = IssueTargetOrder(u, "harvest", d)
  call RemoveUnit(u)
  if i then
    call SetDestructableInvulnerable(d, true)
  endif
  return result
endfunction

Other than that:

Please use Jass tags for all the scripts and the trigger tag for the one GUI trigger that you're showing instead of images.
If you really MUST use images, then they can't be hosted at offsite locations, instead attach them to your post and reference the attachment. This is part of our rules for tutorials.

EDIT: looks better now, approved....
__________________
Zoom (requires log in)

Last edited by PitzerMike : 07-02-2007 at 12:02 AM.
PitzerMike is offline   Reply With Quote
Old 08-29-2007, 12:15 AM   #5
slomka
User
 
Join Date: Jul 2007
Posts: 3

slomka has little to show at this moment (0)

Default

isn;t possible to change the JASS script around and make a hero revive system?
slomka is offline   Reply With Quote
Old 09-28-2007, 08:16 PM   #6
Silvenon
User
 
Silvenon's Avatar
 
Join Date: May 2007
Posts: 492

Submissions (1)

Silvenon will become famous soon enough (63)Silvenon will become famous soon enough (63)Silvenon will become famous soon enough (63)

Send a message via MSN to Silvenon
Default

Instead of all those if/then/elses, isn't it better to just use ors? Like:

return d == 'ATtr' or d == 'BTtw' or d == 'KTtw'......?

EDIT: ......because of the text limit, sry
__________________
Cascading Style Shit

Last edited by Silvenon : 09-28-2007 at 08:28 PM.
Silvenon is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 01:23 AM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2014, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services