func DoInteractWithObjectFunc(a *Ai) lua.GoFunction { return func(L *lua.State) int { if !game.LuaCheckParamsOk(L, "DoInteractWithObject", game.LuaEntity) { return 0 } object := game.LuaToEntity(L, a.ent.Game(), -1) var interact *actions.Interact for _, action := range a.ent.Actions { var ok bool interact, ok = action.(*actions.Interact) if ok { break } } if interact == nil { game.LuaDoError(L, "Tried to interact with an object, but don't have an interact action.") L.PushNil() return 1 } exec := interact.AiInteractWithObject(a.ent, object) if exec != nil { a.execs <- exec <-a.pause L.PushBoolean(true) } else { L.PushNil() } return 1 } }
// Performs an Interact action to toggle the opened/closed state of a door. // Format // res = doDoorToggle(d) // // Input: // d - door - A door. // // Output: // res - boolean - True if the door was opened, false if it was closed. // res will be nil if the action could not be performed for some reason. func DoDoorToggleFunc(a *Ai) lua.GoFunction { return func(L *lua.State) int { if !game.LuaCheckParamsOk(L, "doDoorToggle", game.LuaDoor) { return 0 } door := game.LuaToDoor(L, a.ent.Game(), -1) if door == nil { game.LuaDoError(L, "DoDoorToggle: Specified an invalid door.") return 0 } var interact *actions.Interact for _, action := range a.ent.Actions { var ok bool interact, ok = action.(*actions.Interact) if ok { break } } if interact == nil { game.LuaDoError(L, fmt.Sprintf("Tried to toggle a door, but don't have an interact action.")) L.PushNil() return 1 } exec := interact.AiToggleDoor(a.ent, door) if exec != nil { a.execs <- exec <-a.pause L.PushBoolean(door.IsOpened()) } else { L.PushNil() } return 1 } }