Sir Warock Posted December 3, 2022 Share Posted December 3, 2022 Hello there. I can't figure out how to get the specific player that clicked on my modded context menu. I have looked at the Lua events and there is no "OnContextMenuClick" event - So, I don't even know how to do it then. Do other mods use a work around, or is that specific event just not included in the event list? How do I get the player that clicked on my context menu? Link to comment Share on other sites More sharing options...
stuck1a Posted December 6, 2022 Share Posted December 6, 2022 (edited) You will receive it as argument out of the Java event dispatcher if the event fires. Here is an example: --- --- Event handler for OnFillWorldObjectContextMenu --- @param player int ID of the player who did the right click --- @param context ISContextMenu The current context menu object --- @param worldobjects table Global objects found on the clicked point --- @param test boolean Whether this call is a fetch only call for controller support --- function ISWaterCollectorMenu.OnFillWorldObjectContextMenu(player, context, worldobjects, test) local oPlayer = getSpecificPlayer(player) end Events.OnFillWorldObjectContextMenu.Add(ISWaterCollectorMenu.OnFillWorldObjectContextMenu) Important Note: As you can see, those handlers are not object specific. This means, every function which listens to the event will be fired. So for the sake of performance, it's importantn, that the very first thing you do in such functions is, to check, whether the right clicked square contains any object this function is associated with and if not, to delegate to the next one by returning the execution flow. Mostly, this is done by iterating through the worldobjects arguments and check, whether it contains an object, this handler is made for. This can be done like here: if test and ISWorldObjectContextMenu.Test then return true end local found, isoObject = false for _,v in ipairs(worldobjects) do local square = v:getSquare() if square then for i=1, square:getObjects():size() do local v = square:getObjects():get(i-1) if CWaterCollectorSystem.instance:isValidIsoObject(v) then isoObject = v found = true break end end end if found then break end end if not found then return end (checking for test is relevant for controller support) Edited December 9, 2022 by stuck1a still Java, not JS... Sir Warock 1 Link to comment Share on other sites More sharing options...
stuck1a Posted December 6, 2022 Share Posted December 6, 2022 Btw: You can get the list of events from zombie/Lua/LuaEventManager:AddEvent() AddEvent("OnGameBoot"); AddEvent("OnPreGameStart"); AddEvent("OnTick"); AddEvent("OnTickEvenPaused"); AddEvent("OnRenderUpdate"); AddEvent("OnFETick"); AddEvent("OnGameStart"); AddEvent("OnPreUIDraw"); AddEvent("OnPostUIDraw"); AddEvent("OnCharacterCollide"); AddEvent("OnKeyStartPressed"); AddEvent("OnKeyPressed"); AddEvent("OnObjectCollide"); AddEvent("OnNPCSurvivorUpdate"); AddEvent("OnPlayerUpdate"); AddEvent("OnZombieUpdate"); AddEvent("OnTriggerNPCEvent"); AddEvent("OnMultiTriggerNPCEvent"); AddEvent("OnLoadMapZones"); AddEvent("OnLoadedMapZones"); AddEvent("OnAddBuilding"); AddEvent("OnCreateLivingCharacter"); AddEvent("OnChallengeQuery"); AddEvent("OnFillInventoryObjectContextMenu"); AddEvent("OnPreFillInventoryObjectContextMenu"); AddEvent("OnFillWorldObjectContextMenu"); AddEvent("OnPreFillWorldObjectContextMenu"); AddEvent("OnRefreshInventoryWindowContainers"); AddEvent("OnGamepadConnect"); AddEvent("OnGamepadDisconnect"); AddEvent("OnJoypadActivate"); AddEvent("OnJoypadActivateUI"); AddEvent("OnJoypadBeforeDeactivate"); AddEvent("OnJoypadDeactivate"); AddEvent("OnJoypadBeforeReactivate"); AddEvent("OnJoypadReactivate"); AddEvent("OnJoypadRenderUI"); AddEvent("OnMakeItem"); AddEvent("OnWeaponHitCharacter"); AddEvent("OnWeaponSwing"); AddEvent("OnWeaponHitTree"); AddEvent("OnWeaponHitXp"); AddEvent("OnWeaponSwingHitPoint"); AddEvent("OnPlayerAttackFinished"); AddEvent("OnLoginState"); AddEvent("OnLoginStateSuccess"); AddEvent("OnCharacterCreateStats"); AddEvent("OnLoadSoundBanks"); AddEvent("OnObjectLeftMouseButtonDown"); AddEvent("OnObjectLeftMouseButtonUp"); AddEvent("OnObjectRightMouseButtonDown"); AddEvent("OnObjectRightMouseButtonUp"); AddEvent("OnDoTileBuilding"); AddEvent("OnDoTileBuilding2"); AddEvent("OnDoTileBuilding3"); AddEvent("OnConnectFailed"); AddEvent("OnConnected"); AddEvent("OnDisconnect"); AddEvent("OnConnectionStateChanged"); AddEvent("OnScoreboardUpdate"); AddEvent("OnMouseMove"); AddEvent("OnMouseDown"); AddEvent("OnMouseUp"); AddEvent("OnRightMouseDown"); AddEvent("OnRightMouseUp"); AddEvent("OnNewSurvivorGroup"); AddEvent("OnPlayerSetSafehouse"); AddEvent("OnLoad"); AddEvent("AddXP"); AddEvent("LevelPerk"); AddEvent("OnSave"); AddEvent("OnMainMenuEnter"); AddEvent("OnPreMapLoad"); AddEvent("OnPostFloorSquareDraw"); AddEvent("OnPostFloorLayerDraw"); AddEvent("OnPostTilesSquareDraw"); AddEvent("OnPostTileDraw"); AddEvent("OnPostWallSquareDraw"); AddEvent("OnPostCharactersSquareDraw"); AddEvent("OnCreateUI"); AddEvent("OnMapLoadCreateIsoObject"); AddEvent("OnCreateSurvivor"); AddEvent("OnCreatePlayer"); AddEvent("OnPlayerDeath"); AddEvent("OnZombieDead"); AddEvent("OnCharacterDeath"); AddEvent("OnCharacterMeet"); AddEvent("OnSpawnRegionsLoaded"); AddEvent("OnPostMapLoad"); AddEvent("OnAIStateExecute"); AddEvent("OnAIStateEnter"); AddEvent("OnAIStateExit"); AddEvent("OnAIStateChange"); AddEvent("OnPlayerMove"); AddEvent("OnInitWorld"); AddEvent("OnNewGame"); AddEvent("OnIsoThumpableLoad"); AddEvent("OnIsoThumpableSave"); AddEvent("ReuseGridsquare"); AddEvent("LoadGridsquare"); AddEvent("EveryOneMinute"); AddEvent("EveryTenMinutes"); AddEvent("EveryDays"); AddEvent("EveryHours"); AddEvent("OnDusk"); AddEvent("OnDawn"); AddEvent("OnEquipPrimary"); AddEvent("OnEquipSecondary"); AddEvent("OnClothingUpdated"); AddEvent("OnWeatherPeriodStart"); AddEvent("OnWeatherPeriodStage"); AddEvent("OnWeatherPeriodComplete"); AddEvent("OnWeatherPeriodStop"); AddEvent("OnRainStart"); AddEvent("OnRainStop"); AddEvent("OnAmbientSound"); AddEvent("OnWorldSound"); AddEvent("OnResetLua"); AddEvent("OnModsModified"); AddEvent("OnSeeNewRoom"); AddEvent("OnNewFire"); AddEvent("OnFillContainer"); AddEvent("OnChangeWeather"); AddEvent("OnRenderTick"); AddEvent("OnDestroyIsoThumpable"); AddEvent("OnPostSave"); AddEvent("OnResolutionChange"); AddEvent("OnWaterAmountChange"); AddEvent("OnClientCommand"); AddEvent("OnServerCommand"); AddEvent("OnContainerUpdate"); AddEvent("OnObjectAdded"); AddEvent("OnObjectAboutToBeRemoved"); AddEvent("onLoadModDataFromServer"); AddEvent("OnGameTimeLoaded"); AddEvent("OnCGlobalObjectSystemInit"); AddEvent("OnSGlobalObjectSystemInit"); AddEvent("OnWorldMessage"); AddEvent("OnKeyKeepPressed"); AddEvent("SendCustomModData"); AddEvent("ServerPinged"); AddEvent("OnServerStarted"); AddEvent("OnLoadedTileDefinitions"); AddEvent("OnPostRender"); AddEvent("DoSpecialTooltip"); AddEvent("OnCoopJoinFailed"); AddEvent("OnServerWorkshopItems"); AddEvent("OnVehicleDamageTexture"); AddEvent("OnCustomUIKey"); AddEvent("OnCustomUIKeyPressed"); AddEvent("OnCustomUIKeyReleased"); AddEvent("OnDeviceText"); AddEvent("OnRadioInteraction"); AddEvent("OnLoadRadioScripts"); AddEvent("OnAcceptInvite"); AddEvent("OnCoopServerMessage"); AddEvent("OnReceiveUserlog"); AddEvent("OnAdminMessage"); AddEvent("OnGetDBSchema"); AddEvent("OnGetTableResult"); AddEvent("ReceiveFactionInvite"); AddEvent("AcceptedFactionInvite"); AddEvent("ReceiveSafehouseInvite"); AddEvent("AcceptedSafehouseInvite"); AddEvent("ViewTickets"); AddEvent("SyncFaction"); AddEvent("OnReceiveItemListNet"); AddEvent("OnMiniScoreboardUpdate"); AddEvent("OnSafehousesChanged"); AddEvent("RequestTrade"); AddEvent("AcceptedTrade"); AddEvent("TradingUIAddItem"); AddEvent("TradingUIRemoveItem"); AddEvent("TradingUIUpdateState"); AddEvent("OnGridBurnt"); AddEvent("OnPreDistributionMerge"); AddEvent("OnDistributionMerge"); AddEvent("OnPostDistributionMerge"); AddEvent("MngInvReceiveItems"); AddEvent("OnTileRemoved"); AddEvent("OnServerStartSaving"); AddEvent("OnServerFinishSaving"); AddEvent("OnMechanicActionDone"); AddEvent("OnClimateTick"); AddEvent("OnThunderEvent"); AddEvent("OnEnterVehicle"); AddEvent("OnSteamGameJoin"); AddEvent("OnTabAdded"); AddEvent("OnSetDefaultTab"); AddEvent("OnTabRemoved"); AddEvent("OnAddMessage"); AddEvent("SwitchChatStream"); AddEvent("OnChatWindowInit"); AddEvent("OnInitSeasons"); AddEvent("OnClimateTickDebug"); AddEvent("OnInitModdedWeatherStage"); AddEvent("OnUpdateModdedWeatherStage"); AddEvent("OnClimateManagerInit"); AddEvent("OnPressReloadButton"); AddEvent("OnPressRackButton"); AddEvent("OnHitZombie"); AddEvent("OnBeingHitByZombie"); AddEvent("OnServerStatisticReceived"); AddEvent("OnDynamicMovableRecipe"); AddEvent("OnInitGlobalModData"); AddEvent("OnReceiveGlobalModData"); AddEvent("OnInitRecordedMedia"); AddEvent("onUpdateIcon"); AddEvent("preAddForageDefs"); AddEvent("preAddSkillDefs"); AddEvent("preAddZoneDefs"); AddEvent("preAddCatDefs"); AddEvent("preAddItemDefs"); AddEvent("onAddForageDefs"); AddEvent("onFillSearchIconContextMenu"); AddEvent("onItemFall"); AddEvent("OnTemplateTextInit"); Link to comment Share on other sites More sharing options...
Sir Warock Posted December 8, 2022 Author Share Posted December 8, 2022 (edited) On 12/6/2022 at 7:55 AM, stuck1a said: You will receive it as argument out of the JS event dispatcher if the event fires. Here is an example: --- --- Event handler for OnFillWorldObjectContextMenu --- @param player int ID of the player who did the right click --- @param context ISContextMenu The current context menu object --- @param worldobjects table Global objects found on the clicked point --- @param test boolean Whether this call is a fetch only call for controller support --- function ISWaterCollectorMenu.OnFillWorldObjectContextMenu(player, context, worldobjects, test) local oPlayer = getSpecificPlayer(player) end Events.OnFillWorldObjectContextMenu.Add(ISWaterCollectorMenu.OnFillWorldObjectContextMenu) Important Note: As you can see, those handlers are not object specific. This means, every function which listens to the event will be fired. So for the sake of performance, it's importantn, that the very first thing you do in such functions is, to check, whether the right clicked square contains any object this function is associated with and if not, to delegate to the next one by returning the execution flow. Mostly, this is done by iterating through the worldobjects arguments and check, whether it contains an object, this handler is made for. This can be done like here: if test and ISWorldObjectContextMenu.Test then return true end local found, isoObject = false for _,v in ipairs(worldobjects) do local square = v:getSquare() if square then for i=1, square:getObjects():size() do local v = square:getObjects():get(i-1) if CWaterCollectorSystem.instance:isValidIsoObject(v) then isoObject = v found = true break end end end if found then break end end if not found then return end (checking for test is relevant for controller support) Thank you! I will try this out! Edited December 8, 2022 by Sir Warock Minor spelling mistake Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now