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 > Warcraft III Modding > Developer's Corner > Triggers & Scripts
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 01-12-2012, 07:17 PM   #1
Gadgetguy
User
 
Join Date: Dec 2011
Posts: 10

Gadgetguy has little to show at this moment (4)

Question Gold farming not working

function Trig_GoldFarm_Conditions takes nothing returns boolean
if GetEventDamage() == 0 then
return false
endif
call ShowDamages()
if IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetEventDamageSource())) == false then
return false
endif
if GetUnitTypeId(GetEventDamageSource()) == 'H00D' then
return true
endif
if GetUnitTypeId(GetEventDamageSource()) == 'H000' then
return true
endif
return false
endfunction

function Trig_GoldFarm_Actions takes nothing returns nothing
call SetPlayerState( GetOwningPlayer(GetEventDamageSource()), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(GetEventDamageSource()), PLAYER_STATE_RESOURCE_GOLD) + R2I(GetEventDamage())*2)
endfunction

//===========================================================================
function InitTrig_GoldFarm takes nothing returns nothing
set gg_trg_GoldFarm = CreateTrigger( )
call TriggerAddCondition( gg_trg_GoldFarm, Condition( function Trig_GoldFarm_Conditions ) )
call TriggerAddAction( gg_trg_GoldFarm, function Trig_GoldFarm_Actions )
endfunction

This trigger no longer farms gold after I changed (GetEventDamage())) to (GetEventDamage())*2). Why doesn't this work and how do I fix it?
Gadgetguy is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 01-13-2012, 04:31 PM   #2
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

please use jass tags for your code examples;

Collapse JASS:
    function Trig_GoldFarm_Conditions takes nothing returns boolean
 if GetEventDamage() == 0 then
 return false
 endif
 call ShowDamages()
 if IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetEventDamageSource())) == false then
 return false
 endif
 if GetUnitTypeId(GetEventDamageSource()) == 'H00D' then
 return true
 endif
 if GetUnitTypeId(GetEventDamageSource()) == 'H000' then
 return true
 endif
 return false
 endfunction

function Trig_GoldFarm_Actions takes nothing returns nothing
 call SetPlayerState( GetOwningPlayer(GetEventDamageSource()), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(GetEventDamageSource()), PLAYER_STATE_RESOURCE_GOLD) + R2I(GetEventDamage())*2)
 endfunction

What error message do you get?

Try to use some variables to make your code more readable:
Collapse JASS:
function Trig_GoldFarm_Actions takes nothing returns nothing
    local player p = GetOwningPlayer(GetEventDamageSource())
    local integer gold = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)
    call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, gold + R2I(GetEventDamage())*2)
endfunction
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.

Last edited by cohadar : 01-13-2012 at 04:46 PM.
cohadar is offline   Reply With Quote
Old 01-13-2012, 10:49 PM   #3
Gadgetguy
User
 
Join Date: Dec 2011
Posts: 10

Gadgetguy has little to show at this moment (4)

Default

The trigger just doesn't work.
It is supposed to give the player that is attacking gold, I tried to multiply the gold by 2 but the trigger now no longer works.
I'm editing a map with permission so I don't have much of an idea what goes on here.
I can always just post all of the variables.
Sorry I'm a noob.
Gadgetguy is offline   Reply With Quote
Old 01-14-2012, 01:12 AM   #4
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

You just added *2 and it does not work any more?

Sounds like you are editing a protected map.

Anyways, the only reason I can think for it is not working is call ShowDamages() You should probably move it from condition function to start of action function.
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Old 01-14-2012, 10:24 AM   #5
Gadgetguy
User
 
Join Date: Dec 2011
Posts: 10

Gadgetguy has little to show at this moment (4)

Default

It no longer works.
I am editing an uproteced map with some of the triggers in jass.
I am not very good at jass so I don't really have any idea how to do that.
Thnks for all of your help so far!
Gadgetguy is offline   Reply With Quote
Old 01-14-2012, 10:43 AM   #6
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

The most common mistake for jass trigger to stop working is if you change the trigger name.

For example if you change:
"GoldFarm" to "Gold Farm"

Even adding one space will stop your trigger because your init function will never get called:
Collapse JASS:
// this no longer works because trigger is not called GoldFarm any more
function InitTrig_GoldFarm takes nothing returns nothing


"Gold Farm" (with space in between) needs to have InitTrig function like this:
Collapse JASS:
function InitTrig_Gold_Farm takes nothing returns nothing

So basically your init function should be called InitTrig + <your trigger name>
with all spaces replaced with underscores '_'
The names are case sensitive: "Gold Farm" is not the same as "gold farm"
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Old 01-14-2012, 03:15 PM   #7
Gadgetguy
User
 
Join Date: Dec 2011
Posts: 10

Gadgetguy has little to show at this moment (4)

Default

Collapse JASS:
function Trig_GoldFarm_Conditionsx4 takes nothing returns boolean
    if GetEventDamage() == 0 then
        return false
    endif
    call ShowDamages()
    if IsPlayerEnemy(GetOwningPlayer(GetTriggerUnit()), GetOwningPlayer(GetEventDamageSource())) == false then
        return false
    endif
    if GetUnitTypeId(GetEventDamageSource()) == 'H00D' then
        return true
    endif
    if GetUnitTypeId(GetEventDamageSource()) == 'H000' then
        return true
    endif
    return false
endfunction

function Trig_GoldFarm_Actionsx4 takes nothing returns nothing
    call SetPlayerState( GetOwningPlayer(GetEventDamageSource()), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(GetEventDamageSource()), PLAYER_STATE_RESOURCE_GOLD) + R2I(GetEventDamage())*2)
endfunction

//===========================================================================
function InitTrig_GoldFarmx4 takes nothing returns nothing
    set gg_trg_GoldFarmx4 = CreateTrigger(  )
    call TriggerAddCondition( gg_trg_GoldFarmx4, Condition( function Trig_GoldFarm_Conditionsx4 ) )
    call TriggerAddAction( gg_trg_GoldFarmx4, function Trig_GoldFarm_Actionsx4 )
endfunction

This was my new trigger with the x4 for my x4 mode. I checked all the names of things but everything seems to be in order.
Gadgetguy is offline   Reply With Quote
Old 01-14-2012, 03:33 PM   #8
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

You have no event function.
It should be something like call TriggerRegisterPlayerUnitEvent(... It should be inside your InitTrig.

Just create a simple GUI trigger that has some event that convert it to jass to see how it should look.
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.

Last edited by cohadar : 01-14-2012 at 03:34 PM.
cohadar is offline   Reply With Quote
Old 01-14-2012, 03:53 PM   #9
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,190

Submissions (19)

Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)Anitarf has a brilliant future (903)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

Quote:
Originally Posted by cohadar
Just create a simple GUI trigger that has some event that convert it to jass to see how it should look.
Since he is using damage event responses, I presume he is adding specific unit events to the trigger from somewhere else, or is passing it to a damage detection system.

I would recommend adding debug messages to the trigger. Restore it to its original state when it still worked and then make sure you are changing only one thing at a time and testing it after each change to help identify where it breaks down.
__________________
Anitarf is offline   Reply With Quote
Old 01-14-2012, 04:09 PM   #10
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

Quote:
Originally Posted by Anitarf
Since he is using damage event responses, I presume he is adding specific unit events to the trigger from somewhere else, or is passing it to a damage detection system.
Ah of course, then all he needs to do is find out where gg_trg_GoldFarm is registered with event and do the same with gg_trg_GoldFarmx4..... no wait.

He has modes.
Ok Gadgetguy here is what you do:
1. give the trigger it's old name GoldFarm.
2. if you have more triggers, for example GoldFarm, GoldFarmx2, GoldFarmx4 delete all of them except the original GoldFarm
3. Make global variable: FarmingLevel
4. Change Action like this:
Collapse JASS:
// scroll to the right --->> to see the change I made
function Trig_GoldFarm_Actions takes nothing returns nothing
    call SetPlayerState( GetOwningPlayer(GetEventDamageSource()), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(GetEventDamageSource()), PLAYER_STATE_RESOURCE_GOLD) + R2I(GetEventDamage())*udg_FarmingLevel)
endfunction

Make sure your global variable FarmingLevel has value 1 on startup.
Than if you want double money you set FarmingLevel to 2.
If you want x4 money you set FarmingLevel to 4 ...

Note: Global variables in jass have prefix udg_
So if you create FarmingLevel in GUI it will be called udg_FarmingLevel in jass
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.

Last edited by cohadar : 01-14-2012 at 04:12 PM.
cohadar is offline   Reply With Quote
Old 01-14-2012, 04:19 PM   #11
Gadgetguy
User
 
Join Date: Dec 2011
Posts: 10

Gadgetguy has little to show at this moment (4)

Default

You're right! that looks perfect!
I made FarmingLevel an integer, is that correct?
What would I do if I wanted to divide the gold by two?
How do I edit the variable at the start of the game using gui triggers. (not being good with jass)?

Last edited by Gadgetguy : 01-14-2012 at 04:28 PM.
Gadgetguy is offline   Reply With Quote
Old 01-14-2012, 04:26 PM   #12
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

Quote:
Originally Posted by Gadgetguy
What would I do if I wanted to divide the gold by two?

Than you would have to make it a real and set value to 0.5
And change Action a bit:
Collapse JASS:
// scroll to the right --->> to see the change I made
// now R2I (real to integer) function also has FarminLevel inside because FarmingLevel is now real
function Trig_GoldFarm_Actions takes nothing returns nothing
    call SetPlayerState( GetOwningPlayer(GetEventDamageSource()), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(GetEventDamageSource()), PLAYER_STATE_RESOURCE_GOLD) + R2I(GetEventDamage()*udg_FarmingLevel))
endfunction

Yeah real is more flexible, that way you can even do stuff like 75% gold (that is 0.75)
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.

Last edited by cohadar : 01-14-2012 at 04:28 PM.
cohadar is offline   Reply With Quote
Old 01-14-2012, 04:35 PM   #13
Gadgetguy
User
 
Join Date: Dec 2011
Posts: 10

Gadgetguy has little to show at this moment (4)

Default

How would I edit the variable after the choice ingame?
Gadgetguy is offline   Reply With Quote
Old 01-14-2012, 04:38 PM   #14
cohadar
master of fugue
 
cohadar's Avatar
 
Join Date: Jun 2007
Posts: 2,453

Submissions (5)

cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)cohadar is just really nice (250)

Default

You just set it like any other variable in GUI.

set FarmingLevels = 0.75

Do you have choice with Dialogs? Is that what you are asking?
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.
cohadar is offline   Reply With Quote
Old 01-14-2012, 04:39 PM   #15
Gadgetguy
User
 
Join Date: Dec 2011
Posts: 10

Gadgetguy has little to show at this moment (4)

Default

Yes, that is what I was asking.
Gadgetguy 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 04:00 AM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

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