I just wondered could anybody help me with a script I'm stuck on. I want to write a script that when a fire golem or a fire elemental reads a scroll, there is a high chance of the scroll burning. I have looked at the balrog aura corruption in the corruption lua file but I don't understand it. I think I know how to do a script that would destroy *all* scrolls the fire subraces tried to read, but I wanted to give them a small chance of not destroying the scrolls.
Thanks from CosmicGerbil
TheFalcon: I looked at the balrog Aura script and didn't understand it either, since what it returns doesn't seem to correspond with the description of HOOK_READ in util.pkg.
Anyway, in order to get a chance to do something, all you need to do is something like:
if (randint(100) > 10) then destroying script goes here... end
This will give a 10% chance to *not* do the destroying script. I was in the mood, so I wrote a basic kind of thing. It's not race specific, but I think it does what you want. You can change it as necessary though.
function read(item)
if (randint(100) > 10) then
local i = 0
local scroll_present = FALSE
local scroll
while i < INVEN_TOTAL do
o_ptr = player.inventory(i)
if (o_ptr == item) then
-- msg_print("It's there!")
scroll = i
scroll_present = TRUE
end
i = i + 1
end
if (scroll_present == TRUE) then
msg_print("The scroll burns before you can read it.")
inven_item_increase(scroll, -1)
inven_item_optimize(scroll)
end
return TRUE
end
end
add_hook_script(HOOK_READ, "read", "read")
Hmm, testing shows that it doesn't work for scrolls on the floor, either I'm afraid, but I don't know how to find whether the scroll is there, rather than in the inventory. You might find a better way to do it that I have...
Well you can destroy stuff on the floor with:
floor_item_increase(int item, int num) floor_item_optimize(int item)
But I still can't work out how to scan through the objects. it would be easier to just be able to delete the scroll directly, but I'm afraid I don't know how.
Sorry, I'm not sure this is really much help after all... :-/
CosmicGerbil This script looks really cool. Thanks for writing it. I've copied it onto my memory stick and I'll have a play with it tonight, and see if I can add in the fire subrace stuff.
I wasn't too worried about burning scrolls on the floor, I just thought that the fire golem/elementals would walk around them
CosmicGerbil I tested the script last night (Oct 27), and it is just what I wanted
I've added in a couple of lines to make the script only work for the fire golem and fire elemental, and it will be in the next version of Gerband and Gerband Enhanced. Thanks again for writing it.
Sorgath I've just been wandering around the wiki looking for interesting things and felt i should explain how HOOK_READ works for the next person who wants to know.
There are three booleans you can return from your HOOK_READ function. The description in util.pkg says the first is for whether the scroll was read or not. This is wrong!!!
There first boolean returned determines whether or not to run the default action for the scroll. This is because HOOK_READ is processed BEFORE the original scroll code allowing new lua functions to override the original C code. If the first boolean returned is FALSE then the original scroll spell effect will be cast.
By returning TRUE, TRUE, FALSE for when the scroll is supposed to burn the lua code is basically preventing the default scroll code from running but still reducing the number of scrolls in the stack by 1. The final false is because the scroll wasn't actually read therefore it can't be identified by reading. If you return FALSE with the first variable then the game will continue on as though your HOOK_READ function never existed.
ToME Wiki