(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 25 weeks 1 day ago. Offline
Joined: 2012-06-20
Posts: 1304

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 not work:

  • 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.

Hi, I am a Hedgewars developer. Smile

oranebeast
User offline. Last seen 10 years 16 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 25 weeks 1 day ago. Offline
Joined: 2012-06-20
Posts: 1304

That doesn’t help at all. I don’t want to place girders, I want to find out when a girder has been placed.

Hi, I am a Hedgewars developer. Smile

CheezeMonkey
User offline. Last seen 4 years 51 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 should be a better way of going about it. Smile

oranebeast
User offline. Last seen 10 years 16 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 21 weeks 5 days ago. Offline
Joined: 2009-07-18
Posts: 563

With next release (0.9.21 or something),
these should work:

onSpritePlacement(spriteId, centerX, centerY)
onGirderPlacement(frameIdx, centerX, centerY)
onRubberPlacement(frameIdx, centerX, centerY)

frameIdx is given so that you can figure out the used orientation based on the girder's sprite texture:

Note: Columns go before rows
So the frameIdx for the image above goes like:


0 3 6
1 4 7
2 5  

so a frameIdx of 0 would indicate a short horizontal girder, a frameIdx of 6 a long vertical one.

  sheepluva <- me  my code stats -> 
a Hedgewars Developer


   <- where I'm from  what I speak -> 

Wuzzy
Wuzzy's picture
User offline. Last seen 25 weeks 1 day ago. Offline
Joined: 2012-06-20
Posts: 1304

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

User login

Copyright © 2004-2024 Hedgewars Project. All rights reserved. [ contact ]