engine/scripting/source/MoveScript.cpp
// Return true if the script executed successfully, false otherwise.
Return true if the script executed successfully, false otherwise.
Return true if the script executed successfully false otherwise .
bool MoveScript::execute(ScriptEngine& se, const string& event_script, CreaturePtr moving_creature, const string& map_id, const Coordinate& new_coords)
{
  if (event_script.empty() || moving_creature == nullptr)
  {
    return false;
  }
  bool result = true;
  map<string, string> args = {{"moving_creature_id", moving_creature->get_id()}};
  if (se.execute(event_script, args))
  {
    string moving_creature_id = moving_creature->get_id();
    lua_State* L = se.get_current_state();
    lua_getglobal(L, MOVE_MODULE_NAME.c_str());
    lua_getfield(L, -1, MOVE_FUNCTION_NAME.c_str());
    lua_pushstring(L, moving_creature_id.c_str());
    lua_pushstring(L, map_id.c_str());
    lua_pushinteger(L, new_coords.first);
    lua_pushinteger(L, new_coords.second);
    if (lua_pcall(L, 4, 0, 0) != 0)
    {
      string l_err = lua_tostring(L, -1);
      string error_msg = "MoveScript::execute - error running Lua function `" + MOVE_FUNCTION_NAME + "': " + l_err;
      Log::instance().error(error_msg);
      lua_pop(L, 1);
      result = false;
    }
  }
  else
  {
    Log::instance().error("MoveScript::execute - did not run Lua function due to script failure: " + event_script);
    result = false;
  }
  return result;
}
bool MoveScript :: execute ( ScriptEngine & se , const string & event_script , CreaturePtr moving_creature , const string & map_id , const Coordinate & new_coords ) { if ( event_script . empty ( ) || moving_creature == nullptr ) { return false ; } bool result = true ; map < string , string > args = { { " " , moving_creature -> get_id ( ) } } ; if ( se . execute ( event_script , args ) ) { string moving_creature_id = moving_creature -> get_id ( ) ; lua_State * L = se . get_current_state ( ) ; lua_getglobal ( L , MOVE_MODULE_NAME . c_str ( ) ) ; lua_getfield ( L , -1 , MOVE_FUNCTION_NAME . c_str ( ) ) ; lua_pushstring ( L , moving_creature_id . c_str ( ) ) ; lua_pushstring ( L , map_id . c_str ( ) ) ; lua_pushinteger ( L , new_coords . first ) ; lua_pushinteger ( L , new_coords . second ) ; if ( lua_pcall ( L , 4 , 0 , 0 ) != 0 ) { string l_err = lua_tostring ( L , -1 ) ; string error_msg = " " + MOVE_FUNCTION_NAME + " " + l_err ; Log :: instance ( ) . error ( error_msg ) ; lua_pop ( L , 1 ) ; result = false ; } } else { Log :: instance ( ) . error ( " " + event_script ) ; result = false ; } return result ; }
Return true if the script executed successfully, false otherwise.
Return true if the script executed successfully false otherwise .
// Set up the function call parameters. // Do the function call.  The "move" function returns nothing.