Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
poomanchu
Posts: 3
Joined: Sat May 28, 2016 8:49 pm

Re: Ask a simple question, get a simple answer

Post by poomanchu »

I have another question. I've gone over the scripting basics an few times and still can't figure out how to write this out correctly. I want a sickle_sword to be placed on a pedestal and open a dungeon_door_wooden_double. I did it once, had to exit and forgot to save so I can't go back and read over what I did. What I have put since then is:

--sword to door secret
function checkSword()
if sickle_sword_1.sword:isInserted() then
dungeon_door_wooden_double_1.door:open()
else
dungeon_door_wooden_double_1.door_close()
end
end

I connect the pedestal to the script entity and the door to the pedestal as the second connector. Sometimes it works and sometimes it doesn't.
If I place something else on it I get kicked to the script entity about a nil file and when I put the sword on it I sometimes get kicked to the entity with the same message about a nil file. How would you write this out??
User avatar
Illidan
Posts: 19
Joined: Sat Mar 12, 2016 3:23 pm
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Illidan »

@poomanchu:
Hi. It may be possible that your script is faulty. Also, you do not need to connect the door to the pedestal, the script does what is needed. In addition, in the line "dungeon_door_wooden_double_1.door_close()" is an error! It has to be: "dungeon_door_wooden_double_1.door:close()"

Place a script entity in your dungeon level and write the following two functions in it. Important: only connect the pedestal to function checkSword()!

function surfaceContains(surface, item)
for v,i in surface:contents() do
if i.go.name == item then return true
end
end
end

function checkSword()
if surfaceContains(pedestal_1.surface, "sickle_sword") then
dungeon_door_wooden_double_1.door:open()
else
dungeon_door_wooden_double_1.door:close()
end
end

For pedestal_1 you must enter the entity id of the pedestal that you have placed in your dungeon (perhaps you have named it pedestal_24 or green_pedestal or whatever).
If you want the specific sickle_sword_1 to be used (and no other sickle_sword) then replace "sickle_sword" in the script with "sickle_sword_1".
That should do it. ;)
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Minor bug (only if a specific item is intended): The script does not make use of the item id string; it only checks for the correct item name... The [sickle] sword could be called anything, changing the item id (to sicklesword_1) would not change the item name; so the sickle_sword could be called 'hooked_dagger_1', and it would still open the door, for having the item name 'sickle_sword'.
User avatar
Illidan
Posts: 19
Joined: Sat Mar 12, 2016 3:23 pm
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Illidan »

Ah, yes, you are right, Isaac!
Alright, my script is not perfect... but anyway, the script might do the job for poomanchu, I think. :D
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Illidan wrote:the script might do the job for poomanchu, I think. :D
Indeed. ;)
I rather liked the original script.

*But if a user really needs the optional choice to restrict to a specific item [key], then this modification of Illidan's original script can allow it:

Code: Select all

function surfaceContains(surface, item, checkId)  -- Added optional input of checkId [item.go.id]
	for v,i in surface:contents() do
		if checkId then
			if i.go.id == checkId then
				return true
			end
		 else
			if i.go.name == item then
				return true
			end
		end
	end
end

function checkSword()  -- The OPTIONAL inclusion of a checkId string as a third argument, causes it to check for that Id instead of the name.
	if surfaceContains(pedestal_1.surface, "sickle_sword", "sickle_sword_1") then
		dungeon_door_wooden_double_1.door:open()
	 else
		dungeon_door_wooden_double_1.door:close()
	end
end
User avatar
fisch
Posts: 8
Joined: Thu May 05, 2016 6:00 pm
Location: Austria

Re: Ask a simple question, get a simple answer

Post by fisch »

Hi,
How I can consider the protection? When I call champion:damage(10, "fire") the fire resists is considered (resist in percent. 20 resist fire = 8 dmg from this 10 fire-damage). So far so good. When I deal damage with physical (or pure) damage types then the full values are used. No Protection reduction.
What's the math behind the stats of Evasion, Accuracy, Protection and Shields? Shields always give +25 protection. Is there a cap at the protection? Like a soft- or hard-cap? And Evasion is the chance in percent?
Is there an article which I cannot find?

Thanks
---
Have forbearance with my bad English :)
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

What was the trick to spawning an object that has a script component, and then assigning its source? [and having it work]

I had thought it was to assign the source in a component [onInit] that appears before the script component itself. I've spent too long trying to spawn a script object and then call its function... always to be told [with errors] that the function doesn't exist [yet?]. :?

** Does one have to create the script component in the onInit hook, or is it okay to have blank one defined, and assign the source to it?

I have a scripted object that works, but [presently] requires a separate script_entity on the map for it to function properly. What I'd like, is for the object to spawn a standard script_entity on its own, and assign the source for it. (I didn't want to have to define a custom object template just to spawn a single script object for the other to work.)
minmay
Posts: 2770
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Isaac: viewtopic.php?f=12&t=13048&p=101349#p101349 and viewtopic.php?f=22&t=7951&p=100794#p100794
fisch wrote:Hi,
How I can consider the protection? When I call champion:damage(10, "fire") the fire resists is considered (resist in percent. 20 resist fire = 8 dmg from this 10 fire-damage). So far so good. When I deal damage with physical (or pure) damage types then the full values are used. No Protection reduction.
What's the math behind the stats of Evasion, Accuracy, Protection and Shields? Shields always give +25 protection. Is there a cap at the protection? Like a soft- or hard-cap? And Evasion is the chance in percent?
Is there an article which I cannot find?

Thanks
Player protection is only applied to melee attacks from monsters. It's not applied to all physical damage, all ranged attacks ignore it for example. I don't know of a way to tell the game to apply protection itself, but you could determine the protection formula by making a monster with a very fast attack and an onDealDamage hook.
Evasion is not a percentage chance, it is compared with the attacker's accuracy. I don't know the exact formula, but you could determine it by experimentation again.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Dunkler
Posts: 73
Joined: Thu Jul 10, 2014 3:20 pm

Re: Ask a simple question, get a simple answer

Post by Dunkler »

Is it possible to give a Monster Attack the ability to cause 2 different negative status effects? Or do i have to create 2 different Attacks?

If yes how do i tell the meleebrain to use this second attack?
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Thanks, that worked. 8-)

But it revealed a different problem, one that turned out to need the custom script definition after all. So I used the above method to define & spawn the script on the map when the first object that needs it gets placed.
Post Reply