FreeBASIC snippets

From OHRRPGCE-Wiki
Jump to navigation Jump to search

This page is like the Script dump but for FreeBASIC code instead of HamsterSpeak. Because it isn't possible to mod Custom with scripts, sometimes temporarily modding the engine with a few lines of FB can save hours of time for some editing task.


Copy data from enemies to heroes[edit]

This function creates a new hero definition for each enemy definition, and copies over name and elemental resists. You could easily copy over stats and more too.

SUB enemy_elementals_to_heroes()
 FOR enemynum as integer = 0 TO gen(genMaxEnemy)
  DIM enemy as EnemyDef
  loadenemydata enemy, enemynum
  DIM her as HeroDef

  her.name = enemy.name
  FOR i as integer = 0 TO maxElements - 1
   her.elementals(i) = enemy.elementals(i)
  NEXT

  gen(genMaxHero) += 1
  saveherodata her, gen(genMaxHero)
 NEXT
 xbsave game + ".gen", gen(), 1000
END SUB