Need help, script to run on monster's death.
-
zadkielmodeler
- Posts: 43
- Joined: Sat Sep 15, 2012 6:34 am
Need help, script to run on monster's death.
I am at the point where I want to run a script that activates when a person defeats a monster. Basically to congratulate that person on beating the game.
I know how to make the script play a sound, but not as triggered by the death of a monster. I am curious what the setup would be code-wise.
I know how to make the script play a sound, but not as triggered by the death of a monster. I am curious what the setup would be code-wise.
Re: Need help, script to run on monster's death.
You should use a onDie hook in the monster definition asset.
Just clone a monster in monster.lua and add that function.
for example:
cloneObject{
name = "snail_boss",
baseObject = "snail",
onDie = function (self)
script_monster:script_death()
return true
end
}
in the editor you will place a script entity and call it script_monster, inside of it you will place the function script_death()
when the monster dies, the function wil be called.
Just clone a monster in monster.lua and add that function.
for example:
cloneObject{
name = "snail_boss",
baseObject = "snail",
onDie = function (self)
script_monster:script_death()
return true
end
}
in the editor you will place a script entity and call it script_monster, inside of it you will place the function script_death()
when the monster dies, the function wil be called.
-
zadkielmodeler
- Posts: 43
- Joined: Sat Sep 15, 2012 6:34 am
Re: Need help, script to run on monster's death.
I see so half the code goes into the monster itself and the other half is called by the monster onDeath. Thanks.
-
zadkielmodeler
- Posts: 43
- Joined: Sat Sep 15, 2012 6:34 am
Re: Need help, script to run on monster's death.
Can I just call a lua function that is defined in the editor from monsters.lua or does the whole thing have to be done in monsters.lua?
Also, what is the purpose of return true in the code?
Also, what is the purpose of return true in the code?
-
zadkielmodeler
- Posts: 43
- Joined: Sat Sep 15, 2012 6:34 am
Re: Need help, script to run on monster's death.
yeah putting this
in the monster I have cloned does not work. =(
Code: Select all
onDie:( function beatgame()
playSound("discover_spell")
showText("Congratulations. You have truly beaten this game. I hope you enjoyed it =) ")
end),
-
zadkielmodeler
- Posts: 43
- Joined: Sat Sep 15, 2012 6:34 am
Re: Need help, script to run on monster's death.
I see this asset Definition reference would have been so very useful, so much sooner. Thank you so much. =)
-
zadkielmodeler
- Posts: 43
- Joined: Sat Sep 15, 2012 6:34 am
Re: Need help, script to run on monster's death.
Okay the editor likes it all. but when it gets time to call the script, the game crashes. Here is the error log.
This is the code I have in my monsters.lua for the monster.
And this is the code I have in my lua script in the editor. It is in an entity called beatgame_script
Please tell me what I messed up on.
Code: Select all
#beatgame_script:5: attempt to call global 'showText' (a nil value)
stack traceback:
#beatgame_script:5: in function 'beatgame'
mod_assets/scripts/monsters.lua:115: in function 'onDie'
[string "Monster.lua"]: in function 'die'
[string "Monster.lua"]: in function 'damage'
[string "Combat.lua"]: in function 'damageTile'
[string "ProjectileSpell.lua"]: in function 'onProjectileHit'
[string "Projectile.lua"]: in function 'update'
[string "ProjectileSpell.lua"]: in function 'update'
[string "Map.lua"]: in function 'updateEntities'
[string "Dungeon.lua"]: in function 'updateLevels'
[string "GameMode.lua"]: in function 'update'
[string "Grimrock.lua"]: in function 'display'
[string "Grimrock.lua"]: in main chunk
OS Version 6.1
OEM ID: 0
Number of processors: 2
Page size: 4096
Processor type: 586
Total memory: 6142 MB
Free memory: 1616 MB
Display device 0:
Device name: \\.\DISPLAY1
Device string: NVIDIA GeForce GT 545
State flags: 00000005
Display device 1:
Device name: \\.\DISPLAY2
Device string: NVIDIA GeForce GT 545
State flags: 08000000
Display device 2:
Device name: \\.\DISPLAYV1
Device string: RDPDD Chained DD
State flags: 00200008
Display device 3:
Device name: \\.\DISPLAYV2
Device string: RDP Encoder Mirror Driver
State flags: 00200008
Display device 4:
Device name: \\.\DISPLAYV3
Device string: RDP Reflector Display Driver
State flags: 00200008
Code: Select all
defineObject{
name = "HighCouncelor",
class = "Monster",
model = "assets/models/monsters/goromorg.fbx",
meshName = "goromorg_mesh",
animations = {
idle = "assets/animations/monsters/goromorg/goromorg_idle.fbx",
moveForward = "assets/animations/monsters/goromorg/goromorg_walk.fbx",
strafeLeft = "assets/animations/monsters/goromorg/goromorg_strafe_left.fbx",
strafeRight = "assets/animations/monsters/goromorg/goromorg_strafe_right.fbx",
turnLeft = "assets/animations/monsters/goromorg/goromorg_turn_left.fbx",
turnRight = "assets/animations/monsters/goromorg/goromorg_turn_right.fbx",
attack = "assets/animations/monsters/goromorg/goromorg_attack.fbx",
getHitFrontLeft = "assets/animations/monsters/goromorg/goromorg_get_hit_front_left.fbx",
getHitFrontRight = "assets/animations/monsters/goromorg/goromorg_get_hit_front_right.fbx",
getHitBack = "assets/animations/monsters/goromorg/goromorg_get_hit_back.fbx",
getHitLeft = "assets/animations/monsters/goromorg/goromorg_get_hit_left.fbx",
getHitRight = "assets/animations/monsters/goromorg/goromorg_get_hit_right.fbx",
fall = "assets/animations/monsters/goromorg/goromorg_get_hit.fbx",
},
--attackAnimSpeed = 1.7,
moveAnimSpeed = .9,
turnAnimSpeed = 2.5,
movementCoolDown = .3,
moveSound = "goromorg_walk",
footstepSound = "goromorg_footstep",
attackSound = "goromorg_attack",
hitSound = "goromorg_hit",
dieSound = "goromorg_die",
hitEffect = "hit_dust",
capsuleHeight = 0.8,
capsuleRadius = 0.25,
collisionRadius = 0.8,
health = 2200, -- goromorg shield is on top of this
sight = 4,
seeInvisible = true,
allAroundSight = true,
attackPower = 50,
protection = 2,
rangedAttack = { 45, "lightning_bolt_greater", 25, "ice_shards", 20, "fireball_greater", 10, "poison_bolt" },
coolDown = { 3, 4 },
movementCoolDown = .9,
exp = 10000,
onDie = function (self)
beatgame_script:beatgame()
return true
end,
particleSystem = "goromorg_lantern",
particleSystemNode = "light1",
lightName = "light1",
lightColor = vec(7.5, 1.0, 2.5),
lightBrightness = 4,
lightRange = 4.5,
healthIncrement = 90,
brain = "Goromorg",
}
Code: Select all
function beatgame()
playSound("discover_spell")
showText("Congratulations. You have truly beaten this game. I hope you enjoyed it =) ")
end
Re: Need help, script to run on monster's death.
it's not showText, but
hudPrint("Congratulations. You have truly beaten this game. I hope you enjoyed it =) ")
hudPrint("Congratulations. You have truly beaten this game. I hope you enjoyed it =) ")
-
zadkielmodeler
- Posts: 43
- Joined: Sat Sep 15, 2012 6:34 am
Re: Need help, script to run on monster's death.
Thank you so much Crisman. It works. Thank you so much. It works =)
Re: Need help, script to run on monster's death.
No problem! Glad I could help 