DWORD WINAPI KeyBindsThread( LPVOID lpParam ) { KeyBindsThreadStarted = true; unsigned int time = 0; while (!bEnded){ for (auto it = keyBinds.begin(); it != keyBinds.end(); ++it){ if (GetAsyncKeyState(it->first) & 1) { ExecuteLua(state, it->second); } } for (unsigned int i = 0; i < repeats.size(); ++i){ repeatinfo &info = repeats[i]; if (info.delta + info.lastExec < time){ if (!ExecuteLua(state, info.lua)){ repeats.erase(repeats.begin()+i); --i; }else{ info.lastExec += info.delta; if (info.numtimes != -1) --info.numtimes; if (info.numtimes == 0){ repeats.erase(repeats.begin()+i); --i; } } } } ++time; Sleep(1); } KeyBindsThreadStarted = false; return 0; }
void CComponentTrigger::OnExit (CGameEntity* _pOther) { if(!IsActive()) return; if(!CheckEntered(_pOther)) return; m_sEntered[_pOther]--; if(m_sEntered[_pOther] == 0) { m_sEntered.erase(_pOther); ExecuteLua(m_szOnExit,_pOther); } }
void CComponentTrigger::OnEnter(CGameEntity* _pOther) { if(!IsActive()) return; if(CheckEntered(_pOther)) { m_sEntered[_pOther]++; return; } m_sEntered[_pOther] = 1; ExecuteLua(m_szOnEnter,_pOther); }
// returns true if error bool CScriptEngine::Execute (DISPID & dispid, // dispatch ID, will be set to DISPID_UNKNOWN on an error LPCTSTR szProcedure, // eg. ON_TRIGGER_XYZ const unsigned short iReason, // value for m_iCurrentActionSource LPCTSTR szType, // eg. trigger, alias LPCTSTR szReason, // eg. trigger subroutine XXX DISPPARAMS & params, // parameters long & nInvocationCount, // count of invocations COleVariant * result // result of call ) { // If Lua, we may have been called with no arguments, so just do that if (L) { list<double> nparams; list<string> sparams; bool r; bool status = ExecuteLua (dispid, szProcedure, iReason, szType, szReason, nparams, sparams, nInvocationCount, NULL, NULL, NULL, &r); if (result) { result->vt = VT_BOOL; result->boolVal = r; } return status; } // have Lua // don't do it if no routine address if (dispid == DISPID_UNKNOWN) return false; strProcedure = szProcedure; strType = szType; strReason = szReason; bImmediate = false; unsigned short iOldStyle = m_pDoc->m_iNoteStyle; m_pDoc->m_iNoteStyle = NORMAL; // back to default style HRESULT hr; EXCEPINFO ExcepInfo; unsigned int ArgErr; LARGE_INTEGER start, finish; SCRIPTSTATE ss; m_pDoc->Trace (TFormat ("Executing %s script \"%s\"", szType, szProcedure)); // Frame.SetStatusMessageNow (TFormat ("Executing %s subroutine \"%s\"", szType, szProcedure)); if (m_IActiveScript) { // new for Python - an error may have caused the script state to change hr = m_IActiveScript->GetScriptState (&ss); if (hr == S_OK) { // try to put it back to connected if (ss != SCRIPTSTATE_CONNECTED) hr = m_IActiveScript->SetScriptState (SCRIPTSTATE_CONNECTED); } if (hr != S_OK) { ::UMessageBox (TFormat ("Script engine problem invoking subroutine \"%s\" when %s", (LPCTSTR) szProcedure, (LPCTSTR) szReason)); strProcedure.Empty (); strType.Empty (); strReason.Empty (); bImmediate = true; m_pDoc->m_iNoteStyle = iOldStyle; return true; } } // end of having script engine if (App.m_iCounterFrequency) QueryPerformanceCounter (&start); else { start.QuadPart = 0; finish.QuadPart = 0; } if (iReason != eDontChangeAction) m_pDoc->m_iCurrentActionSource = iReason; hr = m_pDispatch->Invoke (dispid, IID_NULL, 0, DISPATCH_METHOD, ¶ms, result, &ExcepInfo, &ArgErr); if (iReason != eDontChangeAction) m_pDoc->m_iCurrentActionSource = eUnknownActionSource; if (hr == S_OK && App.m_iCounterFrequency) { QueryPerformanceCounter (&finish); m_pDoc->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart; if (m_pDoc->m_CurrentPlugin) m_pDoc->m_CurrentPlugin->m_iScriptTimeTaken += finish.QuadPart - start.QuadPart; } // put status line back // ShowStatusLine (); if (hr == S_OK) nInvocationCount++; // count number of times used else { dispid = DISPID_UNKNOWN; // stop further invocations if (hr == 0x800a01c2) // wrong number of arguments ::UMessageBox (TFormat ("Wrong number of arguments for script subroutine \"%s\" when %s" "\n\nWe expected your subroutine to have %i argument%s", (LPCTSTR) szProcedure, (LPCTSTR) szReason, PLURAL (params.cArgs))); else ::UMessageBox (TFormat ("Unable to invoke script subroutine \"%s\" when %s", (LPCTSTR) szProcedure, (LPCTSTR) szReason)); } // end of bad invoke strProcedure.Empty (); strType.Empty (); strReason.Empty (); bImmediate = true; m_pDoc->m_iNoteStyle = iOldStyle; return hr != S_OK; // true on error } // end of CScriptEngine::ExecuteScript