piXel496 Posted May 27, 2014 Posted May 27, 2014 Hi, The eventHandler: S_EVENT_PLAYER_ENTER_UNIT works perfect in single play. But does not execute if I join as a client in my server. Is this normal, because the EH seems a perfect solution to sync joining players? Or is there maybe an other EH I could use to sync my MP scenario with players that join the mission in progress. Thanks, . old stuff I made
ajax Posted May 27, 2014 Posted May 27, 2014 I use S_EVENT_BIRTH to track when a client enters an aircraft. Works fine in multiplayer. 1
piXel496 Posted May 27, 2014 Author Posted May 27, 2014 It works, thx Ajax! Somewhere I read that this only worked for server-player but that was an old post I guess. +1 on the way :) . old stuff I made
ENO Posted May 27, 2014 Posted May 27, 2014 Eh Pixel... can you explain a bit more about what you mean by syncing? Looking for some new functions I can use on a regular basis... wondering how you use this feature? "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
piXel496 Posted May 28, 2014 Author Posted May 28, 2014 (edited) An eventhandler is very usefull for tracking and participating on an event during the mission. In my case I am interested in a joining player. To track the event and participate with an action I use the below concept. Just Place it in the Global part of your script and it will fire. ------------------------------------------------------- JIPevHandler = {} function JIPevHandler:onEvent(newClient) if newClient.id == world.event.S_EVENT_BIRTH then --code you want to fire when a client joins (I plan to use it to sync objects with fresh players, it might need some filters. Because it fires everytime the players enters/reenters a plane) end end ------------------------------------------------------- [edit] Warning: fires for allunits that spawn in the mission also AIunits Cheers, . Edited May 28, 2014 by piXel496 old stuff I made
ENO Posted May 28, 2014 Posted May 28, 2014 Can I use it as a condition in lua predicate and set up a normal action through the ME? "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
piXel496 Posted May 28, 2014 Author Posted May 28, 2014 I think it is preferable if you put it in your initialization script. That is an option at the botom of triggers in the ME. I am a notepad type of scripter and just initialize my script. I only use the ME for some object and triggerMarkers. I get easily confused if I want to embed my ideas using the trigger actions of the ME or with the use of others library script constructions. But thats just my limitation. So maybe what you propose is possible but I don't know. :huh: . old stuff I made
ajax Posted May 28, 2014 Posted May 28, 2014 What do you have in mind, Eno? I don't think you will be successful trying to capture an event in a Lua predicate simply because the event can fire at any time whereas each trigger condition is checked only once per second (I think). At any rate, there is no guarantee the trigger condition will be checked at the exact same moment that the event fires. You could use an event handler to set various flags which are easily checked using ME trigger functions. Alternatively, the event handler can set various global script variables which can then be read by Lua predicate.
ENO Posted May 28, 2014 Posted May 28, 2014 Not even really sure yet- still trying to figure out certain scripts people use to do different things that I didn't think were possible before. Specifically in this case I was curious about what advantage there was to tracking when someone comes into the mission or when a client joins... thinking... hmmm... maybe there's something neat this guy is up to that I didn't know about before. One of my big issues that I've resolved through periodic updates through the map radio menu is updates on progress. Still not perfect... but I figured if I could broadcast an update to someone when that specific spot was filled it might help to brief the people who are new to the mission on what state it's at. To be honest- sometimes I inquire about such things just to see what other people are up to and neat ways to solve simple issues that up until discovery required complex solutions. "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art
ajax Posted May 28, 2014 Posted May 28, 2014 I'm always on the look-out for new ways to do things, too. That's why your question intrigued me. To send status messages when a client joins using mostly ME functions, I would: 1. Define and initialize a flag for each client slot in the mission (using a mission start trigger). 2. Create an event handler in a script that sets the appropriate flag whenever a client enters the sim. 3. Create a switched condition trigger for each client using the flag as the condition. 4. If flag is set send status message to that client and then reset the flag. Just thinking out loud, here. I'm sure there are multiple ways of doing this.
LFCChameleon_Silk Posted May 28, 2014 Posted May 28, 2014 thanks for that code can be used just to say server message on a client "birth" thats awesome and i can utilize this in many ways.
piXel496 Posted May 28, 2014 Author Posted May 28, 2014 (edited) ..advantage there was to tracking when someone comes into the mission or when a client joins... thinking... hmmm... maybe there's something neat this guy is up to that I didn't know about before... :smartass: Then it's probably most helpful if I try to explain my reason. First of all i am only interested in MP. Then most important is that every player experience the (A) same world at the (B) same moment. A. The same world for every player is actualy a multitude of copies of worlds with the original on the server. To make it work data needs to be syncronized. DCS Example: object with radio beacon spawns. Thats nice now the existing players can track the object. Pitty for the new joining player. Although he receives the object from the server. The radio beacon functionality he never receives. Unless the server tracks the new joining player event and updates the "beacon task" now all the worlds are in sync again. B. The same moment is just as important, no need to explain. To get close to the ideal situation. You could try to script elegant and efficient but functional. I do it by reducing loops and limiting recalculations of the same sum. Although not 100% sure I think an eventhandler is a fast, efficient and low cost triggered construction. Called from somewhere in the base code. So I prefere it above a selfbuild multitriggered loop construction. . Edited May 28, 2014 by piXel496 old stuff I made
piXel496 Posted May 28, 2014 Author Posted May 28, 2014 @ ajax How do you use S_EVENT_BIRTH? Because it fires for every unit spawning in the mission. AIunits aswell? I still think S_EVENT_PLAYER_ENTER_UNIT is the function that should do the trick... if it worked in MP. . old stuff I made
ajax Posted May 29, 2014 Posted May 29, 2014 @ ajax How do you use S_EVENT_BIRTH? Because it fires for every unit spawning in the mission. AIunits aswell? I still think S_EVENT_PLAYER_ENTER_UNIT is the function that should do the trick... if it worked in MP. I use the S_EVENT_BIRTH event in my TroopDrop script to ensure that any transport helicopter that enters the sim starts without any troops loaded. (This will happen if a previous client loads troops then gets killed or leaves the game.) In the event handler I iterate through a Lua table that contains the names of "active" transport helicopters, that is those that supposedly have troops loaded. If the unit that triggered the S_EVENT_BIRTH event is in that table then I wipe out that entry. I suppose I could make it more efficient by immediately testing if the unit is a transport helicopter, but I haven't found that to be necessary.
piXel496 Posted June 3, 2014 Author Posted June 3, 2014 (edited) Because I like solutions from others. So the least I can do is post my own doings. An example of a JIP script created with S_EVENT_BIRTH because S_EVENT_PLAYER_ENTER_UNIT currently does not work properly in MP. --player table to save values playerData {} --JIP eventhandler (this triggers on the event of a new object entering the DCS world) JIPevHandler = {} function JIPevHandler:onEvent(_newObject) if _newObject.id == world.event.S_EVENT_BIRTH and timer.getAbsTime() > 1 then local _eventObject = (_newObject.initiator) timer.scheduleFunction(JIP, _eventObject, timer.getTime() + 3) end end world.addEventHandler(JIPevHandler) --filter JIP player (now we want to syncronize only if the new object is a player) function JIP(_eventObject) local _plrName = _eventObject:getPlayerName() if _plrName ~= nil then local _unknownPlayer = true for i = 1, #playerData do if playerData[i].playerName == _plrName then --we found a player already registered in the player table "playerData" _unknownPlayer = false end end local _clientGroupId = Group.getID(Unit.getGroup(_eventObject)) if _unknownPlayer then -- This is what you could do with a new player, throw him in the table and fire some code local _clientId = _eventObject:getID() local _clientName = _eventObject:getPlayerName() local _clientUnitName = _eventObject:getName() local _clientType = _eventObject:getTypeName() playerData[#playerData + 1] = { playerId = _clientId, playerGroupId = _clientGroupId, playerName = _clientName, playerUnitName = _clientUnitName, playerType = _clientType, --### here you could place the code that updates the player that entered for the first time end --### here you could place code that updates the player and it fires every time as a player becomes a unit even if its found in the player table "playerData" end end --this is a looping procedure that checks every second if a player exists otherwise it wil be deleted from the player table (this needs some fine tuning to determine if player disconnected...!) function checkPlayerExistence() local _j = 1 while _j <= #playerData do local _plr = Unit.getByName(playerData[_j].playerUnitName) if _plr == nil then table.remove(playerData, _j) else _j = _j + 1 end end timer.scheduleFunction(checkPlayerExistence, nil, timer.getTime() + 1) end --initial start of the player check loop timer.scheduleFunction(checkPlayerExistence, nil, timer.getTime() + 5) If you have any comments or smart adjustments please post. . Edited June 7, 2014 by piXel496 old stuff I made
Recommended Posts