A script that work for one player but not for another one...

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!
User avatar
Khollik
Posts: 171
Joined: Tue Aug 29, 2017 6:44 pm
Location: France

A script that work for one player but not for another one...

Post by Khollik »

Hello everyone

I'm struggling hard with a couple of bugs in my first mod (Lost Power of Nadric) and I would really appreciate help from more experienced moders.

The thing is that I have a couple of scripts that do work well with me, either in the editor or in exported version BUT sometimes, it seems not to work for other players. I can't figure out how it is possible :?:

For example, I have a floortrigger that activates a script which casts a darkness spell by using the champions energy. Here is the code of the script (quite basic actually):

Code: Select all

function darknesscast()
       for i = 1, 4 do
          party.party:getChampion(i):regainEnergy(35)
          party.party:getChampion(i):castSpell(58)
       end
end
I don't mind if the spell fizzles because no one can't cast a light/dark spell. The point is to put the party into darkness (and obviously there won't be any light spell if there is no spellcaster). Actually, I tried with a fresh new party and no spellcaster: the spell isn't cast but at least the game does not crash. Unfortunately, there is a game crash for another player, Orace.

Image

Script_entity_31 is the one with the darknesscast code.

Any advice here???

Khollik
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: A script that work for one player but not for another on

Post by Zo Kath Ra »

(it's ptobably not this; if it were, the error message would be different)
SpoilerShow
He's probably playing an old version of LoG2.
viewtopic.php?f=23&t=9031&p=109873&hili ... ll#p109873
Or there are less than 4 champions in his party.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: A script that work for one player but not for another on

Post by zimberzimber »

Did they import the party from another mod?
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: A script that work for one player but not for another on

Post by Isaac »

Try using one of these instead of casting the darkness spell:

Pitch black: (Blunt, but stable. Probably too harsh to actually use.)

Code: Select all

function darknessToggle()  
	if party.torch:isEnabled() then
		party.torch:disable()
	 else party.torch:enable()	
	end
end
Dimmed to near black: (Experimental; if there is a simpler/better way, I'd really love to learn it.)

Code: Select all

function dimnessToggle() --effect controller
	if party.dimmerSwitch then
		if party.dimmerSwitch:isEnabled() then
			party.dimmerSwitch:disable()
		 else party.dimmerSwitch:enable()	
		end
	 else
	 	party:createComponent('Timer', 'dimmerSwitch')
		party.dimmerSwitch:setTimerInterval(.005) --tweak lower if needed; (you will know if you need it).
		party.dimmerSwitch:addConnector('onActivate', self.go.id, 'dim')
	end
end

function dim() --dimness effect
		party.torch:setBrightness(.2) -- lower equals darker
		party.torch:setColor(vec(.05, .06, .012))
end
User avatar
Khollik
Posts: 171
Joined: Tue Aug 29, 2017 6:44 pm
Location: France

Re: A script that work for one player but not for another on

Post by Khollik »

Thanks for your help.
Seemingly he plays with the same version as mine. I asked him if it was an imported party (to be sure). But I also have another player stumbling into a similar script (with a CastSpell) in another part of the mod, with the same problem.

Isaac, I also have a script which checks if the champions have a torch in hand and burn it out. This one seems to work fine, actually, but I'll try yours, though I'm not sure how the second one works ;)

Khollik
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: A script that work for one player but not for another on

Post by Zo Kath Ra »

Khollik wrote:Thanks for your help.
But I also have another player stumbling into a similar script (with a CastSpell) in another part of the mod, with the same problem.
Did he provide a savegame?
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: A script that work for one player but not for another on

Post by Isaac »

Khollik wrote:Isaac, I also have a script which checks if the champions have a torch in hand and burn it out. This one seems to work fine, actually, but I'll try yours, though I'm not sure how the second one works ;)

Khollik
Both were written with the idea that you would activate them with a floor trigger, as in your topic post. On my test map, when the party steps on a plate, the light's go out.

The function dimnessToggle() is called to make it dark, and called again to make it bright; suitable for buttons & floor_triggers... or any scripts.
A floor_trigger set to Activate or Deactivate would begin or end the effect, and if set to Toggle, would make it dark (or light) only while the plate is depressed. Levers, (even buttons) can be attached to make light switches; but these would be world-affecting. It was not originally intended for room-by-room lighting control; more like the anti-magic zones in Bard's Tale; temporarily enforced underground darkness. It doesn't work in outdoor areas.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: A script that work for one player but not for another on

Post by minmay »

This error occurs when the player imports a party with a trait that doesn't exist in the mod and a champion casts a spell. This is due to how learning new spells is handled internally. There is nothing you can do to fix it.
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.
User avatar
Khollik
Posts: 171
Joined: Tue Aug 29, 2017 6:44 pm
Location: France

Re: A script that work for one player but not for another on

Post by Khollik »

Hello guys

Thanks for the answers!

@Isaac: the first code is quite radical but works fine. I shall use it to prevent the castspell function which seems to cause to bug. Thanks again.

@Minmay and AndakRainor: I'm waiting for his response but if it is the case, then it is settled (and I learned something here)... :?

As for me, I prefer beginning with a new party when I play a new mod, particularly because a strong party can overkill the pleasure to struggle for the first experience levels. Maybe I should warn in the description of the mod about playing with an imported party.

Cheers
Khollik
Post Reply