a looting mod & several questions

Freeform discussion about anything related to modding Transcendence.
Schnobs
Miner
Miner
Posts: 36
Joined: Fri Mar 23, 2012 8:49 pm

What I have in mind: a Loot Scanner that will notify you about shipwrecks that are worth docking with.
Between the mining scanners and looting autons, I don't think this will require too much original work.

Which brings me to question #1: is it okay to reuse other people's code without asking?

Next, as I don't think I'll get things right on the first try: how does one go about debugging?
Does Transcendence provide useful error messages or, well... I have no idea what I could do if it doesn't.

Finally, is there a way for me to get this working in my current game? Like, hijacking and extending the
mining scanner I'm currently employing? I don't want to start over and frankly, I'll only try to get this started
if I can expect to use it right away.
RPC
Fleet Admiral
Fleet Admiral
Posts: 2876
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

Schnobs wrote:Which brings me to question #1: is it okay to reuse other people's code without asking?
It's best to ask first through a PM on the forums (as I have), but if the user is long gone, wait a while for a reply before you use it. I think the original modder can still ask for you to remove the offending code if it's misused.

To debug, you could use the dbglog function, but it's best to learn the simple stuff (xml) before going on to tscript, unless you know another language first.
Tutorial List on the Wiki and Installing Mods
Get on Discord for mod help and general chat
Image
Image
Der Tod ist der zeitlose Frieden und das leben ist der Krieg
Wir müssen wissen — wir werden wissen!
I don't want any sort of copyright on my Transcendence mods. Feel free to take/modify whatever you want.
sdw195
Militia Captain
Militia Captain
Posts: 779
Joined: Wed Nov 18, 2009 1:01 am
Location: Still looking for the csc Antarctica
Contact:

(dbglog) is your friend, use it ever other line if you want to know where something is breaking, trust me on that, I have done it!

irc is the best place to learn to code, there are almost always a experienced coder online, and if you hang around for while, someone will answer your questions.
Image
Image
Image
Image
"Dash_Merc - George is a genius, in that he created this game engine that is infinitely extendable"
"<@sheepluva>Good night everybody, may the source be with you." <-- FOSG dev
"You only need THREE tools in life - WD-40 to make things go, Duct Tape to make things stop And C-4 to make things go away"
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

A lot of modders have already given free access to their code. So, as long as you don't copy a mod wholesale and claim it is yours, you should be ok. If you have been heavily inspired by another mod, then give credit where it is due, and you should be ok as well :)
Get your own Galactic Omni Device
Get it now. It's free!!
Image
shanejfilomena
Fleet Officer
Fleet Officer
Posts: 1533
Joined: Tue Mar 22, 2011 8:43 pm
Location: Alaska
Contact:

alterecco wrote:A lot of modders have already given free access to their code. So, as long as you don't copy a mod wholesale and claim it is yours, you should be ok. If you have been heavily inspired by another mod, then give credit where it is due, and you should be ok as well :)
Your shipwreck notification is cool : but I was thinking that it might be calling the OnUpdate for looping the system for wrecks will call too much ( considering the system and what goes in a given system, like a binary has alot going on for updates. )

George did say : " use OnUpdate sparingly " so this is what I think you should keep in mind while you test your ideas.

As for what alterecco said : I would add to at least attempt to PM the extension maker : and/or post for input on what your going to use in the drawing board : so if there is a "no" waiting to happen or the makers have changed names they can get the info and be shocked at your politeness of asking :)
Flying Irresponsibly In Eridani......

I don't like to kill pirates in cold blood ..I do it.. but I don't like it..
Schnobs
Miner
Miner
Posts: 36
Joined: Fri Mar 23, 2012 8:49 pm

shanejfilomena wrote: Your shipwreck notification is cool : but I was thinking that it might be calling the OnUpdate for looping the system for wrecks will call too much
I didn't even really try to get started... the code almost makes sense, but I can't really fathom the ramifications.
Here's a snippet from the "Prospector" ore scanner I use and what I think it means:

Code: Select all

<Events>
            <OnUpdate>
                (if (and (or (eq gSource gPlayerShip)                                                              # the first three lines seem to deal with wether I may scan at all
                    (and (not (objIsEnemy gSource gPlayerShip))                                                 # but I don't quite get what it's really checking
                    (eq (objGetOrderGiver gSource) gPlayerShip)))                                                # also, syntax / indentation seems quite weird
                    (filter (objGetItems gSource "cI") itm (eq (itmGetType itm) &itMinersCargoHold;)))  
#
# The above is true if ( (gSource == gPlayerShip) OR (the next two conditions are both true) ) AND ( I have the necessary equipment)
#
 

                   (block (roids)
                        (setq roids (filter
                            (sysFindObject gSource "t +asteroid; N:16;")                               # find asteroids in range (16 lightseconds, I presume)
                            roid
                            (gr (count (objGetItems roid "t +Ore;")) 0)))                                # all further tests apply only to rocks in scanner range
But, oh boy. What's "gSource"? What's "gr"? And where do I find out without bothering someone for every small thing?

Anyway, back to topic: I don't quite know how "OnUpdate" works, but this function looking for rocks in range works well on my oldish machine.
Assuming that you'll only rarely end up with as many shipwrecks as there are rocks in a mid-sized asteroid belt, I'm not worried about CPU time.

On the other hand, the actual checks to be performed on the wrecks-in-range would be a bit more complicated, and you could end up with quite a few wrecks in a dense cluster.
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Your analysis is quite spot on. Indeed, the indenting could have been a bit better in that example. The best place to see what functions are, is on xelerus.de. In this case, 'gr' is 'greater than'. gSource and gPlayerShip are global variables (therefore the 'g'). gSource always points to the object the event is running on. So, say I have an OnUpdate on the playership: Then gPlayerShip would equal gSource. It is also often used in Dock Screens to signify the station showing the screen. You should not be worried about CPU time of OnUpdate unless you are doing something crazy in it or have it placed on some item that is spawned very many times.

For general help with 'silly questions' there really is no better place than IRC. We are a quite active modding community there, and I am sure you would feel welcome.
Get your own Galactic Omni Device
Get it now. It's free!!
Image
RPC
Fleet Admiral
Fleet Admiral
Posts: 2876
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

Also, to add what 'ecco said, there's also a decent events page on the wiki. It has most documented global variables there.
Tutorial List on the Wiki and Installing Mods
Get on Discord for mod help and general chat
Image
Image
Der Tod ist der zeitlose Frieden und das leben ist der Krieg
Wir müssen wissen — wir werden wissen!
I don't want any sort of copyright on my Transcendence mods. Feel free to take/modify whatever you want.
Schnobs
Miner
Miner
Posts: 36
Joined: Fri Mar 23, 2012 8:49 pm

yep, http://wiki.neurohack.com/transcendence ... xml/events -- someone on IRC tossed that at me.

Which brings me to
wiki/events wrote: <OnUpdate>

Populated variables:

gSource: object that carries the item
gItem: the item
Looking at the code again...

Code: Select all

<OnUpdate>
                (if (and (or (eq gSource gPlayerShip)
                    (and (not (objIsEnemy gSource gPlayerShip)) 
                    (eq (objGetOrderGiver gSource) gPlayerShip)))
                    (filter (objGetItems gSource "cI") itm (eq (itmGetType itm) &itMinersCargoHold;)))
I wonder why the tests were considered necessary.
If I understand it correctly, OnUpdate is tied to a specific item anyway. There might be any number of OnUpdates for any number of items, but each OnUpdate event, when it happens, refers to a particular item. In our case, (eq gItem itMinersCargoHold) and (eq gSource gPlayerShip) would both be true by definition. Why test them?

Or rather: what did I get wrong?
User avatar
WillyTheSquid
Militia Lieutenant
Militia Lieutenant
Posts: 195
Joined: Wed Jan 18, 2012 4:32 pm
Location: Rotterdam, The Netherlands

As far as I'm concerned, you can use the mining scanner code, but it's TransGeek's work so you might wanna check with him.

Lootscanner for the win :D
Image

“Normal people believe that if it ain't broke, don't fix it. (Modders) believe that if it ain't broke, it doesn't have enough features yet.” -Scott Adams

Resident mod-cobbler-together, freakspawn-fixer-upper & musical eclectro-ecumenologist.
If you love something, tweak it and twist it. Keep bending it until it breaks. Rip it apart, remix it, rebuild it. Kill your darlings and stitch them together again.

JOIN US ON IRC. IT KICKS ASS. JOIN THE HIVE MIND.
Place cursor on link. Click link. Never look back.
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Schnobs wrote: I wonder why the tests were considered necessary.
If I understand it correctly, OnUpdate is tied to a specific item anyway. There might be any number of OnUpdates for any number of items, but each OnUpdate event, when it happens, refers to a particular item. In our case, (eq gItem itMinersCargoHold) and (eq gSource gPlayerShip) would both be true by definition. Why test them?
One could imagine a scenario where a cargo hold ended up on an enemy AI ship. I seems to me that the Prospector is installable on a wingman, perhaps through UGWingmen or some similar mod use.

For a simpler use case one could probably get away with something like the following:

Code: Select all

<OnUpdate>
  (if (and (eq gSource gPlayerShip)
             (itmIsInstalled gItem))
    (block nil
      ;; your code here
    )
  )
</OnUpdate>
Get your own Galactic Omni Device
Get it now. It's free!!
Image
Schnobs
Miner
Miner
Posts: 36
Joined: Fri Mar 23, 2012 8:49 pm

alterecco wrote: For a simpler use case one could probably get away with something like the following:
OK, so it might be elsewhere, I get that.
But one needs to check wether it's installed? Does that mean OnUpdate is called regularly as long as the item exists, even if it's just sitting in my cargo hold (or some shop)?


And while I'm at it, the next one (this is a little like pronouncing every single letter as my finger slides across the page):
This is pretty much copy/paste... so it ought to work, but I don'k now why.

Code: Select all

(block (wrecks)  ; I don't quite get why I need this at all. 
	(setq wrecks                                                                               ; create a listnamed "wrecks"
		(filter (sysFindObject gSource "tM -populated; N:25") wreck       ; populate the list with wrecks-in-range...?
Hold it. That last line does so many things at once, it should be like five lines.
The (sysFindObject ...) is wrecks-in-range. This is the list I'll work with next.
(filter ... wreck (stuff)) opens a FOR loop, with "wreck" being the temporary handle for every wreck-in-range while I do (stuff).

So basically,
"for WRECK in (get wrecks-in-range) do (stuff)" -- note that (stuff) isn't in the example.
Sounds simple enough once got my head around it. It just took me quite a while to see it that way.
No please tell me that I'm right.

Other than that, I want this to work only on shipwrecks, not stations. Is there away to distinguish between the two?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Schnobs wrote:Does that mean OnUpdate is called regularly as long as the item exists, even if it's just sitting in my cargo hold (or some shop)?
Yep, iirc.
Schnobs wrote:And while I'm at it ...snip...
A short explanation... hope it clarifies. But yeah, basically you are right.

Code: Select all

(block (wrecks)          ;; this defines 'wrecks' as a variable local to the block (otherwise it would be global!)
  (setq wrecks           ;; actually set the variable
    (filter ....         ;; loops over every element in a list and returns a new list with every element that the "stuff" expression returned true for
Schnobs wrote:Other than that, I want this to work only on shipwrecks, not stations. Is there away to distinguish between the two?
Not in any easy way... at least there is no (objIsWreck ....) function :/

Last i did this (and this is years ago), i checked if the visible damage of an object was 100, or if its name included the string "wreck". We might have gotten an attribute since then, but I am not sure.

Here is the check i used:

Code: Select all

(or (eq (objGetVisibleDamage obj) 100) (strFind (objGetname obj) "wreck"))
Good luck ;)
Get your own Galactic Omni Device
Get it now. It's free!!
Image
User avatar
Atarlost
Fleet Admiral
Fleet Admiral
Posts: 2391
Joined: Tue Aug 26, 2008 12:02 am

Wrecks are not active. That's something you can check for in the criteria string for sysfindobject.

Criteria are kind of messy. See http://wiki.neurohack.com/transcendence ... t_criteria.
Literally is the new Figuratively
Schnobs
Miner
Miner
Posts: 36
Joined: Fri Mar 23, 2012 8:49 pm

Atarlost wrote:Wrecks are not active. That's something you can check for in the criteria string for sysfindobject.
Nah, I meant only shipwrecks, not stationwrecks. Both are wrecks and inactive and everything... anyway, that's cosmetic.

I now tried my code for the first time and guess what? It doesn't work.
I attached it to the ore scanner, like this:

Code: Select all

(if we may scan
   (scan asteroids for ore)
   (scan wrecks for loot)
)
Now, OnUpdate I get my code displayed on the screen. Is that alone a hint as to the nature of my mistake?
Post Reply