vissarion1917 0 Posted March 14, 2022 Hi everyone! I am trying to script a mission so if the player spots a specific enemy, a hint appears. I am trying to implement the "knowsAbout" command and it doesn't work. I don't know what am I doing wrong. I have implemented the following code in a init.sqf file _enemyteam=createGroup east; //here I create the enemy group (as long as the bohemia interactive forum says it must be a group) "O_Soldier_F" createUnit [getMarkerPos "marker3", _enemyteam]; //here I spawn the enemy unit if (player knowsAbout _enemyteam) then {hint "Enemy spotted"}; When I run the mission, appears tthe following error in the 3rd line of code: Error knowsAbout: group type, object expected I have also tried the following code (which is not exactly what I want but...) _enemyteam=createGroup east; "O_Soldier_F" createUnit [getMarkerPos "marker3", _enemyteam]; if (player knowsAbout east) then {hint "Enemy spotted"}; And the error I get is: Error knowsAbout: side type, object expected How can I solve this? What am I doing wrong? Thank you a lot Share this post Link to post Share on other sites
froggyluv 2130 Posted March 15, 2022 knowsAbout is a numerical value between 0-4. Much magic surround this. _knowledge = player knowsAbout _target; _knowledge could return 1.5 for example 10 hours ago, vissarion1917 said: if (player knowsAbout east) then {hint "Enemy spotted"}; So if you wanted to fire your script at the knowsAbout 1.5 value if ( _knowledge) then {hint “enemy spotted”}; typed from phone so excuse 1 Share this post Link to post Share on other sites
soldierXXXX 79 Posted March 15, 2022 Hi. I spotted several mistakes you made. knowsAbout needs object/unit to work. With alternative syntax createUnit you can´t return object when you create it. If condition won´t work if player doesn´t know about unit immediately. So to make this work you do it like this. if (!canSuspend) exitWith {hint "script is not executed in scheduled environment and thus will not work properly"};//this line is to check script environment-execute script in init.sqf, execVM or spawn private _enemyteam=createGroup east; //created enemy group _enemyteam deleteGroupWhenEmpty TRUE;//Marks given group for auto-deletion when group is empty private _specificUnit = _enemyteam createUnit ["O_Soldier_F", getMarkerPos "marker3", [], 0, "NONE"];//use this syntax instead because it returns unit and you can work with it further waitUntil {sleep 1;(player knowsAbout _specificUnit) > 0};//you need to use waitUntil because player doesn´t know about unit immediately when it spawns hint "Enemy spotted"; Share this post Link to post Share on other sites
vissarion1917 0 Posted March 15, 2022 8 hours ago, soldierXXXX said: Hi. I spotted several mistakes you made. knowsAbout needs object/unit to work. With alternative syntax createUnit you can´t return object when you create it. If condition won´t work if player doesn´t know about unit immediately. So to make this work you do it like this. if (!canSuspend) exitWith {hint "script is not executed in scheduled environment and thus will not work properly"};//this line is to check script environment-execute script in init.sqf, execVM or spawn private _enemyteam=createGroup east; //created enemy group _enemyteam deleteGroupWhenEmpty TRUE;//Marks given group for auto-deletion when group is empty private _specificUnit = _enemyteam createUnit ["O_Soldier_F", getMarkerPos "marker3", [], 0, "NONE"];//use this syntax instead because it returns unit and you can work with it further waitUntil {sleep 1;(player knowsAbout _specificUnit) > 0};//you need to use waitUntil because player doesn´t know about unit immediately when it spawns hint "Enemy spotted"; Thank you a lot! It worked Just a pair of doubts. Why is preferible to create the enemy group as you did instead of my method? Why is desirable putting "private" i front of creating the enemy group? And also, I am not an expert on scripting as you can see and I do not know if I have understanded correctly the "waituntil" command. Correct me if I am wrong but I think that what that command does is that checks every 1 seconds (sleep 1) if the conditions (player knowsAbout blabla) has been completed to run the following commands (hint "enemyspotted"). Right? Thank you a lot! Share this post Link to post Share on other sites
soldierXXXX 79 Posted March 15, 2022 To answer your questions. Creating unit this way returns value-object so it's preferable if you have further plans with the unit itself. Your method is good but doesn't return anything upon creation and knowsAbout depends on unit/object which we need to supply. Using private is more like force of habit for me. It protects local variables from being overwritten. It's not really necessary for this script. Yes absolutely right. waitUntil is there to stop the script until desired condition is met. Also sleep command is better to use for codes which are not needed to be time perfect. Otherwise without it it would check every frame. To use sleep in it is better for script optimization. After the condition is met script continues. I'm glad i could help :-). Share this post Link to post Share on other sites