Ghost And Sword

Ghost And Sword

Enter in dark dungeons where the monsters rule are thirsty to kill you, collect items and artifacts, learn skills and fight with giant bossies, buy on earn gold new equipment and trade with lost souls.

Find the game on Gamejolt.

Runtime.js All Functions and usage tutorial

Here you will learn how to use runtime.js with comfort and where you can find all functions that you can use in runtime.js.

Posted by on (updated ago)


About

Runtime.js is javascript file that game run everytick after game is begins. For example if you will write in runtime.js such code:

Print("Hello world");

You will see in console endless count of lines with text "Hello world", code will be repeated forever unlike menu.js. If you need to part of code in runtime.js only runs once use such code:

// Once when game starts.
if(IsActionTriggered("GameStart")) 
{     
      Print("Hello world");
}

// Once when game starts and is not load from save.
if(IsActionTriggered("GameStart") && GetTriggerParam("LoadOrNew") == "New") {     
      Print("Hello world");
}

Usage

To start use function of runtime.js, open your mod folder and create file "runtime.js" open it with your text editor. Some of functions require true name of your mod and for comfort we recommend you make variable with true name of your mod. True name of your mod is just name of mod's folder, for example if you create in "mods" folder new folder for your mod with name "MyNewMod" true name of mod will be "MyNewMod", for comfort we recommend you on first line of runtime.js add variable with true name of mod, this will looks like a that:

var mod = "MyNewMod";

Next below we can start codding, and if any function will require true name of mod you just will can type "mod" for that function. Example:

var mod = "MyNewMod";

if (IsActionTriggered("ThrowableItemHit"))
{	
	PlayModSound(mod, "mega_expl.wav", "once", 0, "baaaaam")	
}

This everything that you will need to know to use runtime.js with comfort.

Important note:

If you will need use any images you have to create "Sprites" folder in your mod folder and put all images to there.

Variables

  • GameVersion - Return version of game as string.
  • Fps - Return frames per second as number.
  • MouseX - Return current X of mouse on screen as number.
  • MouseY - Return current Y of mouse on screen as number.
  • InRoom - Return Index of room where player is right now.
  • ShopRoom - Return room index where is shop.
  • SecretRoom - Return room index where is secret room.
  • ExitRoom - Return room index of room with ladder to down or with door to boss room.
  • InBossRoom - Return 1 if player inside room of final boss of location. (long boss room). else 0.
  • BossBeaten - Return 1 when player kill boss, took reward and leave room of final boss of location (long boss room). else 0. This value resets when going to next floor.
  • ThePlayer - Return player object.

ThePlayer Variables

Note: When you change ability values or defaulthealth/defaultstamina you need use "PushReEquip()" function
else changes will be apply only when player open inventory or equip/unequip items.
Example:

ThePlayer.defaulthealth = 10;
ThePlayer.defaultstamina = 10;
PushReEquip();
  • ThePlayer.mindamage - Minimal damage. (actual number with all stats and buffs)
  • ThePlayer.maxdamage - Maximal damage. (actual number with all stats and buffs)
  • ThePlayer.armor - "armor health".
  • ThePlayer.armormax - max "armor health".
  • ThePlayer.health - Current health of player.
  • ThePlayer.healthmax - Current health maximum of player.
  • ThePlayer.stamina - Current stamina of player.
  • ThePlayer.staminamax - Current stamina maximum of player
  • ThePlayer.protecting - 0 - not protecting now, 1 - protect self.
  • ThePlayer.vampirism - How many hp player restore when you attack.
  • ThePlayer.chest - Name of item on body of player.
  • ThePlayer.head - Name of item on head of player.
  • ThePlayer.hands - Name of item in hands of player.
  • ThePlayer.belt - Name of item on waist of player.
  • ThePlayer.shield - Name of item in shield slot of player.
  • ThePlayer.bracelet - Name of item in bracelet slot of player.
  • ThePlayer.trinket - Name of item in trinket slot of player.
  • ThePlayer.gold - Amount of gold have player.
  • ThePlayer.exp - Amount of experience have player
  • ThePlayer.expneed - How many need experience to get new level. This MAX value this means if you have 5 exp and next level in 50, this return 50, not 45.
  • ThePlayer.lv - Level of player. (Not floor, experience level)
  • ThePlayer.strength - Level of strength ability.
  • ThePlayer.critsskill - Level of crits ability.
  • ThePlayer.vitality - Level of vitality ability.
  • ThePlayer.staminaskill - Level of stamina ability.
  • ThePlayer.intellect - Level of intellect ability.
  • ThePlayer.blacksmithing - Level of blacksmithing ability.
  • ThePlayer.survival - Level of survival ability.
  • ThePlayer.alchemy - Level of alchemy ability.
  • ThePlayer.freeskillpoints - How many player have free skills points to spend them on abilitys
  • ThePlayer.crits - Chance of hit with crit.
  • ThePlayer.petname - Name of pet that have player.
  • ThePlayer.defaulthealth - Start health, this need for challenges, by default is 50. If player have two levels of vitality and 50 in defaulthealth he willl have 70 hp.
  • ThePlayer.defaultstamina - Start health, this need for challenges, by default is 90. If player have two levels of stamina ability and 100 in defaultstamina he willl have 110 hp.
  • ThePlayer.healthpenalty - Penalty of health max.
  • ThePlayer.staminapenalty - Penalty of stamina max.

Functions

Note: All functions from menu.js also work in runtime.js.

  • IsActionTriggered(triggername) - Return true if triggered. Name of all triggers read "Action Triggers And Parameters" below.
  • GetTriggerParam(paramname) - Return value of parameter of current trigger. Name of parameters for all triggers read "Action Triggers And Parameters" below.
  • Kill() - Kills player same as ThePlayer.health = 0
  • KillAll() - Kill all monsters in room.
  • Reset() - Reboot game. Can also use it for back to menu.
  • Give(name, count) - Give item to player. If count null give one. Example Give("Bread") give only 1 bread.
  • PutInBelt(name, count) - Give item to player and but in belt, if belt is full item will be given in inventory, this function not show message about getting item, if count null give one.
  • OpenRoom(roomid) - Open room by id.
  • OpenAllRooms() - Open all rooms on map.
  • ForgetRoom(roomid) - Hide room by id.
  • ForgetAllRooms() - Hide all rooms on map.
  • GetPossibleRoom() - Return random room index that is not busy, this means room is have not special(shop or ladder) and in room possible to enter.
  • GetImpossibleRoom() - Return random room index that not contain secret, BLOCKED by walls, and can be entered with only using a pickaxe.
  • MinMax(min, max) - Return random number between min and max value.
  • TryLuck(chance) - Return "Good" or "Fail", chance is how big chance to get "Good".
  • GetRandomItem(type) - Return random item name of type. If type is null return any item. For example GetRandomItem("trinket") return only trinkets.
  • DoTaskInTime(seconds, function) - Run function in seconds that you set.
  • DoPeriodicTask(seconds, function) - Run function in seconds that you set, repeats forever.
  • MakeMessage(modname, text) - Show alert with text. This pause game when alert is showing.
  • HurtPlayer(damage) - Simulate a hit on a player with all calculating
  • DoHealthDelta(value, splash, ignoregolden) - value is number; splash is true/false or null, if null splash shows. This functions almost same "DamagePlayer", but unlike "DamagePlayer" this functions also can add health, automatic ignore armor and not play animation of damage and make splash of stats change. Example: DoHealthDelta(3) will add 3 to health, DoHealthDelta(-3) will subtract 3 from health. IgnoreGolden is true/false or null, if null or false golden health(endurance) will be spent instead of health if player have it, if is true will be spend health even if golden health is more then zero.
  • DoStaminaDelta(value, splash) - value is number; splash is true/false or null, if null splash shows. Example: DoStaminaDelta(3) will add 3 to stamina, DoStaminaDelta(-3) will subtract 3 from stamina.
  • Shake(magnitude, duration, mode) - magnitude and duration can be float, mode can be 0 or 1. 0 is "Reducing magnitude", 1 is "Constant magnitude".
  • NPC_OpenShop() - Close dialog window, and allow you trade with current NPC. Can be called only when player in shop.
  • NPC_GoToDialog(di_name) - Load dialog of currect NPC by name. Can be called only when player in shop.
  • NPC_ChangeTitle(text,translate_tag) - Make NPC say new text, but not change dialog. Can be called only when player in shop.
  • NPC_DoAnim(anim_name,looping) - NPC will do animation, looping is true/false. Can be called only when player in shop.
  • AddEffect(effname, times, power) - Effname is string, time number in turns, power is number. If times is -1, effect will be 1 floor.
  • RemoveEffect(effname) - Remove effects with this name.
  • HasEffect(effname) - Return true if player have effect with such name else return false.
  • AddEffectToMonster(effname, times, power, id) - Effname is string, time number in turns, power is number. If times is -1, effect will be endless, id is monster id, 1 or 2.
  • RemoveEffectFromMonster(effname, id) - Remove effects with this name.
  • MonsterHasEffect(effname, id) - Return true if player have effect with such name else return false.
  • ItemHasTag(name, tag) - Return true if item have tag, return false if have not tag.
  • GetItemTags(name) - Return "none" if have not any tags, return all tags with comma separated, for example GetItemTags("Carrot") will return "Food,Cookable,Vegi".
  • GetXmlData(XmlName, xpath) - Use Xpath to get information. Example GetXmlData("Items","/items/item[@id='Carrot']/health") will return how many heal carrot IN STRING!!! Possible XmlNames: "Items", "Crafts", "Chests", "Lang", "Shop". More about xpath for XML files read on other sites. Example:
    GetXmlData("Items", "/items/item[@id='Carrot']/health") // return 5 becasue Carrot heal 5 health.
  • GetConfigData(mod, option) - Return selected variant of option. See more at config.js.


Debug functions

  • SetRandomShop() - Change current shop on new random one.
  • SetShop(Type) - Change current shop to new one. Type can be "common","magic","blacksmith".
  • FpsPrint() - Toggle periodic printing of fps in console log.
  • Clear() - Clear console log.
  • ClearHis() - Clear console input history.
  • Clear() - Clear console log.
  • ClearHis() - Clear console input history.
  • TestRoomBg(bg,pattern) - Forced set current room bg and object pattern.
  • Tp(roomindex) - Simulate player going in room by index.
  • GodMode() - Health never spends.
  • SuperGodMode() - Stamina and Health never spends.
  • PoolEdit() - Open utility to creating items sheets for chests and shopkeepers.

Action Triggers And Parameters

  • ItemUsed - Params: Name.
  • DescriptionUpated - Params: ItemName.
  • PlayerDidTurn - Params: TurnAct.
  • PlayerDamaged - Params: Damage, ArmorTakeDamage.
  • PlayerDeath - No Params.
  • ThrowableItemHit - Params: Item
  • ThrowableItemMiss - Params: Item
  • MoveingToNewRoom - No Params.
  • NewRoom - No Params.
  • RoomCleanedUp - No Params.
  • GameStart - Params: LoadOrNew
  • EffectStarts - Params: Effect
  • EffectOver - Params: Effect
  • OnKeyPressed - Params: Key
  • OnKeyReleased - Params: Key
  • EnemyNameKilled - No Params. Well, EnemyName is name of any enemy, for exmaple BatKilled will be triggered when bat will be killed.
  • BgElementClicked - Params: Name, Id, X, Y, Type, Frame. Id only if element is dynamic.
  • BgElementLoaded - Params: Name, Id, X, Y, Type, Frame. Id only if element is dynamic.
  • BgElementDestroyed - Params: Name, Id, X, Y, Type, Frame. Id only if element is dynamic.

Example:

if (IsActionTriggered("PlayerDidTurn") && GetTriggerParam("TurnAct") == "Sleep") && HasEffect("StaminaBoost"){
	ThePlayer.stamina = ThePlayer.stamina+10
}

Comments

Join the community or sign in with your gaming account to join the conversation: