Board index Programs with AI or Rules Enforcement Magic: The Gathering - Duels of the Planeswalkers Programming Talk
[DotP2013] Spell Rupture
Moderator: CCGHQ Admins
[DotP2013] Spell Rupture
by BETenner » 20 Mar 2013, 13:37
I'm trying to coding Spell Rupture, I couldn't find any problem in my code, but it leads to a crash (not script error) while loading the card.
Please help me find the cause..
Please help me find the cause..
- Code: Select all
<SPELL_ABILITY filter_zone="ZONE_IN_PLAY">
<TARGET_DEFINITION id="0">
local filter = Object():GetFilter()
filter:Clear()
filter:SetZone( ZONE_STACK )
filter:SetStackObjectType( STACK_OBJECT_CARD )
filter:SetHint( HINT_ENEMY_ONLY, EffectController() )
</TARGET_DEFINITION>
<TARGET_DETERMINATION>
return AtLeastOneTargetFromDefinition(0)
</TARGET_DETERMINATION>
<PLAY_TIME_ACTION target_choosing="1">
EffectController():ChooseTarget( 0, "CARD_QUERY_CHOOSE_SPELL_TO_COUNTER", EffectDC():Make_Targets(0) )
</PLAY_TIME_ACTION>
<RESOLUTION_TIME_ACTION>
local filter = Object():GetFilter()
filter:Clear()
filter:AddCardType(CARD_TYPE_CREATURE)
filter:SetController(EffectController())
filter:SetZone(ZONE_IN_PLAY)
local count = filter:EvaluateObjects()
local maxpower = 0
for i=0,count-1 do
local crt = filter:GetNthEvaluatedObject(i)
if (crt ~= nil) then
if (crt:GetCurrentCharacteristics():Power_Get() > maxpower) then
maxpower = crt:GetCurrentCharacteristics():Power_Get()
end
end
end
EffectDC():Set_Int(1, maxpower)
</RESOLUTION_TIME_ACTION>
<RESOLUTION_TIME_ACTION>
local target_spell = EffectDC():Get_Targets(0):Get_CardPtr(0)
local player = target_spell:GetPlayer()
local maxpower = EffectDC():Get_Int(1)
if player ~= nil then
if player:CanAfford("{"..maxpower.."}") == 1 then
player:BeginNewMultipleChoice()
player:AddMultipleChoiceAnswer( "CARD_QUERY_OPTION_YES" )
player:AddMultipleChoiceAnswer( "CARD_QUERY_OPTION_NO" )
player:AskMultipleChoiceQuestion( "CARD_QUERY_ASK_PAY_FOR_SPELL_RUPTURE" )
end
end
</RESOLUTION_TIME_ACTION>
<RESOLUTION_TIME_ACTION>
local target_spell = EffectDC():Get_Targets(0):Get_CardPtr(0)
local player = target_spell:GetPlayer()
local maxpower = EffectDC():Get_Int(1)
local decision = Object():GetMultipleChoiceResult()
if player ~= nil then
if player:CanAfford("{"..maxpower.."}") == 1 then
if decision ~= 1 then
player:TapLand("{"..maxpower.."}")
else
target_spell:CounterSpell()
end
else
target_spell:CounterSpell()
end
end
</RESOLUTION_TIME_ACTION>
</SPELL_ABILITY>
Re: [DotP2013] Spell Rupture
by thefiremind » 20 Mar 2013, 13:56
I can't find a sure reason for that, but as first thing to try I would enclose the "for" loop in an "if count > 0 then", and the last 2 RESOLUTION_TIME_ACTIONs in an "if target_spell ~= nil then". You also forgot filter:NotTargetted() when looking for the greatest power (it can't be the reason of the crash, but the card is wrong without it).
If it still crashes, you can try to find the greatest power in another way:
If it still crashes, you can try to find the greatest power in another way:
- Code: Select all
local player = EffectController()
local maxpower = 0
local filter = Object():GetFilter()
filter:Clear()
filter:AddCardType( CARD_TYPE_CREATURE )
filter:SetZone( ZONE_IN_PLAY )
filter:SetController( player )
filter:NotTargetted()
local any_creature = filter:CountStopAt(1)
if any_creature == 1 then
maxpower = -1
while filter:CountStopAt(1) == 1 do
maxpower = maxpower + 1
filter:SetPowerMin( maxpower+1 )
end
-- now "maxpower" is equal to the greatest power
end
< Former DotP 2012/2013/2014 modder >
Currently busy with life...
Currently busy with life...
-
thefiremind - Programmer
- Posts: 3515
- Joined: 07 Nov 2011, 10:55
- Has thanked: 118 times
- Been thanked: 721 times
Re: [DotP2013] Spell Rupture
by BETenner » 20 Mar 2013, 14:15
I did all you said, now it won't crash again, thanks...again(xN)!
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 23 guests