Page 1 of 2
how to spawn particle effect?
Posted: Mon Feb 16, 2015 2:48 pm
by bongobeat
here I am with another silly question
how can be a particle (like blob) spawned after shooting with a gun (defined like a firearms)?
while defining a sci fi gun I use that spawning command: (it's log1 script)
Code: Select all
onAttack = function(self)
spawn("ion_object", self.level, self.x, self.y)
end,
but it spawn the object in front of the party, which is going directly in the party while it should go in the other way
Code: Select all
-- ion gun
defineObject{
name = "ion_gun",
baseObject = "base_item",
components = {
{
class = "Model",
model = "mod_assets/sci_fi_gun/ion_gun.fbx",
},
{
class = "Item",
uiName = "Ion Canon",
description = "A powerful weapon made with old technology, it fires high energetic particles.",
gfxAtlas = "mod_assets/sci_fi_gun/oliveitem.tga",
gfxIndex = 30,
-- gfxIndexPowerAttack = 432,
impactSound = "impact_blade",
weight = 3.0,
secondaryAction = "ions_rapid",
},
{
class = "FirearmAttack",
attackPower = 500,
cooldown = 0.4,
attackSound = "laser01",
ammo = "power",
jamChance = 0,
backfireChance = 0,
requirements = { "firearms", 5 },
onAttack = function(self)
spawn("ion_object", self.level, self.x, self.y)
end,
},
{
class = "FirearmAttack",
name = "ions_rapid",
uiName = "Rapid Fire",
gameEffect = "Quickly Fires 5 Ions Shots.",
energyCost = 50,
attackPower = 500,
cooldown = 3,
attackSound = "laser01",
ammo = "power",
repeatCount = 5,
repeatDelay = 0.10,
jamChance = 0,
backfireChance = 0,
requirements = { "firearms", 5 },
},
},
tags = { "weapon" },
}
the ion_object:
Code: Select all
defineObject{
name = "ion_object",
baseObject = "base_spell",
components = {
{
class = "Particle",
particleSystem = "ions",
},
{
class = "Light",
color = vec(1.0, 1.0, 0.0),
brightness = 100,
range = 10,
fadeOut = 0.5,
disableSelf = true,
},
{
class = "Projectile",
spawnOffsetY = 1.35,
velocity = 20,
radius = 0.1,
hitEffect = "ions_blast",
},
{
class = "Sound",
sound = "laser01",
},
{
class = "Sound",
name = "launchSound",
sound = "laser01",
},
},
}
another question:
Is it possible to increase the range of any firearm to 15 or more square?
while testing, without any firearms level required, It shoot only on 3 squares max in front of the party.
I had to set the requirements = { "firearms", 5 }, so the range is naturally increased, but is there any way to do this without defining it like so?
finaly:
how can be the particle firearm_hit changed by another particle?
Re: how to spawn particle effect?
Posted: Mon Feb 16, 2015 5:52 pm
by Drakkan
I saw similar topic about spawning spells here, maybe it helps you a little
viewtopic.php?f=22&t=9416&hilit=spawn+fireball&start=10
Re: how to spawn particle effect?
Posted: Mon Feb 16, 2015 8:38 pm
by minmay
bongobeat wrote:how can be a particle (like blob) spawned after shooting with a gun (defined like a firearms)?
while defining a sci fi gun I use that spawning command: (it's log1 script)
The "self" parameter in onAttack is the component. Components do not have level, x, or y fields. So your onAttack hook is passing nil values, which is the same as simply calling
which will spawn the item one square in front of the party and facing the party.
Here is the code you should use:
Code: Select all
onAttack = function(self, champion, slot, chainIndex)
local ion = spawn("ion_object",party.level,party.x,party.y,party.facing,party.elevation)
ion.projectile:setIgnoreEntity(party)
-- Set cast by champion so that experience is awarded for kills.
local ord = champion:getOrdinal()
ion.projectile:setCastByChampion(true)
-- When the 2.1.19 patch is released, uncomment the next line and delete the previous line.
-- ion.projectile:setCastByChampion(ord)
-- Simulate the position of a player-cast spell.
local left = nil
for i = 1,4 do
if party.party:getChampion(i):getOrdinal() == ord then
left = i == 1 or i == 3
break
end
end
local wpos = party:getWorldPosition()
local dx = nil
local dz = nil
if party.facing == 0 then
dx = left and -0.1 or 0.1
dz = -1
elseif party.facing == 1 then
dz = left and 0.1 or -0.1
dx = -1
elseif party.facing == 2 then
dx = left and 0.1 or -0.1
dz = 1
else -- party.facing == 3
dz = left and -0.1 or 0.1
dx = 1
end
ion:setWorldPosition(vec(wpos[1]+dx,wpos[2]+1.35,wpos[3]+dz))
end,
bongobeat wrote:another question:
Is it possible to increase the range of any firearm to 15 or more square?
while testing, without any firearms level required, It shoot only on 3 squares max in front of the party.
I had to set the requirements = { "firearms", 5 }, so the range is naturally increased, but is there any way to do this without defining it like so?
"range" field in the FirearmAttackComponent definition.
Re: how to spawn particle effect?
Posted: Tue Feb 17, 2015 12:02 am
by bongobeat
@Drakkan:
sorry I did not find this topic, I got another one with custom spell, but you need to use a script in the editor. I already use that for a custom spell, but I got an error while using it with the ion object.
@minmay:
this is perfect! Great! thanks!
just tested it:
the ion object is spawned even if there is no ammo in the hand. any help?
Re: how to spawn particle effect?
Posted: Tue Feb 17, 2015 2:08 am
by Eburt
Take a look at
this thread. About 3/4 of the way down the OP is a topic on having two specific weapons equipped together. Use that to check if both the weapon and your ammo are both in the hands. The FirearmAttackComponent should take care of decrementing the ammo on use.
Re: how to spawn particle effect?
Posted: Wed Feb 18, 2015 2:07 pm
by bongobeat
thanks,
akroma use this:
Code: Select all
function comboSwordCheckEquip(self, champion, slot)
local sword1 = champion:getItem(1)
local sword2 = champion:getItem(2)
if sword1 and sword2 then
if sword1.go.name == "long_sword" and sword2.go.name == "rapier"
or sword2.go.name == "long_sword" and sword1.go.name == "rapier" then
hudPrint("this works")
end
end
end
function comboSwordCheckUnequip(self, champion, slot)
local sword1 = champion:getItem(1)
local sword2 = champion:getItem(2)
if sword1 and sword2 then
if sword1.go.name == "long_sword" and sword2.go.name == "rapier"
or sword2.go.name == "long_sword" and sword1.go.name == "rapier" then
hudPrint("this works")
end
end
end
How can it be integrated in the ion script?
I can't load the editor with this one: (modified akroma script is added between the quadruple quote)
Code: Select all
{
class = "FirearmAttack",
attackPower = 500,
cooldown = 0.4,
attackSound = "laser01",
ammo = "power",
jamChance = 0,
backfireChance = 0,
range = 15,
onAttack = function(self, champion, slot, chainIndex)
----
local ammo1 = champion:getItem(1)
local ammo2 = champion:getItem(2)
if ammo1.go.name == "ion_gun" and ammo2.go.name == "power_recharge"
or ammo2.go.name == "ion_gun" and ammo1.go.name == "power_recharge" then
----
local ion = spawn("ion_object",party.level,party.x,party.y,party.facing,party.elevation)
ion.projectile:setIgnoreEntity(party)
-- Set cast by champion so that experience is awarded for kills.
local ord = champion:getOrdinal()
ion.projectile:setCastByChampion(true)
-- When the 2.1.19 patch is released, uncomment the next line and delete the previous line.
-- ion.projectile:setCastByChampion(ord)
-- Simulate the position of a player-cast spell.
local left = nil
for i = 1,4 do
if party.party:getChampion(i):getOrdinal() == ord then
left = i == 1 or i == 3
break
end
end
local wpos = party:getWorldPosition()
local dx = nil
local dz = nil
if party.facing == 0 then
dx = left and -0.1 or 0.1
dz = -1
elseif party.facing == 1 then
dz = left and 0.1 or -0.1
dx = -1
elseif party.facing == 2 then
dx = left and 0.1 or -0.1
dz = 1
else -- party.facing == 3
dz = left and -0.1 or 0.1
dx = 1
end
ion:setWorldPosition(vec(wpos[1]+dx,wpos[2]+1.35,wpos[3]+dz))
end,
----
end,
end,
end
----
},
Re: how to spawn particle effect?
Posted: Thu Feb 19, 2015 3:40 am
by Eburt
At a glance, it looks like that should work. It's hard to tell because the code isn't formatted very clearly, but if I had to guess I would say you have too many or not enough "end" statements. I would strongly recommend indenting everything cleanly so that you can tell where functions open/close.
Edit: take a look at this, after formatting, it is very obvious where the extra "end"s are:
Code: Select all
{
class = "FirearmAttack",
attackPower = 500,
cooldown = 0.4,
attackSound = "laser01",
ammo = "power",
jamChance = 0,
backfireChance = 0,
range = 15,
onAttack = function(self, champion, slot, chainIndex)
----
local ammo1 = champion:getItem(1)
local ammo2 = champion:getItem(2)
if ammo1.go.name == "ion_gun" and ammo2.go.name == "power_recharge"
or ammo2.go.name == "ion_gun" and ammo1.go.name == "power_recharge" then
----
local ion = spawn("ion_object",party.level,party.x,party.y,party.facing,party.elevation)
ion.projectile:setIgnoreEntity(party)
-- Set cast by champion so that experience is awarded for kills.
local ord = champion:getOrdinal()
ion.projectile:setCastByChampion(true)
-- When the 2.1.19 patch is released, uncomment the next line and delete the previous line.
-- ion.projectile:setCastByChampion(ord)
-- Simulate the position of a player-cast spell.
local left = nil
for i = 1,4 do
if party.party:getChampion(i):getOrdinal() == ord then
left = i == 1 or i == 3
break
end
end
local wpos = party:getWorldPosition()
local dx = nil
local dz = nil
if party.facing == 0 then
dx = left and -0.1 or 0.1
dz = -1
elseif party.facing == 1 then
dz = left and 0.1 or -0.1
dx = -1
elseif party.facing == 2 then
dx = left and 0.1 or -0.1
dz = 1
else -- party.facing == 3
dz = left and -0.1 or 0.1
dx = 1
end
ion:setWorldPosition(vec(wpos[1]+dx,wpos[2]+1.35,wpos[3]+dz))
end, <---EXTRA END
----
end, <---EXTRA END
end,
end
----
},
On a side note, the above code will crash the game if the champion is not holding an item in both hands because ammo1 or ammo2 will be nil and nil doesn't have a .go component. You should wrap that whole block in:
if ammo1 and ammo 2 then
...
end
Re: how to spawn particle effect?
Posted: Thu Feb 19, 2015 11:33 am
by bongobeat
humm this don't work without the 2 extra ends, I got "item.lua:73: unexpected symbol near ','

Re: how to spawn particle effect?
Posted: Fri Feb 20, 2015 3:42 am
by Eburt
bongobeat wrote:humm this don't work without the 2 extra ends, I got "item.lua:73: unexpected symbol near ','

Probably because the last end that is there doesn't have a comma after it. If there's anything following the onAttack hook and no comma after the end closing it you will get that error. However, you can check by finding line 73 - thats what the error message is telling you (sometimes it will be on the next line with code after the number in the error as well).
Re: how to spawn particle effect?
Posted: Fri Feb 20, 2015 3:56 am
by minmay
Fields in tables are separated by commas. You have several commas in the middle of your function code, which doesn't make any sense, and no comma after the onAttack field assignment. You might find the
Lua Reference Manual useful; it specifies the syntax of the language so that you will not have this problem again.