How to get started at events?

Freeform discussion about anything related to modding Transcendence.
Post Reply
User avatar
TheLoneWolf
Militia Captain
Militia Captain
Posts: 802
Joined: Thu Nov 28, 2013 5:03 pm
Location: Aboard the CSS Radiant

Events...those cursed cancerous lines of code that go over your head...

I want to get started at events (they seem to be the way to get nifty things done) but I don't know how and where (nothing I found was descriptive).
So where did you guys start at? I'd like to start there too!
JohnBWatson
Fleet Officer
Fleet Officer
Posts: 1452
Joined: Tue Aug 19, 2014 10:17 pm

A simple one that I've already worked with is the one for spawning Black Market bounty hunters.

Code: Select all

<Events>
			<OnBountyHunterCheck>
				(if (objGetData gPlayerShip "blackMarketCrimeCost")
					(block (bountyHunter)
						(setq bountyHunter (sysCreateShip &scMolotok; (objGetNearestStargate gPlayerShip) &svBlackMarket;))
						(shpOrderAttack bountyHunter gPlayerShip)
						)
					)
			</OnBountyHunterCheck>

			<OnCreate>
				; Register timer event for bounty hunters
				(sysAddObjRecurringTimerEvent (random 4000 5000) gSource "OnBountyHunterCheck")
			</OnCreate>

			<OnDestroy>
				(intBlackMarketOnDestroy 500000)
			</OnDestroy>
		</Events>
Each of these(<OnBountyHunterCheck>, <OnCreate>, <OnDestroy>) is a separate event that is called under specific circumstances. OnCreate and OnDestroy are preset - the former is called when the station is created by the game, and the latter when it is killed.

OnCreate's task is simple: it calls sysAddObjRecurringTimerEvent, a method that creates a timer and binds it to an event, with some parameters: a random number between 4000 and 5000 indicates how long to wait between timer ticks, and an event(this station's "OnBountyHunterCheck" event) to be called at each tick of the timer. This means that every 4000 - 5000 game ticks(depending on the number rolled when the station was created), the event "OnBountyHunterCheck" will be called.

OnDestroy's code is even simpler: it just calls the method intBlackMarketOnDestroy with parameter 500000. That method increments the playership's variable blackMarketCrimeCost by the parameter specified, but is not tied to this specific station, so it is not within the station's events section.

OnBountyHunterCheck is the most complex of the three, but it's still entry level code, so once you get over the strange formatting and syntax of Tlisp it's easy to understand. In short, it checks if the playership's blackMarketCrimeCost != 0, and, if so, enters a block with space reserved for a variable named bountyHunter. It then sets the previously empty variable "bountyHunter" to a new ship of class scMolotok to be gated in using the gate nearest the playership with the sovereign svBlackMarket. It then orders the new ship to attack the player(it can only reference that ship because it stored it in the variable specified in the block - if it hadn't, we would be able to create the ship, but we wouldn't be able to find it once it had been created).
User avatar
TheLoneWolf
Militia Captain
Militia Captain
Posts: 802
Joined: Thu Nov 28, 2013 5:03 pm
Location: Aboard the CSS Radiant

@JBW

Thanks alot!
Now that I see it, many of the things in the code seem self-descriptive.
Like

Code: Select all

objGetData
gPlayerShip
objGetData clearly gets the data elements (or simply data) of the object to be mentioned, which happens to be gPlayerShip.

After studying it for a while, I'm finding it more and more alike to C++.
We can, you know, take getObjData to be a function that takes the data elements of the object gPlayerShip so that it can pass it as parameters for other functions or vice versa to use them however they want.
But the syntax still seems alien (like I'm looking at Python)
I still don't have an idea what "block" or "setq" can be, and am baffled by what that "if statement" is doing up there.

I seem to be pretty uneducated for someone that's writing a book on modding Trans :|
NMS
Militia Captain
Militia Captain
Posts: 569
Joined: Tue Mar 05, 2013 8:26 am

You should probably start by reading a tutorial on Lisp syntax.

Then you can see the list of functions built into the game here: https://forums.kronosaur.com/viewtopic.php?f=8&t=7567
Unfortunately, many of them don't have descriptions of how they work.

There's information about events on this wiki page.

Events with certain names are called automatically by the game. But you can also make them happen with (objFireEvent obj event [data]) or create a timer that calls events with functions like (sysAddObjRecurringTimerEvent interval obj event).
User avatar
AssumedPseudonym
Fleet Officer
Fleet Officer
Posts: 1190
Joined: Thu Aug 29, 2013 5:18 am
Location: On the other side of the screen.

 There is also a list of functions on Xelerus. Most of these give an example of how to use them. The list is slightly outdated, lacking a number of more recent function additions to the game, but it’s still invaluable — especially since those examples can often be applied or at least to some extent to the functions that aren’t listed there.
Image

Mod prefixes: 0xA010 (registered) and 0xDCC8 (miscellaneous)

My mods on Xelerus: Click here!

Of all the things I’ve lost in life, I miss my mind the least. (I’m having a lot more fun without it!)
User avatar
TheLoneWolf
Militia Captain
Militia Captain
Posts: 802
Joined: Thu Nov 28, 2013 5:03 pm
Location: Aboard the CSS Radiant

@NMS
That wiki was awfully useful ;) ty

@AP
Yeah. I've got a copy of those functions! Thanks!
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

if anybody is interested, I periodically dump the function list on xelerus, so that I can use it offline (or when I'm travelling and I don't have internet)

https://dl.dropboxusercontent.com/u/720 ... onlist.txt
User avatar
TheLoneWolf
Militia Captain
Militia Captain
Posts: 802
Joined: Thu Nov 28, 2013 5:03 pm
Location: Aboard the CSS Radiant

digdug wrote:if anybody is interested, I periodically dump the function list on xelerus, so that I can use it offline (or when I'm travelling and I don't have internet)

https://dl.dropboxusercontent.com/u/720 ... onlist.txt
:D I've already used that function list after the index of the WiP Trans Modding book!
And I have that on my kindle. With Shrike's Unofficial notes and other stuff.
Post Reply