Page 1 of 2
[Script] You steal my stuff! (crowern that steals items)
Posted: Mon Oct 22, 2012 3:27 pm
by Grimwold
I was hit by a revelation that you could add items to a monster on-the-fly, which lead straight to me scripting this stealer-bird... it's basically a Crowern that, when it deals damage, has a 60% chance to steal an item from slots 1 - 8 of the champion it damaged.
At the moment I don't know how to make the monster run away, like the gigglers did in DM, but it's a start. Also could be the basis of a rust monster, remove an item and replace it with a rusted version (or otheriwse a "pile of rust").
place this definition in your
monsters.lua
Code: Select all
cloneObject{
name="stealer_bird",
baseObject = "crowern",
attackPower = 15,
onDealDamage = function(self,champion,amount)
return stealer_script.stealItem(self,champion,amount)
end,
}
REVISED SCRIPT
add a
script_entity called
stealer_script and add this code:
Code: Select all
function stealItem(self,champ,amount)
if math.random(1,10) > 4 then
local w = 1
local slot_list = {}
for z = 1,8 do
local temp_item = champ:getItem(z)
if temp_item ~= nil then
slot_list[w] = z
w = w + 1
end
end
if #slot_list > 0 then
champ_slot = slot_list[math.random(1,#slot_list)]
-- hudPrint("Steal now, Steal now!")
local item = champ:getItem(champ_slot)
champ:removeItem(champ_slot)
self:addItem(item)
end
end
end
In this revised script there's a 60% chance that the crowern will steal an item from the champion it damaged. The script checks slots 1 to 8 and builds a list of where items are and then selects one at random.
ORIGINAL SCRIPT
add a
script_entity called
stealer_script and add this code:
Code: Select all
function stealItem(self,champ,amount)
if math.random(1,10) > 4 then
hudPrint("Steal now, Steal now!")
local champ_slot = math.random(1,8)
local item = champ:getItem(champ_slot)
if item ~= nil then
champ:removeItem(champ_slot)
self:addItem(spawn(item.name))
end
end
end
at the moment the script spawns a new copy of the stolen item, with a different item_id... which could be a problem for items that have been given a very specific ID. I am working on a way to re-spawn the item with the same id.
Re: [Script] You steal my stuff! (crowern that steals items)
Posted: Mon Oct 22, 2012 4:09 pm
by Grimwold
OLD POST
Revised
script_entity called
stealer_script and add this code:
Code: Select all
function stealItem(self,champ,amount)
if math.random(1,10) > 0 then
hudPrint("Steal now, Steal now!")
local champ_slot = math.random(1,8)
local item = champ:getItem(champ_slot)
if item ~= nil then
champ:removeItem(champ_slot)
spawn_name = tostring(item.name)
if string.len(item.id) > 5 then
spawn_id = item.id
else
spawn_id = nil
end
item:destroy()
self:addItem(spawn(spawn_name,nil,nil,nil,nil,spawn_id))
end
end
end
I was having trouble re-spawning items with the same id, specifically because if an item was originally spawned with a random ID, then spawn() would not accept that as a valid id... so I used a little trick to check if the ID was greater than 5 characters (random IDs are all 4 digit numbers - I chose 5 in the rare case that it goes above 9999) if so, use the actual id... otherwise use a new random id.
Therefore the only potential issue now is if you have a specific named ID (that needs to not change!!!) that is 5 or fewer characters e.g. "gem_1" ... hopefully that chance is very unlikely.
Re: [Script] You steal my stuff! (crowern that steals items)
Posted: Mon Oct 22, 2012 4:12 pm
by Merethif
Sounds promising, as always with your scripts. I can't wait to test it when I get back home from work.
Now if wallasaurus will be so kind and create a flying monkey or at least gremlin

Re: [Script] You steal my stuff! (crowern that steals items)
Posted: Mon Oct 22, 2012 4:27 pm
by Batty
Once the bird has met the 60% steal probability, shouldn't it then cycle once through all the champs items until it finds an item? If it just picks one slot, that slot may be empty and then chances of a steal are too slim to me.
Also, can you do
Code: Select all
self:addItem(champ:getItem(champ_slot))
and avoid the string manipulation? Or does that cause one of those "attempt to access table" or whatever crashes?
I'm trying to make more scripting work for you because I know you like big, complicated scripts.

Re: [Script] You steal my stuff! (crowern that steals items)
Posted: Mon Oct 22, 2012 5:10 pm
by Grimwold
Batty wrote:Once the bird has met the 60% steal probability, shouldn't it then cycle once through all the champs items until it finds an item? If it just picks one slot, that slot may be empty and then chances of a steal are too slim to me.
You're quite right, it picks a slot at random, which might be empty. I could probably eliminate the 60% test and just have it steal something everytime and have the 'reduction' simply be based on if the slot is empty (it was getting annoying testing it when it kept failing to steal something!!)
I initially didn't want to cycle through the slots, as that felt a bit predictable.... hmm but perhaps a
repeat math.random() until item ~= nil solution would work instead!!
Batty wrote:Also, can you do
Code: Select all
self:addItem(champ:getItem(champ_slot))
and avoid the string manipulation? Or does that cause one of those "attempt to access table" or whatever crashes?
I will try this when I get chance... I must admit I shied away from trying this just in case it was a crash generator.
Batty wrote:I'm trying to make more scripting work for you because I know you like big, complicated scripts.

lol. Thanks

I do like a challenge.
Re: [Script] You steal my stuff! (crowern that steals items)
Posted: Mon Oct 22, 2012 5:21 pm
by Grimwold
This does work:
Code: Select all
champ:removeItem(champ_slot)
self:addItem(champ:getItem(champ_slot))
The removal is needed to actually have the item removed from the champion.. otherwise a duplicate is created and if you try and put them both down on the ground at the same time, the game crashes.
Also, it might be similar to what Petri said not to do in his comment here:
viewtopic.php?f=14&t=3379&start=10#p34294
EDIT - also the problem with using repeat - until.... if all possible items have been taken, then the game locks up trying to find something to steal when none exist.
Re: [Script] You steal my stuff! (crowern that steals items)
Posted: Mon Oct 22, 2012 5:48 pm
by Batty
You could cycle through all 8 slots and create a table of the champs items, maybe 5 of the slots have items so a table of 5. Then pick a random item from that table.
I like the rust monster, having your prized sword turned into a pile of rust is hilarious.
Re: [Script] You steal my stuff! (crowern that steals items)
Posted: Mon Oct 22, 2012 6:10 pm
by JohnWordsworth
Brilliant! I'm reminded of those little thieving guys from Dungeon Master 'ruh-huh ruh-huh'. Used to hate those guys (but loved them for being in the game!).
As Batty said, I think a good solution is to pick a character at random and then build an array (well, table in Lua), of all of the item slots that have an item in by iterating over every slot (skipping body armour perhaps). If the resulting table of slotNumbers is empty, then don't steal anything. Otherwise, pick an index at random and steal the item in that index. You could easily filter out certain items then too (maybe nothing with a weight over a certain threshold can be stolen for realism).
Re: [Script] You steal my stuff! (crowern that steals items)
Posted: Mon Oct 22, 2012 6:16 pm
by Merethif
Batty wrote:(...) I like the rust monster, having your prized sword turned into a pile of rust is hilarious.
Exactly, as a DM I always have been thinking about it being hilarious...
To my utter surprise, my players haven't been laughing that much

Re: [Script] You steal my stuff! (crowern that steals items)
Posted: Mon Oct 22, 2012 6:19 pm
by Grimwold
Thanks for the great suggestions guys. I will definitely look at this more when I get some time tonight.
champion is currently picked according to who is damaged by the monster... after that I will look at building a table of remaining items to steal from.
I actually had rooms I'd created in (my aborted attempt to use) ReturnToChaos, that used Rusters and Gigglers.. so was thinking of re-creating those... if only I could get monsters to run away when they'd stolen... that was half the fun with the gigglers... chasing after the little buggers.