| 01-12-2012, 07:17 PM | #1 |
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? |
| 01-13-2012, 04:31 PM | #2 |
please use jass tags for your code examples; 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: 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 |
| 01-13-2012, 10:49 PM | #3 |
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. |
| 01-14-2012, 01:12 AM | #4 |
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. |
| 01-14-2012, 10:24 AM | #5 |
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! |
| 01-14-2012, 10:43 AM | #6 |
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: 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: 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" |
| 01-14-2012, 03:15 PM | #7 |
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. |
| 01-14-2012, 03:33 PM | #8 |
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. |
| 01-14-2012, 03:53 PM | #9 | |
Quote:
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. |
| 01-14-2012, 04:09 PM | #10 | |
Quote:
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: 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 |
| 01-14-2012, 04:19 PM | #11 |
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)? |
| 01-14-2012, 04:26 PM | #12 | |
Quote:
Than you would have to make it a real and set value to 0.5 And change Action a bit: 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) |
| 01-14-2012, 04:35 PM | #13 |
How would I edit the variable after the choice ingame? |
| 01-14-2012, 04:38 PM | #14 |
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? |
| 01-14-2012, 04:39 PM | #15 |
Yes, that is what I was asking. |
