Javascript API documentation

For AI and campaign script related discussions and questions
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

aubergine wrote:Wooohooo!!! :D :yahoo: :bow2: Thank you!!! :D
sg1efc, you forgot to re-login :roll:

P.S. +1.
User avatar
Shadow Wolf TJC
Regular
Regular
Posts: 1047
Joined: 16 Apr 2011, 05:12
Location: Raleigh, NC

Re: Javascript API documentation

Post by Shadow Wolf TJC »

Per wrote:eventDestroyed() is not throttled. It can be used to monitor object destruction.
Perhaps, but is it called whenever ANY game object, including those not owned by the player, is destroyed? :|

Oh well. I suppose I could give eventGroupLoss() a shot. It could prove to be a more cost-effective alternate to the old bind() function.
Creator of Warzone 2100: Contingency!
Founder of Wikizone 2100: http://wikizone2100.wikia.com/wiki/Wikizone_2100
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

Afaik, it is called even when an oil drum is picked up.
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

eventDestroyed() gets called for your own objects, and features (players 12 and 99), but not enemy objects.

eventGroupLoss() is a neat alternative to bind -- I'm so used to the 3.1 style of groups that I didn't consider putting all my targets for a sector in to a 3.2 style group and then monitoring eventGroupLoss(), but indeed that fits exactly what I want to do! :D
Last edited by aubergine on 19 Dec 2012, 12:41, edited 1 time in total.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

NoQ wrote:
aubergine wrote:Wooohooo!!! :D :yahoo: :bow2: Thank you!!! :D
sg1efc, you forgot to re-login :roll:
heh, I've been wanting string params to setTimer/queue since 3.1 Beta 1, hence the sg1efc-style homage.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

aubergine wrote:eventDestroyed() gets called for your own objects, and features (players 12 and 99)
Huh? O_o

It should only ever be called for objects you own.

Anyway, your opinion - should I extend eventDestroyed() to also be called for non-owned objects (which may require you to change your event handlers to account for this), or add a new event (eg eventDestroyedOther...) for these?
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

I think eventDestroyed() should be limited to stuff owned by 'me' in wz 3.2 and above. In recent versions eventPickup() covers the main requirements regarding features (oil barrels and artifacts). And eventGroupLoss() allows a script to listen to anything else it's interested in simply by adding it to a group.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
Shadow Wolf TJC
Regular
Regular
Posts: 1047
Joined: 16 Apr 2011, 05:12
Location: Raleigh, NC

Re: Javascript API documentation

Post by Shadow Wolf TJC »

Per wrote:Anyway, your opinion - should I extend eventDestroyed() to also be called for non-owned objects (which may require you to change your event handlers to account for this), or add a new event (eg eventDestroyedOther...) for these?
While it may not be needed for AI developers, something like an eventDestroyedAny() function could be useful for scripting certain special effects to happen (like spawning a new object, or creating a damaging explosion on death) whenever particular objects get destroyed (such as if a critical mission objective is destroyed, or if an object equipped with a certain component was destroyed). This would be most useful in both campaign scripts and rules.js.
Creator of Warzone 2100: Contingency!
Founder of Wikizone 2100: http://wikizone2100.wikia.com/wiki/Wikizone_2100
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

I'm not using eventDestroyed anywhere (i think), so don't worry about me. If you ask me for an irresponsible opinion, i think eventDestroyed should catch all objects.
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

EDIT: I agree with NoQ - it's easy enough to add "if (victim.player != me) return;" to the start of the event handler.

If eventDestroyed() catches all objects then that will mandate some extra cruft in the script to filter to specific player, I imagine most of the time you just want your own stuff in there.

If you want to know when other stuff gets destroyed, just enum the stuff you want tracking and add it to groups then use eventGroupLoss() to get notified when stuff leaves the group. Only problem there is you don't know whether it left group because it was put in some other group or died, I guess you could use hackGetObj() to find out if it's still alive?


BTW, I was wondering if an unthrottled eventGroupAttacked(groupNum, by) event would be worthwhile - doesn't necessarily tell you what was attacked, just lets you know something in the group was attacked. Might be a saner alternative to eventAttackedUnthrottled()?
Last edited by aubergine on 19 Dec 2012, 20:46, edited 1 time in total.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

Updated post above.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

Well, I'll just leave it as is for now, but I'm adding a note to eventDestroyed() documentation saying to always check owner of the passed object, in case we want to extend it in the future. So when you start using the API more and run into some brick wall concerning destroyed objects, let me know.
Since everyone else feels like changing their opinions, I'll do it, too. I just changed eventDestroyed() to respond to every destroyed object, regardless of owner.
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

Does the passed in object now have correct .player id for destroyed features? (12 for oil drums, artifacts and oil resources; 99 for all other features)
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

There is no reason to assume that 'player' has any meaningful value for features.
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

I use featureObj.player == 12 as a quick way to determine if it's one of the special features (barrel, artifact or resource).
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO