Author Topic: [fixed] Why 'registerCellTriggerEventForUnitToLocation()' function not working ?  (Read 977 times)

felipeludo2011

  • Guest
I am trying to make scenarios but when I move the horseman the game crash, whats wrong ?
the 'you' variable is the horseman
'indianchief' is the variable that start with 'not_here'  value, and change to 'end' if the horseman stay near to the mainteepee.
Here is the function :
Code: [Select]
cell_event2 = registerCellTriggerEventForUnitToLocation(you,{100,100})
</startup>
<cellTriggerEvent>
if triggeredCellEventId() == cell_event2 and indianchief == 'end' then
setPlayerAsWinner(0)
endGame()
          unregisterCellTriggerEvent(cell_event1)
       end
</cellTriggerEvent>
</scripts>
</scenario>
And here the full code :
Code: [Select]
<?xml version="1.0" standalone="yes" ?>
<scenario>
<difficulty value="1"/>
<players>
<player control="human" faction="tech" team="1"/>
<player control="cpu-easy" faction="indian" team="1"/>
<player control="cpu-easy" faction="indian" team="1"/>
<player control="closed"/>
</players>
<map value="kaloan2-3"/>
<tileset value="forest"/>
<tech-tree value="megapack"/>
<default-resources value="true"/>
<default-units value="false"/>
<default-victory-conditions value="false"/>
<scripts>
<startup>
showMessage('intro1', 'title')
showMessage('intro2', 'title')
showMessage('messenger1', 'messenger')
showMessage('messenger2', 'messenger')
showMessage('info1', 'info')

createUnit('horseman', 0, startLocation(2))
you = lastCreatedUnit()

createUnit('mainteepee', 1, startLocation(1))
main = lastCreatedUnit()
createUnit('worker', 1, startLocation(1))
worker1 = lastCreatedUnit()
createUnit('worker', 1, startLocation(1))
worker2 = lastCreatedUnit()
createUnit('worker', 1, startLocation(1))
worker3 = lastCreatedUnit()
createUnit('shaman', 1, startLocation(1))
shaman = lastCreatedUnit()
createUnit('archer', 1, startLocation(1))
archer1 = lastCreatedUnit()
createUnit('archer', 1, startLocation(1))
archer2 = lastCreatedUnit()
createUnit('archer', 1, startLocation(1))
archer3 = lastCreatedUnit()
createUnit('roundtent', 1, startLocation(1))
roundtent = lastCreatedUnit()
createUnit('horsefarm', 1, startLocation(1))

cell_event1 = registerCellTriggerEventForFactionToUnit(0,main)
cell_event2 = registerCellTriggerEventForUnitToLocation(you,{100,100})
cell_event3 = registerCellTriggerEventForFactionToUnit(0,worker1)
cell_event4 = registerCellTriggerEventForFactionToUnit(0,worker2)
cell_event5 = registerCellTriggerEventForFactionToUnit(0,worker3)
cell_event6 = registerCellTriggerEventForFactionToUnit(0,shaman)
cell_event7 = registerCellTriggerEventForFactionToUnit(0,roundtent)
cell_event8 = registerCellTriggerEventForFactionToUnit(0,archer1)
cell_event9 = registerCellTriggerEventForFactionToUnit(0,archer2)
cell_event10 = registerCellTriggerEventForFactionToUnit(0,archer3)
indianchief = 'not_here'
</startup>

<cellTriggerEvent>   
if triggeredCellEventId() == cell_event1 and indianchief == 'not_here' then
showMessage('messenger1', 'messenger')
       end
if triggeredCellEventId() == cell_event1 and indianchief == 'here' then
showMessage('main1', 'messenger')
indianchief = 'end'
          unregisterCellTriggerEvent(cell_event1)
       end
if triggeredCellEventId() == cell_event2 and indianchief == 'end' then
setPlayerAsWinner(0)
endGame()
          unregisterCellTriggerEvent(cell_event1)
       end
if triggeredCellEventId() == cell_event3 then
showMessage('messenger1', 'messenger')
          unregisterCellTriggerEvent(cell_event3)
       end
       if triggeredCellEventId() == cell_event4 then
showMessage('messenger1', 'messenger')
          unregisterCellTriggerEvent(cell_event4)
       end
       if triggeredCellEventId() == cell_event5 then
showMessage('messenger1', 'messenger')
          unregisterCellTriggerEvent(cell_event5)
       end
       if triggeredCellEventId() == cell_event6 and indianchief == 'not_here' then
showMessage('shaman1', 'messenger')
indianchief = 'shaman'
       end
       if triggeredCellEventId() == cell_event6 and indianchief == 'roundtent' then
showMessage('shaman2', 'messenger')
indianchief = 'here'
          unregisterCellTriggerEvent(cell_event6)
       end
       if triggeredCellEventId() == cell_event7 and indianchief == 'shaman' then
showMessage('roundtent1', 'messenger')
indianchief = 'roundtent'
          unregisterCellTriggerEvent(cell_event7)
       end
       if triggeredCellEventId() == cell_event7 and indianchief == 'not_here' then
showMessage('messenger1', 'messenger')
       end
       if triggeredCellEventId() == cell_event8 then
showMessage('messenger1', 'messenger')
          unregisterCellTriggerEvent(cell_event8)
       end
       if triggeredCellEventId() == cell_event9 then
showMessage('messenger1', 'messenger')
          unregisterCellTriggerEvent(cell_event9)
       end
       if triggeredCellEventId() == cell_event10 then
showMessage('messenger1', 'messenger')
          unregisterCellTriggerEvent(cell_event10)
       end
</cellTriggerEvent>
</scripts>
</scenario>

Please help me !
« Last Edit: 5 October 2011, 15:21:37 by softcoder »

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Try without the strange variable checks.
Code: [Select]
</startup>
<cellTriggerEvent>
if registerCellTriggerEventForUnitToLocation(you,{100,100}) and indianchief == 'end' then
setPlayerAsWinner(0)
endGame()
          unregisterCellTriggerEvent(cell_event1)
       end
</cellTriggerEvent>
</scripts>
</scenario>
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

felipeludo2011

  • Guest
Thanks Omega, but not work.
Only work with the ...UnitToUnit() or ...FactionToUnit() functions  :(
The code of one scenario working with the function may help to find the error comparing them. I'm searching one.
I like making maps and scenarios codes  :) but I'm starting and I need help.

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Hmm, not sure then. I'm afraid I haven't the time to go through the entire scenario code, and only looked at the snippet you stated had the issue. Just a simple check, are you certain you went to the right location? {100,100} is actually 50,50 cells, since in Lua, the cells are all subdivided into 2x2 tiles. Thus, a 128x128 map actually has 256x256 tiles that the scenarios can use (though the first and last rows should not be used).
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Is this GAE or MegaGlest? If it is a bug, lets move it to the right place so it can be fixed.
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

felipeludo2011

  • Guest
I checked the location on the map editor, Omega, and I know about the tiles, thanks.
And I'm using MegaGlest, titi.

felipeludo2011

  • Guest
I'm making another scenario that use the function FationToLocation(), and not working too.  :(

Code: [Select]
<?xml version="1.0" standalone="yes" ?>
<scenario>
<difficulty value="3"/>
<players>
<player control="human" faction="tech" team="1"/>
<player control="cpu" faction="egypt" team="2"/>
<player control="cpu" faction="egypt" team="1"/>
<player control="closed"/>
</players>
<map value="kaloan7-8"/>
<tileset value="meadow"/>
<tech-tree value="megapack"/>
<default-resources value="true"/>
<default-units value="false"/>
<default-victory-conditions value="true"/>
<scripts>
<startup>
disableAi(1)
disableConsume(1)
showMessage('info1', 'title')
showMessage('wizard1', 'wizard')
showMessage('captain1', 'captain')
showMessage('wizard2', 'wizard')
showMessage('wizard3', 'wizard')
showMessage('captain2', 'captain')
showMessage('you1', 'you')
setDisplayText('info2')

createUnit('castle', 0, startLocation(0))
for i=1, 10 do
createUnit('worker', 0, startLocation(0))
end
for i=1, 10 do
createUnit('archer', 0, startLocation(0))
end
for i=1, 10 do
createUnit('swordman', 0, startLocation(0))
end
createUnit('guard', 0, startLocation(0))
createUnit('guard', 0, startLocation(0))
createUnit('guard', 0, startLocation(0))
for i=1, 3 do
createUnit('horseman', 0, startLocation(0))
createUnit('cow', 0, startLocation(0))
end
createUnit('ornithopter', 0, startLocation(0))
createUnit('horseman', 0, startLocation(0))
createUnit('blacksmith', 0, startLocation(0))
createUnit('technodrome', 0, startLocation(0))
createUnit('technician', 0, startLocation(0))
createUnit('farm', 0, startLocation(0))

for i=1, 50 do
createUnit('snake', 1, startLocation(1))
end
for i=1, 15 do
createUnit('anubis_warrior', 1, startLocation(1))
end
createUnit('temple', 1, startLocation(1))
fenix=lastCreatedUnit()
createUnit('obelisk', 1, startLocation(1))
createUnit('obelisk', 1, startLocation(1))
cell_event1 = registerCellTriggerEventForFactionToLocation(0,{94,152})
</startup>

<unitDied>
if lastDeadUnit()==fenix then
clearDisplayText()
setPlayerAsWinner(0)
endGame()
end

</unitDied>
<cellTriggerEvent>   

       if triggeredCellEventId() == cell_event1 then
enableAi(1)
unregisterCellTriggerEvent(cell_event1)
       end
       
</cellTriggerEvent>
</scripts>
</scenario>

I'm still looking for a another scenario code  with this function working.  :look:

softcoder

  • MegaGlest Team
  • Battle Machine
  • ********
  • Posts: 2,239
    • View Profile
Fixed in svn rev# 2539:

 - bugfix for scripted scenario function registerCellTriggerEventForFactionToLocation not working properly

Update: Svn rev# 2540 also fixed registerCellTriggerEventForUnitToLocation

tomreyn

  • Local Moderator
  • Airship
  • ********
  • Posts: 2,764
    • View Profile
    • MegaGlest - the free and open source cross platform 3D real-time strategy game
Felipe: If you would like to try your sceanrios with a version which has these fixes, you will either need to wait for the next alpha release (I assume there will be on within a week or two) or build your own from our subversion repository, as explained at http://wiki.megaglest.org/Development
atibox: Ryzen 1800X (8 cores @3.6GHz), 32 GB RAM, MSI Radeon RX 580 Gaming X 8G, PCI subsystem ID [1462:3417], (Radeon RX 580 chipset, POLARIS10) @3440x1440; latest stable Ubuntu release, (open source) radeon (amdgpu) / mesa video driver
atibox (old): Core2Quad Q9400 (4 cores @2.66GHz), 8 GB RAM, XFX HD-467X-DDF2, PCI subsystem ID [1682:2931], (Radeon HD 4670, RV730 XT) @1680x1050; latest stable Ubuntu release, (open source) radeon / mesa video driver
notebook: HP envy13d020ng
internet access: VDSL2+

· · · How YOU can contribute to MG · Latest development snapshot · How to build yourself · Megapack techtree · Currently hosted MG games · · ·

felipeludo2011

  • Guest
Thanks for the help! :D