Page 11 of 11

Re: Useful scripts repository

Posted: Sat Aug 13, 2016 7:46 pm
by THOM
mbmpf... :evil:

Re: Useful scripts repository

Posted: Sat Aug 13, 2016 7:50 pm
by THOM
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.

Re: Useful scripts repository

Posted: Sat Aug 13, 2016 8:35 pm
by Howl3r
THOM 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.
Welp I am an idiot xD
Thank you so much though! :)

Re: Useful scripts repository

Posted: Sat Aug 13, 2016 9:24 pm
by Isaac
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.)

Re: Useful scripts repository

Posted: Sat Feb 17, 2018 9:50 pm
by wagtunes
Billick wrote:A couple of script functions I wrote to check if anybody in your party is carrying a particular type of item:

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
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

if checkForItemParty("torch")
 then print("We have a torch")
 else print("We don't have a torch")
end
Edit: fixed invalid function names
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.

Can somebody please check the above and let me know what's changed. This is for LoG 1, not 2.

Re: Useful scripts repository

Posted: Sun Feb 18, 2018 5:12 am
by Isaac
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.

Code: Select all

function check()

	if checkForItemParty("torch")
	 then print("We have a torch")
	 else print("We don't have a torch")
	end

end
Optional (changed) version of the script:
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
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.)