(RESOLVED) What is the proper way to find out when a girder has been placed?

6 replies [Last post]
Wuzzy
Wuzzy's picture
User offline. Last seen 3 days 21 hours ago. Offline
Joined: 2012-06-20
Posts: 1301
Okay, here is a Lua question: How do I properly find out when a girder (or rubber) has been placed by the player? Here are some ways which do [i]not[/i] work: [list] [*]Using onHogAttack: Useless, it also gets called if a placement attempt has failed (for example on an invalid position). [*]Using onGearAdd: Also gets called when placement has failed. [*]Observing the number of girders in inventory for changes: Does not work if the player has infinite girders.[/list]
Hi, I am a Hedgewars developer. Smile
oranebeast
User offline. Last seen 9 years 34 weeks ago. Offline
Joined: 2013-06-10
Posts: 104
If it helps i could offer you my girder script that places girders randomly. Link : http://pastebin.com/EKt32BYs I don't think it will help though, BTW randomly placed objects don't go through maps, Don't believe me? Set the girder place function to onTick.
{} {} \___/ - Happy
Wuzzy
Wuzzy's picture
User offline. Last seen 3 days 21 hours ago. Offline
Joined: 2012-06-20
Posts: 1301
That doesn’t help at all. I don’t want to place girders, I want to find out [i]when[/i] a girder has been placed.
Hi, I am a Hedgewars developer. Smile
CheezeMonkey
User offline. Last seen 4 years 17 weeks ago. Offline
Joined: 2010-11-19
Posts: 117
It took my a long while to figure it out (it annoyed me that I couldn't figure it out, and so the I kept coming back to it Big Grin) and I finally came up with a hack which works. http://pastebin.mozilla.org/3922099 The only little problem is that, when you have infinite girders and you place one correctly, the top of the screen will mention that you have 98 girders left, although you actually have infinite girders remaining. It's a little annoying, but eh, it's not really a big deal. :P I hope it helps, though there really [i][b]should[/b][/i] be a better way of going about it. Smile
oranebeast
User offline. Last seen 9 years 34 weeks ago. Offline
Joined: 2013-06-10
Posts: 104
For your 98 error, Maybe something along the lines of if ammo girder = 98 then change the displayed string to Infinite I don't know, I'm just being my normal "Based on theroy" self again...
{} {} \___/ - Happy
sheepluva
sheepluva's picture
User offline. Last seen 1 day 17 hours ago. Offline
Joined: 2009-07-18
Posts: 561
With next release (0.9.21 or something), these should work: [code][b]onSpritePlacement[/b](spriteId, centerX, centerY) [b]onGirderPlacement[/b](frameIdx, centerX, centerY) [b]onRubberPlacement[/b](frameIdx, centerX, centerY)[/code] [code]frameIdx[/code] is given so that you can figure out the used orientation based on the girder's sprite texture:[img]https://hedgewars.googlecode.com/hg/share/hedgewars/Data/Graphics/amGirder.png[/img] Note: [b]Columns go before rows[/b] So the [code]frameIdx[/code] for the image above goes like: [center][code][b] 0 3 6 1 4 7 2 5   [/b][/code][/center] so a [code]frameIdx[/code] of 0 would indicate a short horizontal girder, a [code]frameIdx[/code] of 6 a long vertical one.
  [url=/user/3290][color=white][b]sheepluva[/b][/color][/url][color=#90BA5D] <- me[float=right]  [/float][float=right][url=https://www.openhub.net/accounts/80048][img]https://www.openhub.net/accounts/80048/widgets/account_tiny.gif[/img][/url][/float][float=right]my code stats -> [/float][/color] [i][color=#6080C0][size=8]a[size=4] [/size][/size][/color][color=yellow]Hedgewars Developer[/color][/i] [center][float=left]  [/float][float=left][url=https://twitter.com/sheepytweety][img]/images/twitter.png[/img][/url][/float] [url=/privatemsg/new/3290][color=#C0C0C0]click here to message me[/color][/url][/center] [color=#90BA5D][float=left]  [/float][float=left][url=https://en.wikipedia.org/wiki/Austria][img]/images/Flags/austria.png[/img][/url][/float][float=left] <- where I'm from[/float][float=right]  [/float][float=right][img]/images/Flags/united_kingdom.png[/img][/float][float=right][img]/images/Flags/germany.png[/img][/float][float=right]what I speak -> [/float][/color]
Wuzzy
Wuzzy's picture
User offline. Last seen 3 days 21 hours ago. Offline
Joined: 2012-06-20
Posts: 1301
Thank you, sheepluva. I have tested onGirderPlacement and onRubberPlacement and both work as intended. This old problem has now finally resolved. In case you wondered, here is what I needed this for: http://www.hedgewars.org/node/5615?page=0#comment-29932 This strategy script is now working, but not without some weird hacks.
Hi, I am a Hedgewars developer. Smile
Copyright © 2004-2023 Hedgewars Project. All rights reserved. [ contact ]