diff --git a/docs/modchart.md b/docs/modchart.md index 5bf68a5..4e5b08a 100644 --- a/docs/modchart.md +++ b/docs/modchart.md @@ -145,6 +145,7 @@ Kade Engine provides a list of global variables to be used in the lua scripting | scrollSpeed | Int | The current scrollspeed | | mustHit | Bool | If the current section is a must hit section | | strumLineY | Float | The current Strum Line Y Position | +| health | Float | The current health of the player | ## Functions @@ -465,3 +466,11 @@ Sets the window's position ##### resizeWindow(int width, int height) Resizes the window + + +### Misc + +##### setHealth(float heal) + +Sets the player's health + diff --git a/source/ModchartState.hx b/source/ModchartState.hx index 62fdeb7..4c2ac07 100644 --- a/source/ModchartState.hx +++ b/source/ModchartState.hx @@ -232,7 +232,23 @@ class ModchartState public static var luaSprites:Map = []; + function changeDadCharacter(id:String) + { var olddadx = PlayState.dad.x; + var olddady = PlayState.dad.y; + PlayState.instance.removeObject(PlayState.dad); + PlayState.dad = new Character(olddadx, olddady, id); + PlayState.instance.addObject(PlayState.dad); + PlayState.instance.iconP2.animation.play(id); + } + function changeBoyfriendCharacter(id:String) + { var oldboyfriendx = PlayState.boyfriend.x; + var oldboyfriendy = PlayState.boyfriend.y; + PlayState.instance.removeObject(PlayState.boyfriend); + PlayState.boyfriend = new Boyfriend(oldboyfriendx, oldboyfriendy, id); + PlayState.instance.addObject(PlayState.boyfriend); + PlayState.instance.iconP2.animation.play(id); + } function makeLuaSprite(spritePath:String,toBeCalled:String, drawBehind:Bool) { @@ -312,6 +328,7 @@ class ModchartState // get some fukin globals up in here bois setVar("difficulty", PlayState.storyDifficulty); + setVar("health", PlayState.instance.health); setVar("bpm", Conductor.bpm); setVar("scrollspeed", FlxG.save.data.scrollSpeed != 1 ? FlxG.save.data.scrollSpeed : PlayState.SONG.speed); setVar("fpsCap", FlxG.save.data.fpsCap); @@ -349,6 +366,10 @@ class ModchartState // sprites Lua_helper.add_callback(lua,"makeSprite", makeLuaSprite); + + Lua_helper.add_callback(lua,"changeDadCharacter", changeDadCharacter); + + Lua_helper.add_callback(lua,"changeBoyfriendCharacter", changeBoyfriendCharacter); Lua_helper.add_callback(lua,"getProperty", getPropertyByName); @@ -365,6 +386,10 @@ class ModchartState Lua_helper.add_callback(lua,"setHudAngle", function (x:Float) { PlayState.instance.camHUD.angle = x; }); + + Lua_helper.add_callback(lua,"setHealth", function (heal:Float) { + PlayState.instance.health = heal; + }); Lua_helper.add_callback(lua,"setHudPosition", function (x:Int, y:Int) { PlayState.instance.camHUD.x = x; diff --git a/source/PlayState.hx b/source/PlayState.hx index 8b8f567..3e3040d 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -125,7 +125,7 @@ class PlayState extends MusicBeatState private var curSong:String = ""; private var gfSpeed:Int = 1; - private var health:Float = 1; + public var health:Float = 1; //making public for modchart's sake, but things could go wrong private var combo:Int = 0; public static var misses:Int = 0; private var accuracy:Float = 0.00; @@ -143,8 +143,8 @@ class PlayState extends MusicBeatState private var generatedMusic:Bool = false; private var startingSong:Bool = false; - private var iconP1:HealthIcon; - private var iconP2:HealthIcon; + public var iconP1:HealthIcon; //making these public for modcharts cause i dont know how else to do it + public var iconP2:HealthIcon; //what could go wrong? public var camHUD:FlxCamera; private var camGame:FlxCamera; @@ -1833,6 +1833,7 @@ class PlayState extends MusicBeatState if (health > 2) health = 2; + if (executeModchart && luaModchart != null){luaModchart.setVar('health', health);}; if (healthBar.percent < 20) iconP1.animation.curAnim.curFrame = 1; @@ -2362,6 +2363,7 @@ class PlayState extends MusicBeatState else { health -= 0.075; + if (executeModchart && luaModchart != null){ luaModchart.setVar('health', health);}; vocals.volume = 0; if (theFunne) noteMiss(daNote.noteData, daNote); @@ -2557,6 +2559,7 @@ class PlayState extends MusicBeatState combo = 0; misses++; health -= 0.2; + if (executeModchart && luaModchart != null){ luaModchart.setVar('health', health);}; ss = false; shits++; if (FlxG.save.data.accuracyMod == 0) @@ -2565,6 +2568,7 @@ class PlayState extends MusicBeatState daRating = 'bad'; score = 0; health -= 0.06; + if (executeModchart && luaModchart != null){ luaModchart.setVar('health', health);}; ss = false; bads++; if (FlxG.save.data.accuracyMod == 0) @@ -2576,11 +2580,13 @@ class PlayState extends MusicBeatState goods++; if (health < 2) health += 0.04; + if (executeModchart && luaModchart != null){ luaModchart.setVar('health', health);}; if (FlxG.save.data.accuracyMod == 0) totalNotesHit += 0.75; case 'sick': if (health < 2) health += 0.1; + if (executeModchart && luaModchart != null){ luaModchart.setVar('health', health);}; if (FlxG.save.data.accuracyMod == 0) totalNotesHit += 1; sicks++;