Heeeere's johnny! 69 Posted March 23, 2013 Hey guyz,I'm having a problem where my SQF and programming knowledge reaches its edge. In my dayz_mission.pbo, I'm trying to use a global variable (a string) which I declared and set in the dayz_server.pbo.In the Bohemia Wiki it says that global variables can be used throughout the whole computer, so what I am trying should be possible. After all my trial and error attempts, I just still don't know how.To test if it worked, I setup a hintSilent loop (like a debug monitor) to show me normal text and 2 seconds later another hintSilent with the variable. But only the first hintSilent actually appears. The second one with the variable does not.Can anyone please help me? I'd be very grateful!Have a nice play!Heeeere's Johnny! Share this post Link to post Share on other sites
dayz247 59 Posted March 23, 2013 Hm, correct me if I am wrong.... butdayz_server is run on the server side.dayz_mission is run on the client side.Thus a global variable set in dayz_server would be a global variable on the server.The variables on a server cannot be accessed by the client.Your dayz_mission is only going to be able to read global variable set on the client's computer (ie within dayz_mission).I'm pretty sure thats how it works, I've never tried scripting between _mission and _server (mainly because the above has always been an assumption of mine). Perhaps you need to rethink the structure of what you are trying to do? Share this post Link to post Share on other sites
Heeeere's johnny! 69 Posted March 23, 2013 Hello again,now as I'm thinking about it, this seems to be true - my bad.BUT, if you take a look into the compiles.sqf in your local dayz_code.pbo (or evtl. in your dayz_mission.pbo), you will find a line saying:call compile preprocessFileLineNumbers "\z\addons\dayz_server\init\server_functions.sqf";That means, a file in the dayz_server.pbo is called from within a local pbo (either dayz_code.pbo or dayz_mission.pbo). So, I wonder if I cannot set a reference like that to call a variable from one of the sqf files in there.I want to have that because I've got an anti hack SQF in the server file which logs if anyone is spawning gear or something. But I want it to show a message in global chat or as hintSilent (debug monitor) if it detects somebody, so every player can see it.player globalChat _text;obviously does not work server side, so I need to get the line (for instance as a formatted string) client side somehow. That's why I am trying this whole thing.I just have no clue how. So it would be very cool if anyone could help me. I promise my beans to the solver of this problem or to somebody who can link or connect me to somebody/something who/which can help me!Have a nice play!Heeeere's Johnny! Share this post Link to post Share on other sites
dayz247 59 Posted March 23, 2013 (edited) What about something along the lines of (untested) for displaying as a global message:_message = format["%1 is using cheat: %2", _player, _cheat];[nil, nil, [_player, _message], { (_this select 0) globalChat (_this select1) }] call RE;The above is modified from the "server_playerHit.sqf"Might also try, for displaying as a "hint" .... ie white text at bottom of screen (think "you must be in a forrest and near a tree to cut wood"):_message = format["%1 is using cheat: %2", _player, _cheat];[nil,nil,"per",rHINT,_message] call RE; Edited March 23, 2013 by dayz247 1 Share this post Link to post Share on other sites
AmberHelios 2071 Posted March 24, 2013 I dont think the server files are read by the clients it references the dayz files that are on the server not the client side in the text you put above. hit messages are broadcast serverside have you looked into seeing how they are done Share this post Link to post Share on other sites
Heeeere's johnny! 69 Posted March 26, 2013 (edited) Hmm, somehow I just can't get it to run.The past dayz, I tried to get this "call RE" to give me some text on my screen. But somehow, it just does not want to show it.What I did:I wrote a tiny function which you can take a look at here: (It won't let me upload zip or sqf files to the attachment)http://rapidshare.co...st_function.sqfI executed the function from within the server_functions.sqf in the dayz_server.pbo by adding the following line to the very bottom:["server_functions"] execVM "\z\addons\dayz_server\init\test_functions.sqf";EDIT:The above execVM statement contains a tiny mistake. The name of the SQF file used to be "test_function.sqf" without the ending "s". This is why it did not even start and thereby not show any error whatsoever in the RPT.The parameter "server_functions" is just so I know which function did the execution. ... again, testing purposes ... just don't care.What it does:The function simply loops the output of a text line in global chat and RPT log (for proving the function runs in case it might not show a message on the screen). In the end, it shall be a hintSilent, but for several testing purposes, I chose global here.Now, the test_function.sqf just does not want run. I don't know what I am missing.What am I doing wrong? And where exactly does this line have to be?waitUntil{!(isNil "BIS_MPF_InitDone")};Have a nice play!Heeere's Johnny! Edited March 26, 2013 by Heeeere's Johnny Share this post Link to post Share on other sites
dayz247 59 Posted March 26, 2013 It sends a global message, just without the text you want? Is it posting an empty global message?Also, see no script attached? Share this post Link to post Share on other sites
Heeeere's johnny! 69 Posted March 26, 2013 Sorry, it didn't want to let me upload an SQF or zip file, so I just uploaded it to Rapidshare.The previous post was not correct. Sorry for that too. I don't know how I got that sentence down. But it is not working at all. It does not give me an error and it does not show anything in global.So, take a look at the file and see if you can do anything. Would really appreciate it!Have a nice play!Heeeere's Johnny! Share this post Link to post Share on other sites
dayz247 59 Posted March 26, 2013 (edited) I think your issue is that you do not have anyone set as sending the message.All messages have to be sent by someone, so you are going to need to set someone to broadcast the message.Does it not give you any sort of error in the logs?You also have the functions commented out?Oh, and to post code, just copy paste it, if its not too large. Or attach as a txt file. Edited March 26, 2013 by dayz247 1 Share this post Link to post Share on other sites
Heeeere's johnny! 69 Posted March 26, 2013 There are different versions of the "broadcast" function which are commented out. Plus all message functions are commented out in this version of the SQF, because I tested if it would even show up in the RPT - it doesn't. So I am assuming that something is wrong with the call/execution, because I don't get any errors in the RPT.According tohttps://community.bistudio.com/wiki/REthis message:[nil,nil,rHINT,"Enjoy the game."] call RE;will send a "Hint on all clients currently connected to the MP game".My message is actually similar:[nil,nil,rGLOBALCHAT,"Text: Hallo1"] call RE;I think it doesn't really matter if it's rGLOBALCHAT or rHINT. Share this post Link to post Share on other sites
dayz247 59 Posted March 26, 2013 (edited) If you use global chat, your going to have to have a player in there.So you will need something along the lines of:[_player,nil,rGLOBALCHAT,"Text: Hallo1"] call RE;course you will need to assign _player before hand. Edited March 26, 2013 by dayz247 1 Share this post Link to post Share on other sites
Heeeere's johnny! 69 Posted March 26, 2013 (edited) Ok, I now know what my mistake was. In execVM line in the server_functions.sqf, I accidently called "test_functions" instead of "test_function". So now it is showing me the text I wanted as a hint.So, you helped me with the "RE", so you deserve my beans! :DWhat I now want to do is to give a formatted text to the function which uses information which is usually called client side (mission file).For instance variables being called by "getVariable".Otherwise, except for calling the hint directly by using "RE", I'd like to call a function located in the mission file (let's call it "mission_test.sqf") which I am giving parameters. These parameters should be commands, which are not executed when giving it to the mission_test, but which the mission_test reads and executes itself.In these terms, I am thinking about calling the mission_test with strings as parameters. Can it actually remove the quotations, so those strings get kind of "converted" into actual commands?Have a nice play!Heeeere's Johnny! Edited March 26, 2013 by Heeeere's Johnny Share this post Link to post Share on other sites
dayz247 59 Posted March 27, 2013 (edited) Hm..... Let me see if I got this right in an example:You want to pass information from dayz_mission.pbo/localTest.sqf to dayz_server.pbo/serverTest.sqf ?How about something like this: (localTest.sqf)_letsDoThis = [info1, info2, _someVar] execVM "\z\addons\dayz_server\init\serverTest.sqf";Then: (serverTest.sqf)private["info1", "info2", "var1"];_info1 = this select 0; // variable for first info passed_info2 = this select 1; // variable for second info passed_var1 = this select 2; // data from the variable passeddo something here with information.That should get you going in the right direction. Edited March 27, 2013 by dayz247 Share this post Link to post Share on other sites
Heeeere's johnny! 69 Posted March 27, 2013 Uuuuhm, sorry if I was misunderstood, but I want it the exact other way round.The server file should give parameters to the mission file. These parameters should be functions which should NOT be executed within the server file, BUT in the mission file. For instance, the mission file has a function ("localTest.sqf") which uses the following line:_result = _object getVariable[_variable,0];Can I "create" this line in the server file ("serverTest.sqf") and send it as a parameter to localTest, so localTest executes this very line to get the information? Share this post Link to post Share on other sites
dayz247 59 Posted March 27, 2013 (edited) Hm.I don't quite understand your logic in wanting to pass a command to the player, and have them execute it. It just seems to me that there would be more efficent ways of programming what you are wanting to do. I've never liked crossing the local and server barrier (its there for a reason). It just seems that you could do whatever you are needing to do either completely on the server, or completely on the client. Remember that anything you pass to the client will slow the logging in process (thus we like to do a lot on the server side).Sometimes you have to semi break the barrier.... ie: on client side:if (something) { execute this script on the server }But thats usually as far as you want to go.moral: I would relook exactly how I am going about doing what I am trying to do.But if you want to pass something from the server side to the client side..... simply return the variable at the end of your serverFunctions.sqf/*bunch of code*/_result // end of sqf, no semi colonNow whatever variable you used to call the server with, will be equal to whatever is in _resultLets call that variable _fromServerIf you want to execute a string that was stored in _result (now _fromServer), this might work...._someVar = spawn compile _fromServer;You might be able to combine these (again untested) like so:_fromServer = spawn compile [ [parameters to pass to server] execVM "\path\to\serverFunctions.sqf"];I would try the first part first lol, I'm not entirely sure you can compile a variable.... though in theory it should work (calling a file does nothing more than assign the resulting information passed from the file to a temporary variable).Again, I like the exercise, got me to thinking about sqf in a wierd way. I still think this can be done much more effeciently by doing it on the server, and simply executing (via execVM) from the client (if nothing else that will cut down on network traffic when logging in).edit: Hm, I think I might be explaining this backwards............ Edited March 27, 2013 by dayz247 1 Share this post Link to post Share on other sites
dayz247 59 Posted March 27, 2013 Just let me know if you have further questions or anything.The hardest thing about programming (or scripting in this case) is figuring out the best method for doing something. Once you have the method you are going to use to do something figured out..... its easy to write code. Share this post Link to post Share on other sites
Heeeere's johnny! 69 Posted March 27, 2013 Hey dayz247,well :(, sorry for repeating a lot here, but once more, you gave me an example of code for sending data from the mission to the server file. And once more, I want it the other way round.The server file should give parameters to the mission file.I've seen this thingy without semicolon already, didn't know what it ment though. Now, thanks to your explanation, I know. But that does still not help me since it does not solve the primary problem which is that I could not yet figure out how to send a command as a parameter to the mission file. Example:"result = _object getVariable[_variable,0];" call missionFunction;If I do this, I simply give a string to the function. So can this function somehow "remove" the quotes and actually use the function? Or can it convert a string into an executable or functional term? Or is there ANY OTHER WAY to make the missionFunction getting this line ("result = _object getVariable[_variable,0];") as an actual command line which the missionFunction can execute???That is what I mean... I hope I made it clear enough. :rolleyes:If you need a proper example of what I mean, tell me and I'm gonna make two files (server and mission side) and comment, what actually works and what I want.Have a nice play!Heeeere's Johnny! Share this post Link to post Share on other sites
dayz247 59 Posted March 27, 2013 (edited) dayz_server\test.sqf_x = 1;_xclient/localTest.sqf_letsDoThis = [] execVM "\z\addons\dayz_server\test.sqf";Now _letsDoThis, which is on the client (in dayz_mission.pbo) equals 1 ............................................Further:dayz_server\test.sqf_x = "result = _object getVariable[_variable,0];";_xclient/localTest.sqf_letsDoThis = [] execVM "\z\addons\dayz_server\test.sqf";_letsDoThis Now equals "result = _object getVariable[_variable,0];"So, lets run it (What I was talking about above that in theory should work, but I'm not absolutely sure.....):call compile _letsDoThis; Edited March 27, 2013 by dayz247 1 Share this post Link to post Share on other sites
Heeeere's johnny! 69 Posted March 29, 2013 (edited) Hey dayz247,at first, I want to let you know that I really appreciate your help since you seem to be the only one paying attention to this thread.I tested a lot around, but sadly I just couldn't get it to work. To make sure, the call and stuff is correct, I just took the hull of an already existing SQF, which gives a hint on certain events.So I did the following:I wrote a small "test.sqf" and called it in the mission init.sqf right above the line saying "progressLoadingScreen 1.0;" with the following line:call compile preprocessFileLineNumbers "fixes\test.sqf";This should be correct since did the same with the previously mentioned hint-sending sqf.The test.sqf looks the following:showText ={_i = 0;while {true} do{_i = _i + 1;_text = [] execVM "\z\addons\dayz_server\init\test_function_2.sqf";_textT = call compile _text;hintSilent "Hint:";Sleep 2;hintSilent parseText format ["Hint: %1",_textT];diag_log format ["Test Function loop %1", _i];Sleep 2;};};[] spawn showText;To make sure I see it's working, I made this loop with a simple text hint and 2 sec later a hint with the variable. This is what the "test_function_2.sqf" looks like:_text = "Function is running";_textBut when loading into the game it says"Script z\addons\dayz_server\init\test_function_2.sqf not found"It shows the hintSilent lines though, but when it should show the text from the foreign variable, it shows "any".So... I don't know what's wrong. Don't know any further... Edited March 29, 2013 by Heeeere's Johnny Share this post Link to post Share on other sites
dayz247 59 Posted March 29, 2013 Well.Lets try this from a different approach.Send variable from server to client.text = "some text";_playerID = // the id of the player you want to send a variable to, you can actually replace this with any variable which contains information about a player, for exapmle: _playerObj can be used instead of _playerID provided it points to the player you want to connect to.(owner _playerID) publicVariableClient "text";Send variable from client to servertext = "some text";publicVariableServer "text";Notice that in both cases, "text" does not have an underscore preceeding it.Try that and see if you can use the "text" variable on the client/server after it is passed. 1 Share this post Link to post Share on other sites
Heeeere's johnny! 69 Posted March 31, 2013 (edited) Hey again,sorry for the delay. I have to do some other stuff too so I can't concentrate on DayZ all the time.So, according to:https://community.bi....com/wiki/ownerthis "owner" thing needs to be the other way round:text = "some text";_playerID = owner _someobject; //I don't know what _someobject can be..._playerID publicVariableClient "text";I still don't know though, how I can send this code to every client, because as already stated, I want every player to see individual event based messages... Edited March 31, 2013 by Heeeere's Johnny Share this post Link to post Share on other sites
dayz247 59 Posted March 31, 2013 Hey again,sorry for the delay. I have to do some other stuff too so I can't concentrate on DayZ all the time.So, according to:https://community.bi....com/wiki/ownerthis "owner" thing needs to be the other way round:_playerID = owner _whatever; //I don't know what _whatever can be..._playerID publicVariableClient "VariableName";I still don't know though, how I can send this code to every client, because as already stated, I want every player to see event based messages...I was combining commands.Yes, you can do it the way that you posted ....... _whatever is some object owned by the player. The server has to know which player you are talking about. So if you have some variable that described something owned by a player.... you can useowner _someVARwhich will return the playerID that owns the information stored in that variable. By using:(owner _SomeVar) publicVariableClient "someOtherVar";I am simply cutting out the need to store an additional variable.If you are wanting to send a message to everyone on the server.... why are you trying to send the message to the client, and then have the client post it? For server wide messages post it from the server.We keep going back and forth it seems on exactly what you are trying to do...... your going to have to be more specific. Sending code to each client, and then having each client post a message to that player is extremely inefficient. Simply posting a message from the server to everyone is much better (we talked about that a few posts up).Again, if you could lay out what you are trying to do, we could probably tackle this problem a lot faster, instead of dancing around each individual command. Share this post Link to post Share on other sites
Heeeere's johnny! 69 Posted March 31, 2013 (edited) Wow, do you have an instant SMS info when this thread gets updated? You replied even before I could correct my post a bit, directly after sending it. XDI now see that it's pretty much the same. It was just a bit confusing, because you used _playerID as what I called _someobject.The result after using the "owner" function will be the very "PlayerID", that's why I was a bit confused.So, if you reread my post, you will see the highlighted "individual" somewhere, which should be the answer to your question,why I don't simply send server wide messages. Additional info: "individual messages" means that every player will have different values for the same variables just like every player has a different name. That's why I cannot simply send server wide messages.So, since I had to send this little "unmissunderstanding" post, I will give a specific example of what I want to do. Just give me some minutes ... or hours. Don't know yet. Edited March 31, 2013 by Heeeere's Johnny Share this post Link to post Share on other sites
dayz247 59 Posted March 31, 2013 Ah!Messages sent at the same time, but different for each player. Definitely changes things a bit.Are you wanting to send this message when a player logs in? At a certian time? Or are you wanting to do this when some action is triggered? Share this post Link to post Share on other sites
Heeeere's johnny! 69 Posted March 31, 2013 (edited) No. 1 - Yes, when a player logs in, I want him to be greeted with his name and some other data, which in the mission file whould be called with "player betVariable ..."No. 2 - For instane when a player gets his 100th headshot or kills a player from a certain distance (i.e. 500+ meters), he should get a hintSilent, saying that.Because I don't want, like the known kill messages, that everytime a player gets killed, it shows up. Instead I want those "special" kill messages to appear for the killer (and probably victim) only, saying the details.Is that possible? Edited March 31, 2013 by Heeeere's Johnny Share this post Link to post Share on other sites