"fun with filters 2" the filter strikes back

This is a moderated forum that collects tutorials, guides, and references for creating Transcendence extensions and scripts.
Post Reply
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

due to the nice response to my filter thread I am giving a little more advanced example (I am planning a more advanced example still but that will need some thought)

Code: Select all

(setq items (objGetItems gSource "*"))

;filter out things that can not be tranformed into other things
(setq items (filter items element (itmGetStaticData element "tranformable")))

;pick an item at random

(setq randomPick (item (shuffle items) 0))

;find what items it can be combined with

(setq items (filter items element (itmGetStaticData element (cat "startWith" (itmGetStaticData randomPick "prefixTransform")))))

;pick an random ending item

(setq randomEndPick (item (shuffle items) 0))

;get all the items
(setq allItems (itmGetTypes "*"))

;filter out all items that do not a result of this

(setq allItems (filter allItems element (itmGetStaticData (itmCreate element 1) (cat (itmGetStaticData randomPick "prefixTransform") (itmGetStaticData randomEndPick "postfixTransform"))))) 

;get random result

(setq result (item (shuffle allItems) 0))

the head enjineer at tinker station take a look at your cargo and says "hey i can take this [put name here] and [put second name] and i could make you this wonderful [result].

Code: Select all

;remove old items

(objRemoveItem gSource randomPick 1)
(objRemoveItem gSource randomEndPick 1)

;add new item
(objAddItem gSource (itmCreate result 1) 1)
warning this has no error checking so you have to add your own
Last edited by Betelgeuse on Tue Aug 05, 2008 10:29 pm, edited 1 time in total.
Crying is not a proper retort!
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

now let's mod all the items to add staticdata to them for the tinker station !
User avatar
Aury
Fleet Admiral
Fleet Admiral
Posts: 5421
Joined: Tue Feb 05, 2008 1:10 am
Location: Somewhere in the Frontier on a Hycrotan station, working on new ships.

:lol: lol, I was going back and adding in special tags to every weapon (like a standard laser was "etc...; single; laser1" then dual turbolaser is "...etc; multi2; laser2" etc...
I was planning on doing something similar w/ the code... :D
(shpOrder gPlayership 'barrelRoll)
(plySetGenome gPlayer (list 'Varalyn 'nonBinary))
Homelab Servers: Xeon Silver 4110, 16GB | Via Quadcore C4650, 16GB | Athlon 200GE, 8GB | i7 7800X, 32GB | Threadripper 1950X, 32GB | Atom x5 8350, 4GB | Opteron 8174, 16GB | Xeon E5 2620 v3, 8GB | 2x Xeon Silver 4116, 96GB, 2x 1080ti | i7 8700, 32GB, 6500XT
Workstations & Render machines: Threadripper 3990X, 128GB, 6900XT | Threadripper 2990WX, 32GB, 1080ti | Xeon Platinum 8173M, 48GB, 1070ti | R9 3900X, 16GB, Vega64 | 2x E5 2430L v2, 24GB, 970 | R7 3700X, 32GB, A6000
Gaming Systems: R9 5950X, 32GB, 6700XT
Office Systems: Xeon 5318Y, 256GB, A4000
Misc Systems: R5 3500U, 20GB | R5 2400G, 16GB | i5 7640X, 16GB, Vega56 | E5 2620, 8GB, R5 260 | P4 1.8ghz, 0.75GB, Voodoo 5 5500 | Athlon 64 x2 4400+, 1.5GB, FX 5800 Ultra | Pentium D 3.2ghz, 4GB, 7600gt | Celeron g460, 8GB, 730gt | 2x Athlon FX 74, 8GB, 8800gts 512 | FX 9590, 16GB, R9 295x2 | E350, 8GB | Phenom X4 2.6ghz, 16GB, 8800gt | random core2 duo/atom/i5/i7 laptops
User avatar
Betelgeuse
Fleet Officer
Fleet Officer
Posts: 1920
Joined: Sun Mar 05, 2006 6:31 am

oh don't use shuffle to get a random item from a list you can use random. I forgot about that aspect of random.
Crying is not a proper retort!
Post Reply