Useful scripts repository
Re: Useful scripts repository
mbmpf...
Re: Useful scripts repository
You can't do this with standard-commands. You have to write a print-text-on-screen-function by your own. But out of the hat I have no solution how to do that...
hudPrint has a given time.
hudPrint has a given time.
Re: Useful scripts repository
Welp I am an idiot xDTHOM wrote:You can't do this with standard-commands. You have to write a print-text-on-screen-function by your own. But out of the hat I have no solution how to do that...
hudPrint has a given time.
Thank you so much though!
Re: Useful scripts repository
Note: hudPrint() can be called again. If you call hudPrint five times in succession, with the first four times using empty strings, the fifth will [seem to] overprint the first message, with no fading text above it. If you call a function that does this, every seven seconds, it should just look like it's the same message on the screen until seven seconds after you stop calling it.
*BTW... Which game are you using? (This thread is for Grimrock 1.)
*BTW... Which game are you using? (This thread is for Grimrock 1.)
Re: Useful scripts repository
This simply does not work. I have tried everything and tested every scenario possible. My guess is that in the course of 6 years since this was posted, some of the variables have changed and thus, are returning nil values. No matter what I do, any item I pick up and place in inventory doesn't trigger the script to execute the true function.Billick wrote:A couple of script functions I wrote to check if anybody in your party is carrying a particular type of item:
The first function calls the second function. Pass in the name of the item you want to check for into checkForItemParty. You would use it like this:Code: Select all
function checkForItemParty(item) local i = 1 repeat if checkForItem(party:getChampion(i), item) then return true end i = i + 1 until i == 5 return false end function checkForItem(champion, item) local i = 1 repeat local itemObj = champion:getItem(i) if itemObj ~= nil then if itemObj.name == item then return true end end i = i+1 until i == 32 return false end
Edit: fixed invalid function namesCode: Select all
if checkForItemParty("torch") then print("We have a torch") else print("We don't have a torch") end
Can somebody please check the above and let me know what's changed. This is for LoG 1, not 2.
Re: Useful scripts repository
Gotcha #1... The party does not start with a torch. First try taking a torch from the wall, and test again.
Otherwise, it is that checkForItem script needs to be visible from where you call it. It should work if all three functions are in the same script, but if you are calling it from another script, you must use the object id of the checkForItemParty script; as prefix.
As is, the calling code block only runs once. If you want to call it from a script or trigger object, it must be encapsulated in a function block; or (if from a user script) call the checkForItemParty(item) function directly.
Optional (changed) version of the script:
This version expects to extract the item name from the trigger.id of the plate, button, or switch used to call it.
For example: A connected button named, wall_button_1@rotten_pitroot_bread, would check the party for rotten pitroot bread.
(Also returns the name of the first champion to have the item.)
Otherwise, it is that checkForItem script needs to be visible from where you call it. It should work if all three functions are in the same script, but if you are calling it from another script, you must use the object id of the checkForItemParty script; as prefix.
As is, the calling code block only runs once. If you want to call it from a script or trigger object, it must be encapsulated in a function block; or (if from a user script) call the checkForItemParty(item) function directly.
Code: Select all
function check()
if checkForItemParty("torch")
then print("We have a torch")
else print("We don't have a torch")
end
end
SpoilerShow
Code: Select all
function checkForItemParty(item)
local i = 1
repeat
local test, championName = checkForItem(party:getChampion(i), item)
if test --successful
then return true, championName
end
i = i + 1
until i == 5
return false
end
function checkForItem(champion, item)
local i = 1
repeat
local itemObj = champion:getItem(i)
if itemObj ~= nil then
if itemObj.name == item
then return true, champion:getName()
end
end
i = i+1
until i == 32
return false
end
function checkByTrigger(triggerId)
if triggerId and triggerId.id then
local index = triggerId.id:find("@")
local item = "<no item>"
if index and index < #triggerId.id then
item = triggerId.id:sub(index+1)
else print("Error: no index character in trigger object id")
end
local test, championName = checkForItemParty(item)
if item then
---[[
print(championName,"has the item :"..item)
--]]
else print(championName,"doesn't have the item :"..item)
end
return
end
print('Error: table expected, got', triggerId," ")
end
For example: A connected button named, wall_button_1@rotten_pitroot_bread, would check the party for rotten pitroot bread.
(Also returns the name of the first champion to have the item.)