MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / TryRoomScriptEvent

Function TryRoomScriptEvent

internal/scripting/room.go:56–95  ·  view source on GitHub ↗
(eventName string, userId int, roomId int)

Source from the content-addressed store, hash-verified

54}
55
56func TryRoomScriptEvent(eventName string, userId int, roomId int) (bool, error) {
57
58 vmw, err := getRoomVM(roomId)
59 if err != nil {
60 return false, err
61 }
62
63 timestart := time.Now()
64 defer func() {
65 mudlog.Debug("TryRoomScriptEvent()", "eventName", eventName, "roomId", roomId, "time", time.Since(timestart))
66 }()
67
68 if onCommandFunc, ok := vmw.GetFunction(eventName); ok {
69
70 // Set forced ansi tag wrappers
71 userTextWrap.Set(`script-text`, ``, ``)
72 roomTextWrap.Set(`script-text`, ``, ``)
73
74 sUser := GetActor(userId, 0)
75 sRoom := GetRoom(roomId)
76
77 res, err := runCallable(vmw, scriptRoomTimeout, onCommandFunc,
78 vmw.VM.ToValue(sUser),
79 vmw.VM.ToValue(sRoom),
80 )
81
82 userTextWrap.Reset()
83 roomTextWrap.Reset()
84
85 if err != nil {
86 return false, fmt.Errorf("%s(): %w", eventName, err)
87 }
88
89 if boolVal, ok := res.Export().(bool); ok {
90 return boolVal, nil
91 }
92 }
93
94 return false, ErrEventNotFound
95}
96
97func TryRoomTryEnterEvent(userId int, destRoomId int) (bool, error) {
98

Callers 6

handlePlayerCombatFunction · 0.92
HandleJoinFunction · 0.92
GoFunction · 0.92
StartFunction · 0.92
TeleportFunction · 0.92
MoveRoomMethod · 0.85

Calls 8

DebugFunction · 0.92
getRoomVMFunction · 0.85
GetActorFunction · 0.85
GetRoomFunction · 0.85
runCallableFunction · 0.85
GetFunctionMethod · 0.80
SetMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected