Jump to content

jshock

Member
  • Content Count

    3059
  • Joined

  • Last visited

  • Medals

  • Medals

Posts posted by jshock


  1. 5 minutes ago, phronk said:

     

    My understanding was that eventHandlers are constantly checking (looping) if the event (Fired, GetInMan, Explosion, etc.) is met, then checks condition for that event(s).

    Well, technically everything is apart of the main game loop in the end, which I'd assume is the case with the conditions of the regular EHs, which is what I believe you meant. Dedmen may have misunderstood the scope of your statement.

    • Thanks 1

  2. 1 hour ago, sarogahtyp said:

    calling a function in a loop which checks if an event is happening and calling a scripted EH

     

     

    There is no difference when calling, however, you can add any number of scriptedEH of the same name (each with their own behavior) and subsequently call all of them at the same time.

     

    So say OP here had an addon that added a scripted EH for localized messages to a player (let’s name it sendMsg). Now say you have a function that i want to use in my mission that adds sendMsg and your message says “Hello!”. And now I’ve also added a sendMsg of my own with a message that says “To infinity and...well that’s about it”. Now when sendMsg is called the player would see both our messages.

     

    Think about Respawn EHs, every mission maker out there probably does their own thing for respawn as well as every outside script that accounts for respawn in their mission. When the player respawns the EH fires and all of that code gets called, the mission maker, outside scripts, etc.

     

    You can essentially “stack” executions of different code on one event and when that event fires (i.e. called) the entire stack is called.

    • Like 4

  3. Uploaded to GitHub, OP updated. So I can be publicly shamed for terrible coding practices :rthumb:. Any contributions are welcome (still trying to figure out all the GitHub stuff too). However, I do have limits on the scope of this mod because I would prefer to not compete with Ravage or other similar addons.

     

    fN4KHs5.png

    • Like 3

  4. 14 hours ago, jshock said:

    make a custom event handler for say, entering and leaving the area of a marker

     

    8 hours ago, ZaellixA said:

    So, I was wondering, what is the difference of running a constant loop and when the condition is met, run a script in every "concerned" unit? Now, I do understand that tracking the "concerned" units now has become a lot easier with the use of sciptedEventHandlers, but still haven't found a way to avoid this constant loop

     

    Figured out the long hand for my concept (using OEF)....probably a little messy and could use some fine tuning here and there, especially when accounting for more than just one player in SP. At least some sort of reference for what you would have to do. But open the editor, place a unit, any number of markers, follow the example function calls at the bottom, copy all and paste into debug and exec:

     

    Spoiler
    
    /////////////////////////
    //  Main Background Functions
    /////////////////////////
    jshk_mrk_fnc_onExitMarker = {
    	params [["_marker","",[""]]];
    	if (allMapMarkers find _marker > -1) then {
    		missionNamespace setVariable [
    			"jshk_exitMarkerEH_id",
    			[	true,format ["jshk_exitMarkerArea_%1",_marker],
    			{
    				params [
    					["_obj",objNull,[objNull]],
    					["_marker","",[""]],
    					["_code",{},[{}]]
    				];
    				private _inAreaMarkers = missionNamespace getVariable ["jshk_currentInAreaMarkers",[]];
    				private _areaIndex = _inAreaMarkers find _marker;
    				if !(_areaIndex isEqualTo -1) then {
    					[_obj,_marker] call _code;
    					_inAreaMarkers deleteAt _areaIndex;
    					missionNamespace setVariable ["jshk_currentInAreaMarkers",_inAreaMarkers];
    					private _id = missionNamespace getVariable ["jshk_exitMarkerEH_id",-1];
    					if !(_id isEqualTo -1) then
    					{
    						[true,format ["jshk_exitMarkerArea_%1",_marker],_id] call BIS_fnc_removeScriptedEventHandler;
    					};
    				};
    			}] call BIS_fnc_addScriptedEventHandler
    		];
    	};
    };
    
    jshk_mrk_fnc_onEnterMarker = {
    	params [["_marker","",[""]]];
    	if (allMapMarkers find _marker > -1) then {
    		[true,format ["jshk_enterMarkerArea_%1",_marker],
    		{
    			params [
    				["_obj",objNull,[objNull]],
    				["_marker","",[""]],
    				["_code",{},[{}]]
    			];
    			private _inAreaMarkers = missionNamespace getVariable ["jshk_currentInAreaMarkers",[]];
    			private _areaIndex = _inAreaMarkers find _marker;
    			if (_areaIndex isEqualTo -1) then {
    				_inAreaMarkers pushBack _marker;
    				missionNamespace setVariable ["jshk_currentInAreaMarkers",_inAreaMarkers];
    				[_obj,_marker] call _code;
    				[_marker] call jshk_mrk_fnc_onExitMarker;
    			};
    		}] call BIS_fnc_addScriptedEventHandler;
    	};
    };
    
    jshk_mrk_fnc_getMarkerHash = {
    	params [["_marker","",[""]]];
    	private _markerHashes = missionNamespace getVariable ["jshk_markerHashList",[]];
    	private _index = _markerHashes findIf {_x select 0 isEqualTo _marker};
    	private _code = [{},{}];
    	if (_index > -1) then {
    		_code = _markerHashes select _index select 1;
    	};
    	_code;
    };
    
    /////////////////////////
    //  Main User Function
    /////////////////////////
    jshk_mrk_fnc_addMarkerAreaEH = {
    	params [
    		["_marker","",[""]],
    		["_onEnter",{},[{}]],
    		["_onExit",{},[{}]]
    	];
    	private _old = missionNamespace getVariable ["jshk_checkMarkerArray",[]];
    	private _index = _old find _marker;
    	if (_index isEqualTo -1) then {
    		[_marker] call jshk_mrk_fnc_onEnterMarker;
    		private _hashList = missionNamespace getVariable ["jshk_markerHashList",[]]; 
    		_hashList pushBack [_marker,[_onEnter,_onExit]];
    		_old pushBack _marker;
    		missionNamespace setVariable ["jshk_checkMarkerArray",_old];
    		missionNamespace setVariable ["jshk_markerHashList",_hashList];
    	};
    };
    
    
    /////////////////////////
    //  OEF applied (post init)
    //  'Event handler handling'
    //  Applied to player for testing purposes
    /////////////////////////
    [ "jshk_inMarkerArea_OEF", "onEachFrame", 
    	{
    		private _markers = missionNamespace getVariable ["jshk_checkMarkerArray",[]];
    		
    		params [["_obj",objNull,[objNull]]];
    		if (!isNull _obj) then {
    			private _outMarkers = [];
    			private _inMarkers = _markers select {getPos player inArea _x};
    
    			if !(_inMarkers isEqualTo []) then {
    				{
    					private _code = [_x] call jshk_mrk_fnc_getMarkerHash;
    					[true,format ["jshk_enterMarkerArea_%1",_x],[player,_x,_code select 0],false] call BIS_fnc_callScriptedEventHandler;
    				} forEach _inMarkers;
    			} else {
    				{	
    					private _code = [_x] call jshk_mrk_fnc_getMarkerHash;
    					[true,format ["jshk_exitMarkerArea_%1",_x],[player,_x,_code select 1],false] call BIS_fnc_callScriptedEventHandler;
    				} forEach _markers;
    			};
    		};
    	},
    [player]] call BIS_fnc_addStackedEventHandler;
    
    
    
    /////////////////////////
    //  Test uses of user function jshk_mrk_fnc_addMarkerArea
    //  Params: [string,code,code]
    //  0: "markerName"
    //	1: {code on entering marker area}
    //			Params available in code: [obj EH is attached, marker name]
    //	2: {code on exiting marker area}
    //			Params available in code: [obj EH is attached, marker name]
    /////////////////////////
    ["test",{systemChat "in: test";},{systemChat "out: test";}] call jshk_mrk_fnc_addMarkerAreaEH;
    ["test_1",{systemChat "in: test_1";},{systemChat "out: test_1";}] call jshk_mrk_fnc_addMarkerAreaEH;
    ["test_2",{systemChat "in: test_2";},{systemChat "out: test_2";}] call jshk_mrk_fnc_addMarkerAreaEH;
    ["test_3",{systemChat "in: test_3";},{systemChat "out: test_3";}] call jshk_mrk_fnc_addMarkerAreaEH;

     

    Then move in and out of the marker areas as desired to see results.

     

    And yes I know my “hash” function isn’t really quite that....

    • Like 2
    • Thanks 1

  5. Now I haven't dug too deep into understanding the extent of CBA's system but my question is with either system is it possible to make a custom event handler for say, entering and leaving the area of a marker, without having to create any sort of while loop or OEF handler?

     

    In basic vanilla EH terms (I know there are some major assumptions here):

     

    player addEventHandler [ "EnterMarkerArea",
    	{
    		params ["_marker"];
    		if (_marker isEqualTo "mySpecialMarker") then
    		{
    			hint "You made it!";
    		};
    	}
    ];
    player addEventHandler [ "ExitMarkerArea",
    	{
    		params ["_marker"];
    		if (_marker isEqualTo "mySpecialMarker") then
    		{
    			hint "You left the marker area!";
    		};
    	}
    ];

     

    Because with how I understand either system atm it seems like there would still need to be some sort of loop or similar handling to call the "event" code?

     

     

    • Like 2

  6. 3 hours ago, ZaellixA said:

    this whole topic started from scriptedEventHandlers and ended up going a bit deeper into eventHandlers in general. Please let me know if I ask too much from people here or if I should start a different topic.

     

    Eh, one could argue that without fundamentally understanding event handlers in general you can't truly understand the difference between the base EHs and scripted ones :tounge2:. I for one have had the similar questions too.

    • Like 2

  7. Make sure that the marker is set properly in 3D space in the editor (as in the proper height on the ship) and make this small change to your code. If the first option doesn't work, try the second and change the marked value. Info: getMarkerPos  set

     

    _slingammo = "B_Slingload_01_Ammo_F" createvehicle (getmarkerpos ["huron_pickup",true]);
    
    //getMarkerPos ["myMrk",true] returns a position array with [x,y,z]
    
    /////OR
    
    _slingammo = "B_Slingload_01_Ammo_F" createvehicle (getmarkerpos "huron_pickup") set [2,*properHeightOfShipSurface*];
    //getMarkerPos "myMrk" returns a position array as [x,y,0]
    //subsequently using 'set [2,someNumber]' overwrites that zero to whatever value you input

     

     

    EDIT: After seeing that you actually can't easily set the marker height via editor and noticing the return of getMarkerPos [array] is positionAGL you may run into problems since you're on a ship. Second option is your best option.

    • Like 2

  8. Well either you or the server isn’t loading with the mod, that’s why that error is present that’s pretty cut and dry. Now in the midst of making changes to your mod if you altered the CfgPatches classname there is a chance that the mission doesn’t recognize the new class and is still looking for the old one. That’s the only other possibility I can think of.


  9. 4 hours ago, eviljack109 said:

    The problem with this is people tend to pick up the stuff from one kit, drop it on the floor, pick another cit, then combine the two. Making for some people to have really OP load-outs which were never the intent of the system I made.

    Yea, people are a$$holes, but there really isn't anyway to prevent this unless you disable their ability to drop things from their inventory entirely or have some sort of "clean up" script that keeps objects from being present on the ground too long.

     

     

    Ok, well, wayyyy easier to do than initially expected:

     

    player addEventHandler [ "InventoryClosed",
    	{
    		params ["_unit","_container"];
    		deleteVehicle _container;
    	}
    ];

     

    • Like 2

  10. 1 minute ago, Reid236 said:

    Will you be adding functionality to the new gear so we can use it with your mod?

    Well, if you've used my mod, you should know that the functionality is already there (at least for the masks/uniforms/etc). Just add the classnames! Now, I may add some "auto include" options to the gear/mask modules to make it easier, less hunting for classnames. I will surely have to take into consideration the new backpacks, but I will avoid making any specific plans until the DLC is released. But of course one could speculate the possibility of air tank capacity and use over time effects with supplemental refill handling.....but one could only speculate :teeth:.

    • Like 1
    • Haha 1

  11. 1 minute ago, Reid236 said:

    The cbrn gear in the new dlc will be cosmetic only there won't be any functionality to the gear at all

    Well, sure the gear won't have much to do aside from being there. But I read about a detector of sorts (like reading EM fields or something) too. I'm just joking anyhow :tounge2:. But it will certainly be nice to have some vanilla options for everyone on that front.


  12. UPDATE: v0.5.5 is LIVE

    OP mirror links updated.

     

    My brain remember that the wonderful TADST tool existed so I was able to figure out some stuff that was going on dedicated MP.....which was honestly way too much. Hopefully now, even though I obviously suck at my one job, I was able to hash out most of the issues that have been reported (along with a few others that I found along the way).

     

    I apologize for my lack of organization, especially when it comes to thoroughly testing shit before going public with it (really bad habit).

     

    Again, I especially urge those of you that play MP (both player-hosted and dedicated server) to report back with any problems because now with TADST I may be able to replicate instead of just guessing...

     

    Changelog:

    Spoiler

    -PUBLIC v0.5.5:

        Additions:
            -Added setting to Debug module to show/hide network related debug messages
        Changes/Fixes:
            -Changed Zeus UI to display all defaults when placing modules down consecutively
            -Changed (simplified) the way clients are updated on key variables
            -Changed from getPos to getPosWorld to update markers after using updateInfo fncs
            -Changed declaration namespace of some preInit variables for client/server
            -Fixed a number of before unseen logic or script errors causing any number of undesired results in dedicated MP
            -Fixed issue when player respawned and would not be affected by areas until adding then removing gear
            -Fixed issue where linked area on an object was not deleted after destroyed
        Removals:
            -Temporary (possible permanent) removal of some suspending functions that may have caused long mission load times

     

     

     

    Random aside: Seems like BI is coming around and supplying some vanilla gear and stuff here soon! Maybe I'll be useless after Contact is released :down:.

    • Like 2

  13. 4 hours ago, Dedmen said:
    14 hours ago, CuddleTank001 said:

    i tried this script in multiplayer and it didn't work

    What part didn't work? The action didn't show up? Do your other actions show up? Or did the action show up but the code didn't execute when you used the action?

     

    The problem is that we don't know what the problem is unless you are more specific as to what doesn't work. The actions are not showing up at all; the actions are present but do nothing; these specific actions work without issue but these others do not; etc.

     

    Getting things to work through the use of the debug console doesn't necessary mean anything since you can execute that code in whatever way is needed. Did you execute globally or locally? Did you only do the one action that we've been using in this thread consistently? Did you just copy and paste the entire onPlayerRespawn.sqf in there and click execute?

     

    This is all critical information on what we need to help. When we don't have specifics we tend to make grandiose assumptions as to where, how and why certain stuff is executed (based on our experiences). While I'm sure we can make an educated guess as to what could be happening, the fact is that is that is wildly inefficient and just keeps all of us moving in circles. And for some of us, myself included, we have other projects, work, college, etc. that keep us from dedicating a lot of time to walking people step-by-step through the debugging process for every single hiccup. I love to help (obviously) but help us help you. Because I'm sure if we came in here just to post "Oh, well I couldn't get your code to work either, sucks to suck 😢" it wouldn't be of much help.

     

    Sorry if that comes off as harsh but to put it simply; give us specifics for every issue you encounter (the who, what, when, where, why, and how).

    • Like 2

  14. 41 minutes ago, CuddleTank001 said:

    condition parsing explanations

    Just to clarify, these parsing concepts apply in every usage of strings, not just conditions. I was just keeping my explanation focused specifically on this example.

     

    hint "My hint that still shows a ""string""";
    //displays as: My hint that still shows a "string"

     

    47 minutes ago, CuddleTank001 said:

    but seriously thanks for the help

    That's what the forums are for. I for one just like to tackle issues with people even if I'm not entirely sure how to approach it, especially in the cases where better/more experienced coders (cough, Dedmen :respekt:) come in and poke holes in my stuff, helps me learn too. Even though half the time I screw up is either because I'm sleep deprived or post without testing :hammer:


  15. 7 minutes ago, CuddleTank001 said:

    and arent

    
    "toLower (typeOf currentWeapon player) isEqualTo "hgun_p07_f""

    and

    
    "toLower (typeOf currentWeapon player) isEqualTo 'hgun_p07_f'"

    the same?
    the only difference that i can spot is that one of them is more tidier than the other

     

    Sorry missed that you were still doing "typeOf currentWeapon player", see @sarogahtyp post above this.

     

    And to answer this simply, no they are not the same, because the condition is evaluated as a string anything within two ". So in your original condition, it is evaluting only: "toLower (typeOf currentWeapon player) isEqualTo "

     

    So it will throw an error no only because the condition itself is incomplete code (and it expects the closing addAction bracket) but also because there is incomplete code outside of that condition string, e.g. the rest of the condition itself.

    • Like 1

  16. 14 minutes ago, Dedmen said:

    Way more expensive than it needs to be

    https://community.bistudio.com/wiki/find

    Just use find to check if string contains a space. No need to split.

    Indeed. General question though, if I did want to filter for more than just spaces (e.g. dashes and underscores) I would assume iterating with each special character using find would still be better than counting the return of splitString? Not at my computer to run the numbers atm.


  17. From the wiki arrayIntersects:

    Quote

    Intersects array1 with array2 returning array of unique common elements.

     

    So if they don’t share an element the returned value should be []. I did test this before posting.

     

    I avoided making a number of the assumptions you’ve made in your code simply because OP never really specified the intent of the action, only that it’s available when the player has a certain magazine (which can be a type that isn’t for the weapon the player carries, think wasteland or survival modes where you pick up what you can) or uniform. I concede on otherwise inefficient code though, forgot findIf even existed :hehe:.


  18. Going back to OP about mags and uniform:

     

    fnc_hasTheStuff = {	
    	params [
    		["_unit",objNull,[objNull]],
    		["_magClasses",[],[[]]],
    		["_uniClasses",[],[[]]]
    	];
    	
    	private _uniClass = toLower uniform _unit;
    	private _magArr = magazines _unit;
    	_magArr pushBackUnique currentMagazine _unit;
    	{
    		_x = _x apply {toLower _x};
    	} forEach [_magClasses,_uniClasses,_magArr];
    	private _hasMag = count (_magArr arrayIntersect _magClasses) > 0;
    	private _hasUni = _uniClasses find _uniClass > -1;
    	_hasMag || _hasUni;
    };
    
    player addAction [
    	"My Action",
    	{/*do stuff*/},
    	[],
    	-1,
    	false,
    	true,
    	"",
    	"[_originalTarget,['myMagClass1','myMagClass2'],['myUniformClass1']] call fnc_hasTheStuff"
    ];

    Of course replace info where necessary (in the addAction portion), fnc_hasTheStuff is called with the parameters of a unit (namely the player), an array of magazine classnames and an array of uniform classnames, if the player has either the right magazine or the right uniform then the action is shown. 

    • Like 1
×