ADHS Posted October 26, 2022 Posted October 26, 2022 (edited) Hello. I tried to check events with both ways: IF..THEN..END IF..ELSEIF..END if Event.id == * I've noticed that ENTER and LEAVE worked ONLY with string world.event.if Event.id == S_EVENT_PLAYER_ENTER_UNIT instead others (CRASH,BIRTH,DEAD, etc) with event numbers world.event.if Event.id == 5 Is it my side effect, or indeed each event needs number/string ? Thank you. Edited October 26, 2022 by ADHS Democracy was already invented, while Scrat was eating oak fruits.
toutenglisse Posted October 26, 2022 Posted October 26, 2022 3 hours ago, ADHS said: ...I've noticed that ENTER and LEAVE worked ONLY with string world.event.if Event.id == S_EVENT_PLAYER_ENTER_UNIT... I've just checked and both following sentences work : if event.id == 20 then if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT then 1
Grimes Posted October 27, 2022 Posted October 27, 2022 Its fairly common throughout the scripting engine that values are defined within table entries and you can use one or the other. If you dump _G then you can see a list of the events like below, which is how the event types table is saved. A lot of the time the value is an "enumerator" which most of the time just means its a number value that might not have a frame of reference. What I mean is if you check event.id == 8 then you *have* to know what is at id 8, if for whatever reason ED decided to insert an event into the list, then every id after that would be shifted. Whereas if you used world.event.S_EVENT_DEAD then the only way that would break is if that event was deleted. ["world"]["event"] = table: 000001E8157FC630 { ["world"]["event"]["S_EVENT_MISSION_END"] = 12, ["world"]["event"]["S_EVENT_DAYNIGHT"] = 39, ["world"]["event"]["S_EVENT_AI_ABORT_MISSION"] = 38, ["world"]["event"]["S_EVENT_KILL"] = 28, ["world"]["event"]["S_EVENT_UNIT_CREATE_TASK"] = 44, ["world"]["event"]["S_EVENT_SHOOTING_END"] = 24, ["world"]["event"]["S_EVENT_BASE_CAPTURED"] = 10, ["world"]["event"]["S_EVENT_DEAD"] = 8, ["world"]["event"]["S_EVENT_TRIGGER_ZONE"] = 35, ["world"]["event"]["S_EVENT_EJECTION"] = 6, ["world"]["event"]["S_EVENT_WEAPON_ADD"] = 34, ["world"]["event"]["S_EVENT_SHOOTING_START"] = 23, ["world"]["event"]["S_EVENT_UNIT_LOST"] = 30, ["world"]["event"]["S_EVENT_INVALID"] = 0, ["world"]["event"]["S_EVENT_PLAYER_ENTER_UNIT"] = 20, ["world"]["event"]["S_EVENT_EMERGENCY_LANDING"] = 43, ["world"]["event"]["S_EVENT_CRASH"] = 5, ["world"]["event"]["S_EVENT_MAX"] = 46, ["world"]["event"]["S_EVENT_LANDING_AFTER_EJECTION"] = 31, ["world"]["event"]["S_EVENT_PLAYER_LEAVE_UNIT"] = 21, ["world"]["event"]["S_EVENT_HUMAN_FAILURE"] = 16, ["world"]["event"]["S_EVENT_ENGINE_SHUTDOWN"] = 19, ["world"]["event"]["S_EVENT_PILOT_DEAD"] = 9, ["world"]["event"]["S_EVENT_REFUELING_STOP"] = 14, ["world"]["event"]["S_EVENT_LANDING_QUALITY_MARK"] = 36, ["world"]["event"]["S_EVENT_BDA"] = 37, ["world"]["event"]["S_EVENT_HIT"] = 2, ["world"]["event"]["S_EVENT_MARK_ADDED"] = 25, ["world"]["event"]["S_EVENT_ENGINE_STARTUP"] = 18, ["world"]["event"]["S_EVENT_LAND"] = 4, ["world"]["event"]["S_EVENT_FLIGHT_TIME"] = 40, ["world"]["event"]["S_EVENT_DISCARD_CHAIR_AFTER_EJECTION"] = 33, ["world"]["event"]["S_EVENT_TAKEOFF"] = 3, ["world"]["event"]["S_EVENT_TOOK_CONTROL"] = 13, ["world"]["event"]["S_EVENT_PLAYER_CAPTURE_AIRFIELD"] = 42, ["world"]["event"]["S_EVENT_PLAYER_COMMENT"] = 22, ["world"]["event"]["S_EVENT_PLAYER_SELF_KILL_PILOT"] = 41, ["world"]["event"]["S_EVENT_SCORE"] = 29, ["world"]["event"]["S_EVENT_REFUELING"] = 7, ["world"]["event"]["S_EVENT_PARATROOPER_LENDING"] = 32, ["world"]["event"]["S_EVENT_BIRTH"] = 15, ["world"]["event"]["S_EVENT_SHOT"] = 1, ["world"]["event"]["S_EVENT_MARK_REMOVED"] = 27, ["world"]["event"]["S_EVENT_MARK_CHANGE"] = 26, ["world"]["event"]["S_EVENT_DETAILED_FAILURE"] = 17, ["world"]["event"]["S_EVENT_MISSION_START"] = 11, ["world"]["event"]["S_EVENT_UNIT_DELETE_TASK"] = 45, }, 2 The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
ADHS Posted October 28, 2022 Author Posted October 28, 2022 (edited) 8 hours ago, Grimes said: values are defined within table entries and you can use one or the other On 10/27/2022 at 2:52 AM, toutenglisse said: I've just checked and both following sentences work Hello and thank you both (Grimes for the printout). Hmm, so it's better to check for both cases at the same time: if Event.id == string or number. I am trying to setup a custom multi-event handler check and i am facing many problems (overlaping alarms etc) so i wanted to be sure that this is working. And now i am : i am defenetly doing something wrong that need to be fixed. Thank you very much. PS: I am experimenting with both MIST and DCS Event Handlers. Can you please give me a draft of the propper way to call them ? Others calling them directly, others with a local var, others with equations, so i've got confused. Edited October 28, 2022 by ADHS Democracy was already invented, while Scrat was eating oak fruits.
toutenglisse Posted October 28, 2022 Posted October 28, 2022 5 hours ago, ADHS said: ...Hmm, so it's better to check for both cases at the same time: if Event.id == string or number. ... I think Grimes said it's better to only test the event "string", as number can change but not "string" : 13 hours ago, Grimes said: ...if you used world.event.S_EVENT_DEAD then the only way that would break is if that event was deleted... 5 hours ago, ADHS said: ...I am trying to setup a custom multi-event handler check and i am facing many problems (overlaping alarms etc)...Can you please give me a draft of the propper way to call them ?... Here is a script example where I check for SP player/client both "pilot dead" and "killed" events (so script works when player crashes, get killed, or eject from damaged aircraft). Both can happen at same time and so desired following schedulled functions (respawn and countdown messages) can overlap. So when 1 event occures I first remove schedulled functions of probable other event : Spoiler local MessageID = {} function WhenDEAD(player) mist.removeFunction(RespawnID) for i = 1, 5 do mist.removeFunction(MessageID[i]) end local playerDatas = mist.getGroupData(player:getGroup():getName()) for i = 1, 4 do if playerDatas["units"][i] and playerDatas["units"][i]["skill"] == "Client" then playerDatas["units"][i]["skill"] = "Player" end end RespawnID = mist.scheduleFunction(mist.dynAdd,{playerDatas}, timer.getTime() + 6) for i = 1, 5 do MessageID[i] = mist.scheduleFunction(trigger.action.outText,{player:getPlayerName()..' you will be respawned in '.. (i==1 and '5' or i==2 and '4' or i==3 and '3' or i==4 and '2' or i==5 and '1')..' seconds.',1,true}, timer.getTime() + 0.5 + (i-1)) end end function DEAD(event) if event.id == world.event.S_EVENT_PILOT_DEAD and event.initiator and event.initiator == world.getPlayer() then player = event.initiator WhenDEAD(player) elseif event.id == world.event.S_EVENT_KILL and event.target and event.target == world.getPlayer() then player = event.target WhenDEAD(player) end end mist.addEventHandler(DEAD) 1
ADHS Posted October 28, 2022 Author Posted October 28, 2022 (edited) Thank you very much for the code. I really appreciate it my friend. I have to study/analyze it because for me, this comes from the future! 20 hours ago, toutenglisse said: I think Grimes said it's better to only test the event "string", as number can change but not "string" : Yes, i understood what Grimes meant. But after his reply i've setup something like this that will detect on the fly any number that have change without notice: (Haven't make it work yet but this the basic skeleton. I think the string is hidden somewhere near the world.event field but i couldn't find a way to get it so to campare both fields.) LeCONST = 'world.event.S_EVENT_' _EVENTS = { [PLAYER_LEAVE_UNIT] = { o_VAL = 20, n_VAL = 0, eve = '_LEAVE', dia = _LEAVE} } for key,value in pairs(_EVENTS) do LeKEY = key LeEVENT = LeCONST..LeKEY _EVENTS[LeKEY].n_VAL = _Event.id LeID = _EVENTS[LeKEY].n_VAL if (world.event == LeEVENT and LeID ==_Event.id or world.event == LeEVENT and _EVENTS[LeKEY].o_VAL == _Event.id ) then .... As for the multi-event handler check, this is a draft that i have in mind to use in conjuction with the above basis, to shorten the typing: LeCONST = 'world.event.S_EVENT_' _EVENTS = { ['BIRTH'] = {eve = '_BIRTH', dia = _BIRTH}, ['PLAYER_ENTER_UNIT'] = {eve = '_ENTER', dia = _ENTER}, ['PLAYER_LEAVE_UNIT'] = {eve = '_LEAVE', dia = _LEAVE}, ['UNIT_LOST'] = {eve = '_LOST', dia = _LOST}, ['LAND'] = {eve = '_LAND', dia = _LAND}, ['CRASH'] = {eve = '_CRASH', dia = _CRASH}, ['PILOT_DEAD'] = {eve = '_PDEAD', dia = _PDEAD}, ['BASE_CAPTURED'] = {eve = '_CAPTU', dia = _CAPTU}} Thank you(always) PS: Yes, i've noticed that S_EVENT_DEAD is simply "dead"! UNIT_LOST is what i use as the replacement. Edited October 29, 2022 by ADHS Democracy was already invented, while Scrat was eating oak fruits.
Recommended Posts