Having some trouble with shootProjectile

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

Having some trouble with shootProjectile

Post by MrChoke »

I keep getting an "invalid arch" error when it executes this:

shootProjectile("fireball_large", self.go.level, self.go.x, self.go.y+3, 0, 10, 0, 0, 0, 0, 0, 3, nil, false)

I know the level, x and y values is an open square (its 3 squares behind the button that is "self")

Maybe it has something to do with the offset values? I set zeros because I am not sure what to set. The reference says it is this:
offsetX,offsetY,offsetZ: 3D offset in world space from the center of cell.

If it relative you would think zeros would work. Has anyone used this command yet?
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

"shootProjectile" does not work

Post by MrChoke »

After far too much trial and error trying to get this command to work, I declare this command BROKEN. Nothing works. Period. Didn't Grimrock 1 have a command like this? Maybe I will see if I can find some examples from 1. Not that it matters.
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Having some trouble with shootProjectile

Post by minmay »

shootProjectile(projectile, level, x, y, direction, speed, gravity, velocityUp, offsetX, offsetY, offsetZ, attackPower, ignoreEntity, fragile, championOrdinal)
Shoots a projectile item. The parameters are:

projectile: the name of the item to shoot.
level,x,y: the initial position of the projectile in a level.
direction: the shooting direction (0=north, 1=east, 2=south, 3=west).
speed: the speed of the projectile (metres/second). Typical values around 10.
gravity: the gravity force in y-direction. Typical values around 0.
velocityUp: the initial velocity in y-direction. Typically set to 0.
offsetX,offsetY,offsetZ: 3D offset in world space from the center of cell.
attackPower: attack power of the projectile.
ignoreEntity: the entity to be ignored for collisions (or nil if the entity should not ignore any collisions).
fragile: a boolean flag, if set the projectile is destroyed on impact.
championOrdinal: a champion ordinal number, used for dealing experience points. This parameter is optional.
Notice how it asks for the name of an item. Fireballs are not items.
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.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Having some trouble with shootProjectile

Post by MrChoke »

minmay wrote:
shootProjectile(projectile, level, x, y, direction, speed, gravity, velocityUp, offsetX, offsetY, offsetZ, attackPower, ignoreEntity, fragile, championOrdinal)
Shoots a projectile item. The parameters are:

projectile: the name of the item to shoot.
level,x,y: the initial position of the projectile in a level.
direction: the shooting direction (0=north, 1=east, 2=south, 3=west).
speed: the speed of the projectile (metres/second). Typical values around 10.
gravity: the gravity force in y-direction. Typical values around 0.
velocityUp: the initial velocity in y-direction. Typically set to 0.
offsetX,offsetY,offsetZ: 3D offset in world space from the center of cell.
attackPower: attack power of the projectile.
ignoreEntity: the entity to be ignored for collisions (or nil if the entity should not ignore any collisions).
fragile: a boolean flag, if set the projectile is destroyed on impact.
championOrdinal: a champion ordinal number, used for dealing experience points. This parameter is optional.
Notice how it asks for the name of an item. Fireballs are not items.
If I put an invalid item name in there it tells me so saying "Invalid Type". I need an example of it working. I just hunted down 5 examples from Grimrock 1 too since the command parameters didn't change and none of them work either.
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Having some trouble with shootProjectile

Post by Prozail »

My guess is it's a leftover from LoG1 that is not used anymore since the new component system, and should simply be removed from the scripting reference.

You can do the same thing, albeit a bit more verbose, like this. Just check the reference for ProjectileComponent

Code: Select all

local s = spawn("poison_bolt",sender.go.level,sender.go.x,sender.go.y,sender.go.facing,0)
	s.projectile:setIgnoreEntity(party)
	s.projectile:setAttackPower(10)
	print(s:getWorldPosition())
	s:setWorldPosition(13.5,1.35,28,5,0) -- just toying around with values here... 
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Having some trouble with shootProjectile

Post by MrChoke »

Prozail wrote:My guess is it's a leftover from LoG1 that is not used anymore since the new component system, and should simply be removed from the scripting reference.

You can do the same thing, albeit a bit more verbose, like this. Just check the reference for ProjectileComponent

Code: Select all

local s = spawn("poison_bolt",sender.go.level,sender.go.x,sender.go.y,sender.go.facing,0)
	s.projectile:setIgnoreEntity(party)
	s.projectile:setAttackPower(10)
	print(s:getWorldPosition())
	s:setWorldPosition(13.5,1.35,28,5,0) -- just toying around with values here... 
Thanks Prozail! That works great. I gotta start looking at the components closer. Thing is though, if shootProjectile is not valid in LoG2 it really needs to be removed from the scripting reference. It will only cause confusion.
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Re: Having some trouble with shootProjectile

Post by Aisuu »

I was messing with projectile component too. It work all right with spells. But I cant get it work with arrow.
Arrow trap is common in most dungeons so I guess it would by great idea to implement it.
It was easy with shootProjectile in LOG1, but in LOG2 Iam lost :(
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Having some trouble with shootProjectile

Post by Prozail »

Yup.. came to the same conclusion.. fireing actual items is... strange.

This is as far as i've gotten, so if anyone knows what's missing please say!

Code: Select all


defineObject{
	name ="projectile_arrow",
	baseObject = "arrow",
	components = {
		{
			class = "Item",
			weight = 0.1,
			projectileRotationY = 90,
			sharpProjectile = true,
		},
		{
			class = "Projectile",
			spawnOffsetY = 1.0,
			velocity = 15,
			fallingVelocity = 1,
			angularVelocity = 0,
			gravity = 1,
			radius = 0.5,
			hitEffect = "hit_blood_small",
			attackPower = 10,
			castByChampion = true,	
			onProjectileHit = function(self, what, entity)
				print("onHit",self,what,entity)
			end
		}
	},
}
Image
..It is flying!... just.. sideways....
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Having some trouble with shootProjectile

Post by akroma222 »

Have you guys tried adding a RangedAttack component to the item def??

EDIT - Dont do that^^ that was a very bad idea
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Having some trouble with shootProjectile

Post by AndakRainor »

Prozail wrote:My guess is it's a leftover from LoG1 that is not used anymore since the new component system, and should simply be removed from the scripting reference.

You can do the same thing, albeit a bit more verbose, like this. Just check the reference for ProjectileComponent

Code: Select all

local s = spawn("poison_bolt",sender.go.level,sender.go.x,sender.go.y,sender.go.facing,0)
	s.projectile:setIgnoreEntity(party)
	s.projectile:setAttackPower(10)
	print(s:getWorldPosition())
	s:setWorldPosition(13.5,1.35,28,5,0) -- just toying around with values here... 
Well shootProjectile is documented in the global functions examples of the official scripting reference of Grimrock 2. It would be odd if it was there but deprecated.
I tried to build a simple spell that throws a rock, and also tried examples from Grimrock 1 mods, but so far nothing works...
I managed to launch several magic projectiles with your spawn code, fireballs, lightning bolts, poison bolts, ice bolts, etc... But all the projectile items such as "rock" are not considered projectile in Grimrock 2 !!! So s.projectile is an invalid reference if you replace "poison_bolt" by "rock" in your example. What am I missing ?

Also one of my goals would be to build spells similar to meteor storm for the other magic schools, such as the multiple poison bolts that monsters use in the last dungeon.
Do you know how to delay and move the start positions of multiple projectiles to recreate the meteor spell ?
Post Reply