PDA

View Full Version : Question about looting...



Rarnd Araki
05-01-2012, 08:31 PM
Hi guys,

I am new to both Ruby and Lich (and programming for that matter), and I have a question about looting. DISCLOSURE: I know there are scripts out there that do this, but I want to write my own scripts to learn Ruby.

I have some characters on the CoL path and I want to setup a skinning script that loots only the skin in the room. I've had a look at Loot3 and Lootit but I just can't make heads or tails of this part.

I know I need an array of all the skins, and I know I need to make use of checkloot / GameObj.loot. Otherwise, I'm fairly stumped.

Here's a snippet of what I'm thinking, but this is in no way functional code. Input please!

skin = ["tailspike", "tailfeather", "fur", "fin", "nail", "canine", "antlers", "bone", "beard", "carapace", "claw", "crest", "ear", "eye", "eyeball", "fang", "feather", "feathers", "firethorn", "heart", "hide", "horn", "hoof", "incisor", "jawbone", "knuckle", "spider leg", "mandible", "mane", "nose", "paw", "pelt", "pincer", "plume", "scalp", "sail", "scraping", "shroud", "skin", "skull", "snout", "stinger", "tail", "talon", "thumb", "toe", "tooth", "tongue", "tusk", "wing", "whisker", "ambergris"]
loot = checkloot
if skin.include?(loot) === true
fput "get #{loot}"
end

DaCapn
05-01-2012, 11:33 PM
If you look in the gameobj-data.xml file in your lich scripts directory, you can see that object types are already defined within lich (for the most common items) and are accessible using the 'type' method. No need to build a list yourself. For example, this is an array of objects that are of a type that includes the word skin:

GameObj.loot.find_all { |obj| obj.type =~ /skin/ }

You can iterate over that with 'each' in the usual fashion to collect them. The checkloot function just collects a list of non-npc nouns that are in the "you notice" line of a room description.

Also, you're using 'include?' incorrectly, the proper syntax uses data types as follows: array.include?(string). It check the array for instances of string. You're feeding it 'array.include?(array)'. Don't assume you can cram whatever you want anywhere and that things will just fall out properly because when you read it aloud, the grammar is basically correct.

There was a thread called something like 'looting armor' or 'armor in disks' in this category where I posted a version of my loot function. You may get some ideas there. Always take a look at other scripts that do similar things.

Rarnd Araki
05-02-2012, 11:35 AM
Wow, thank you! Obviously I have MUCH to learn and this is a big help.

I've always wanted to try programming but couldn't find any task that sustained my interest, but now - building Gemstone scripts in Ruby? That's almost too good...