[Solved] Casting custom spells like built in spells

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!
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: How do I cast a custom spell like built in spells are ca

Post by MrChoke »

minmay wrote:
MrChoke wrote:

Code: Select all

onHitMonster = function(self, monster)
				monster:setCondition("poisoned", 25)

				-- mark condition so that exp is awarded if monster is killed by the condition
				local poisonedCondition = monster.go.poisoned
				local ord = self:getCastByChampion()
				if poisonedCondition and ord then
					poisonedCondition:setCausedByChampion(ord)
				end
			end,
The above code will not work like that unless it is cast as a built-in spell. I experimented quite a bit on it.
But you don't need this. You can just change

Code: Select all

poisonedCondition:setCausedByChampion(ord)
to

Code: Select all

poisonedCondition:setCausedByChampion(1)
and get the same effect.
You mean because of the way XP is granted. I suppose but there may be another reason depending on what you want to do. I can't think of anything right now. But its good there is way to get it working just in case.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: [Solved] Casting custom spells like built in spells

Post by AndakRainor »

@MrChoke; To move the starting position of a projectile I use GameObject:setSubtileOffset(dx, dy), knowing your caster you will have no difficulty to find the correct values. I use it to mimic the meteor spell.

@minmay; iirc the xp system of grimrock 1 was insane :) . But I agree, all this is unnecessary with equal xp in grimrock 2. I didn't know the dangers of this variable, so thank you for the warning, I will adapt my code. However the function onProjectileHit still needs to be custom to set an ordinal for the tileDamager spawned. I would be curious to see the build-in spells code, as even if I don't plan to modify the xp system I am not comfortable with arbitrary ordinal, I'd like the code to be universal enough to share it with other modders who may or may not want to use unequal xp. I doubt now, didn't grimrock 1 grant more xp to the performer of the killing action ?
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: [Solved] Casting custom spells like built in spells

Post by MrChoke »

AndakRainor wrote:@MrChoke; To move the starting position of a projectile I use GameObject:setSubtileOffset(dx, dy), knowing your caster you will have no difficulty to find the correct values. I use it to mimic the meteor spell.

@minmay; iirc the xp system of grimrock 1 was insane :) . But I agree, all this is unnecessary with equal xp in grimrock 2. I didn't know the dangers of this variable, so thank you for the warning, I will adapt my code. However the function onProjectileHit still needs to be custom to set an ordinal for the tileDamager spawned. I would be curious to see the build-in spells code, as even if I don't plan to modify the xp system I am not comfortable with arbitrary ordinal, I'd like the code to be universal enough to share it with other modders who may or may not want to use unequal xp. I doubt now, didn't grimrock 1 grant more xp to the performer of the killing action ?
Man, setSubtileOffset(), another new command. Thanks! So dx and dy, these are world coordinate offsets, not map ones?
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: [Solved] Casting custom spells like built in spells

Post by minmay »

Grimrock 1 granted half experience to champions that did not damage a monster.

If you really do want to attach arbitrary data to a projectile for whatever reason, using a ScriptComponent is probably the best way, yeah. Trying to directly add additional fields to a component or GameObject probably won't end well.
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.
Post Reply