- Joined
- Jul 10, 2007
- Messages
- 6,306
You can't avoid them as they have to occur at the same instant. Timer events allow the thing to show that it's no longer the same instant.
I get your idea, but let's say that we had this scenario
Player buys an item for 400 gold
Player sells an item for 400 gold
Without the timer thing, that'd register as a trade event.
constant playerscore PLAYER_SCORE_GOLD_GIVEN = ConvertPlayerScore(14)
constant playerscore PLAYER_SCORE_GOLD_RECEIVED = ConvertPlayerScore(15)
constant playerscore PLAYER_SCORE_LUMBER_TOTAL = ConvertPlayerScore(16)
constant playerscore PLAYER_SCORE_LUMBER_LOST_UPKEEP = ConvertPlayerScore(17)
constant playerscore PLAYER_SCORE_LUMBER_LOST_TAX = ConvertPlayerScore(18)
constant playerscore PLAYER_SCORE_LUMBER_GIVEN = ConvertPlayerScore(19)
constant playerscore PLAYER_SCORE_LUMBER_RECEIVED = ConvertPlayerScore(20)
library Trade uses /*
*/Event //hiveworkshop.com/forums/submissions-414/snippet-event-186555/
//Version 3.0.0.0
//struct Trade extends array
//static constant Event EVENT_GOLD
//static constant Event EVENT_LUMBER
//readonly static player giver
//readonly static player reciever
//readonly static integer amount
//readonly static playerstate state
private module Init
private integer goldScore
private integer lumberScore
private static method tradeGold takes nothing returns boolean
local integer i
local player p = GetTriggerPlayer()
local thistype this = GetPlayerId(p)
if (giver == null) then
set i = GetPlayerScore(p, PLAYER_SCORE_GOLD_GIVEN)
set amount = i-goldScore
if (amount != 0) then
set goldScore = i
set giver = p
set state = PLAYER_STATE_RESOURCE_GOLD
endif
else
set reciever = p
call EVENT_GOLD.fire()
set giver = null
set giver = null
set reciever = null
set state = null
set amount = 0
endif
set p = null //decrease pointer count to handle
return false
endmethod
private static method tradeLumber takes nothing returns boolean
local integer i
local player p = GetTriggerPlayer()
local thistype this = GetPlayerId(p)
if (giver == null) then
set i = GetPlayerScore(p, PLAYER_SCORE_LUMBER_GIVEN)
set amount = i-lumberScore
if (amount != 0) then
set lumberScore = i
set giver = p
set state = PLAYER_STATE_RESOURCE_LUMBER
endif
else
set reciever = p
call EVENT_LUMBER.fire()
set giver = null
set giver = null
set reciever = null
set state = null
set amount = 0
endif
set p = null //decrease pointer count to handle
return false
endmethod
private static method onInit takes nothing returns nothing
local integer this = 16
local trigger t = CreateTrigger()
local trigger t2 = CreateTrigger()
set EVENT_GOLD = CreateEvent()
set EVENT_LUMBER = CreateEvent()
loop
set this = this - 1
set goldScore = GetPlayerScore(Player(this), PLAYER_SCORE_GOLD_GIVEN)
set lumberScore = GetPlayerScore(Player(this), PLAYER_SCORE_LUMBER_GIVEN)
call TriggerRegisterPlayerStateEvent(t, Player(this), PLAYER_STATE_RESOURCE_GOLD, GREATER_THAN_OR_EQUAL, 0)
call TriggerRegisterPlayerStateEvent(t2, Player(this), PLAYER_STATE_RESOURCE_LUMBER, GREATER_THAN_OR_EQUAL, 0)
exitwhen this == 0
endloop
call TriggerAddCondition(t, Condition(function thistype.tradeGold))
call TriggerAddCondition(t2, Condition(function thistype.tradeLumber))
endmethod
endmodule
struct Trade extends array
readonly static player giver = null
readonly static player reciever = null
readonly static playerstate state = null
readonly static integer amount = 0
readonly static Event EVENT_GOLD = 0
readonly static Event EVENT_LUMBER = 0
implement Init
endstruct
endlibrary
* function GetUnitById takes integer index returns unit
* - Returns unit given a unit index
* function GetUnitId takes unit u returns integer
* - Returns unit index given a unit
//static constant Event EVENT_GOLD
//static constant Event EVENT_LUMBER
//readonly static player giver
//readonly static player taker
//readonly static integer amount
//readonly static playerstate state
I think it's more of a formality than anything else. While it's redundant, it'd make it complete. Maybe add a note that shows how to use EVENT_GOLD, EVENT_LUMBER or at least a link to a how-to that shows how to use those things.
I don't believe in redundant information
There, I made the documentation pretty >.>