Jump to content
Sign in to follow this  
McArcher

addPublicVariableEventHandler problem

Recommended Posts

My aim is: to run a script on server from client (call server's script from a client's PC)

I set the eventhandler for a variable, change variable, but script doesn't run. Why? Just a simple mission to test:

// init.sqf

enableSaving [false, false];
mcti_RoS = FALSE; // Ð´Ð»Ñ Ð·Ð°Ð¿ÑƒÑка комманд на Ñерваке
publicVariable "mcti_RoS";

if (not isServer) then
{
waitUntil {time>1};
p1 globalChat "Get Ready..."; // p1 is the name of player (in editor)
"mcti_RoS" addPublicVariableEventHandler {[1,2,3] execVM "ros1.sqf";};
mcti_RoS = TRUE;
publicVariable "mcti_RoS";
};

// ros1.sqf

waitUntil {time>2};
p1 globalChat format["%1,%2,%3", _this select 0, _this select 1, _this select 2];

[b]if[/b] (isServer) then  //corrected ;)
{
//////////////////////////////////////////////////////////////////////////////////////////
// очищаем Ñерверную команду                                   //
"mcti_RoS" addPublicVariableEventHandler {};          //
mcti_RoS = FALSE;                                                       //
publicVariable "mcti_RoS";                                            //
/////////////////////////////////////////////////////////////////////////////////////////
p1 globalChat "Starting RoS...";
};

---------- Post added at 17:12 ---------- Previous post was at 17:11 ----------

tested on dedi server, see only "Get Ready..." and no line from script... .rpt at client is empty, no errors in server's .rpt also.

Edited by McArcher

Share this post


Link to post
Share on other sites

omg....))))

---------- Post added at 17:20 ---------- Previous post was at 17:20 ----------

thanx))

---------- Post added at 17:23 ---------- Previous post was at 17:20 ----------

I corrected mistake, but still no text visible from that script...

---------- Post added at 17:24 ---------- Previous post was at 17:23 ----------

server's .rpt:

2010/01/04, 16:21:04 Server: Update of object 2:9 arrived from nonowner

---------- Post added at 17:27 ---------- Previous post was at 17:24 ----------

what is wrong now? :)

---------- Post added at 17:47 ---------- Previous post was at 17:27 ----------

I decided to make it another way... created special object in editor, named is s1 and wrote following:

// init.sqf

enableSaving [false, false];

waitUntil {time>1};

if (not isServer) then
{
waitUntil {time>2};
p1 globalChat "Get Ready..."; // p1 is the name of player (in editor)
s1 setVehicleInit " [1,2,3] execVM ""ros1.sqf""; ";
processInitCommands;
};

// ros1.sqf

waitUntil {time>3};
p1 globalChat format["%1,%2,%3", _this select 0, _this select 1, _this select 2];

if (isServer) then
{
clearVehicleInit s1;
p1 globalChat "Starting RoS...";
};

it says Get ready, then 1,2,3, but no server's "Starting RoS...".

So... the question is, HOW CAN I MAKE SCRIPT RUN ON SERVER (CALL FROM CLIENT) ???

---------- Post added at 17:47 ---------- Previous post was at 17:47 ----------

My aim is: to run a script on server from client (call server's script from a client's PC)

Share this post


Link to post
Share on other sites

It seems there's an error in the second script on the globalChat..

if you write this:

// ros1.sqf

waitUntil {time>2};
//p1 globalChat format["%1,%2,%3", _this select 0, _this select 1, _this select 2];

if (isServer) then  //corrected ;)
{
//////////////////////////////////////////////////////////////////////////////////////////
// очищаем Ñерверную команду                                   //
"mcti_RoS" addPublicVariableEventHandler {};          //
mcti_RoS = FALSE;                                                       //
publicVariable "mcti_RoS";                                            //
/////////////////////////////////////////////////////////////////////////////////////////
p1 globalChat "Starting RoS...";
};

it work for me..

I am referred at the code of your first post ;)

Share this post


Link to post
Share on other sites

goliath86, yes someting with that commented line, but it worked for vehicle Init...

and... still..... "Starting Ros" not written by sever - i.e. the script is NOT executed on server....but I need to execute a script on server by call from client... how can I do this?

---------- Post added at 18:01 ---------- Previous post was at 18:00 ----------

I think I cannot do it on this f**ked OFP engine....its damn too old to make such things.... or am I wrong?

Share this post


Link to post
Share on other sites

in the init.sqf you have declared that only NON SERVER (not isServer) machines fire the code attached to the command addPublicVariableEventhandler and the Server do nothing at the change of the public variable

Share this post


Link to post
Share on other sites

then , this should work?

// init.sqf

enableSaving [false, false];
mcti_RoS = FALSE; // Ð´Ð»Ñ Ð·Ð°Ð¿ÑƒÑка комманд на Ñерваке
publicVariable "mcti_RoS";
"mcti_RoS" addPublicVariableEventHandler {[1,2,3] execVM "ros1.sqf";};

if (not isServer) then
{
waitUntil {time>1};
p1 globalChat "Get Ready..."; // p1 is the name of player (in editor)
mcti_RoS = TRUE;
publicVariable "mcti_RoS";
};

// ros1.sqf

waitUntil {time>2};
//p1 globalChat format["%1,%2,%3", _this select 0, _this select 1, _this select 2];

if (isServer) then  //corrected ;)
{
//////////////////////////////////////////////////////////////////////////////////////////
// очищаем Ñерверную команду                                   //
"mcti_RoS" addPublicVariableEventHandler {};          //
mcti_RoS = FALSE;                                                       //
publicVariable "mcti_RoS";                                            //
/////////////////////////////////////////////////////////////////////////////////////////
p1 globalChat "Starting RoS...";
};

---------- Post added at 18:17 ---------- Previous post was at 18:17 ----------

(addPublicVariableEventHandler is added in Server's and Client's "area")

---------- Post added at 18:20 ---------- Previous post was at 18:17 ----------

it doesn't write "Starting RoS..." either...

Share this post


Link to post
Share on other sites

Try this:

//init.sqf
start_var = 0;

waitUntil{start_var==1};
if (isServer && start_var == 1) then {
            null0 = []execVM "scripts.sqf";
};

Now to start the script make a client to start this code (i.e. with a trigger):

start_var = 1;
publicVariable "start_var";

Edited by goliath86

Share this post


Link to post
Share on other sites

//init.sqf
start_var = 0;

waitUntil{start_var==1};
if (isServer && start_var == 1) then {
            null0 = []execVM "ros1.sqf";
};

if (not isServer) then
{
waitUntil {time>2};
start_var = 1;
publicVariable "start_var";
};

// ros1.sqf

if (isServer) then 
{
p1 globalChat "Starting RoS...";
};

doesn't show my text...

server's .rpt:

2010/01/04, 17:26:58 Server: Update of object 2:10 arrived from nonowner

i think it gets stuck in waitUntil loop. I'll rewrite it...but....well....I'll write something soon.

---------- Post added at 18:37 ---------- Previous post was at 18:31 ----------

//init.sqf

start_var = 0;
publicVariable "start_var";

if (isServer) then
{
waitUntil{start_var==1};
null0 = []execVM "ros1.sqf";
};

if (not isServer) then
{
waitUntil {time>2};
start_var = 1;
publicVariable "start_var";
};

// ros1.sqf

p1 globalChat "pre-Starting RoS...";

if (isServer) then 
{
p1 globalChat "Starting RoS...";
};

2010/01/04, 17:34:44 Server: Update of object 2:10 arrived from nonowner

this also doesn't work.

---------- Post added at 18:41 ---------- Previous post was at 18:37 ----------

but, even if it worked there are number of problems this construction makes:

1. it needs to do "endless" waitUntil loop not in main code! it will get stuck there and no further code will be run. So it needs to be separated in...maybe.. spawn (asyncroniously run), and maybe sleep should be added with check, instead of waitUntil. SUCH CONSTRUCTION LEAD TO HUGE LAGS!

2. I need to run many (!) scripts on server, so I should make several loops for each script??? bullshit... it will make such lags, that no server will be playable. endless loops will "eat" all the CPU time! even with spawn command :(

---------- Post added at 18:48 ---------- Previous post was at 18:41 ----------

// ros1.sqf

p1 globalChat "pre-Starting RoS...";

if (isServer) then 
{
"MASH" createVehicle (position p1);
};

this works. (dunno why globalChat command doesnt work)

Edited by McArcher

Share this post


Link to post
Share on other sites

the 'p1 globalChat "StartingRos"' starts only if the player p1 is the server; if you (p1) join a dedi it doesn't work because you aren't the server.. don't worry about the waituntil command..for now it's only a method to test the possibility to launch a script on a server from a client

Edited by goliath86

Share this post


Link to post
Share on other sites

I have an idea...

I may create an array of strings, and clients will add their wishes ( =))) ), their commands , and server will query this array every...for example 10 seconds (not to make it laggy), and compile commands and throw them from array.....

omg..... it is even worse than soviet do-it-yourself-automobiles.. i hate OFP's engine :D

Share this post


Link to post
Share on other sites

Goal is to run a script once on server, when a client tells it to?

init.sqf

if (isserver) then { execvm "ros1.sqf" };

ros1.sqf

waituntil {!isnil "runscript"};
//do whatever

to tell it to run it, from trigger/script/waypoint or whatever

runscript = true; publicvariable "runscript";

Edited by Shuko

Share this post


Link to post
Share on other sites
Goal is to run a script once on server, when a client tells it to?

init.sqf

if (isserver) then { execvm "ros1.sqf" };

ros1.sqf

waituntil {!isnil "runscript"};
//do whatever

to tell it to run it, from trigger/script/waypoint or whatever

runscript = true; publicvariable "runscript";

ok, thanx, but, what if I what to run my own code, and this code is not the same every next time? this metod will fail I guess.

Goal is to run a script not once, but ANY script and ANY code ANY time :))))

---------- Post added at 19:20 ---------- Previous post was at 18:57 ----------

how can I say something in server's script?

players' units cannot be used, and

[West,"HQ"] SideChat "Hi there";
also doesn't work. No choice again? :) lol, I "love"this game more everyday ;D omg....

---------- Post added at 19:22 ---------- Previous post was at 19:20 ----------

maybe I'll add a civilian grandmother somewhere at the end of the world and she will say someting for us? lol............:smileflower:

Share this post


Link to post
Share on other sites

Chat commands are local, so it doesn't do much good saying anything on server. If you want it for debugging, you can always write to the RPT log with diag_log.

Share this post


Link to post
Share on other sites

lol... in editor....SIDE: Civilian, there are classes like : people, and women.... lol...women are not people? BIS, BIS............ omg....

---------- Post added at 19:26 ---------- Previous post was at 19:24 ----------

Leshiy globalChat "'I am Leshiy :D"; //dbg

Lol, works! :D but not for dedicated ...

Edited by McArcher

Share this post


Link to post
Share on other sites

//sendall.sqf
_init = _this select 0;
_cone = createVehicle ["RoadCone",[0,0,0], [], 0, "FLY"];
_cone setVehicleInit _init; processInitCommands;
deleteVehicle _cone;

If you do ["nul = [] execVM 'serveronly.sqf'"] execVM "sendall.sqf"; and then have the "serveronly.sqf" script do a if (isServer) in the beginning, it should only run on the server.

I might have stuff wrong, but as you can see its fairly few lines so if something is wrong you can probably fix it yourself ;)

You can use it to sideChat on all clients too.

Edited by Murklor

Share this post


Link to post
Share on other sites

i tried setVehicleInit and it didn't run on server. unfortunately, your example doesn't run on server too :( only on clients.

---------- Post added at 19:40 ---------- Previous post was at 19:36 ----------

or maybe I did a mistake.... I'll retest it.

---------- Post added at 19:46 ---------- Previous post was at 19:40 ----------

//sendall.sqf
_init = _this select 0;
_cone = createVehicle ["RoadCone",[0,0,0], [], 0, "FLY"];
_cone setVehicleInit _init; processInitCommands;
deleteVehicle _cone;

If you do ["nul = [] execVM 'serveronly.sqf'"] execVM "sendall.sqf"; and then have the "serveronly.sqf" script do a if (isServer) in the beginning, it should only run on the server.

I might have stuff wrong, but as you can see its fairly few lines so if something is wrong you can probably fix it yourself ;)

You can use it to sideChat on all clients too.

WORKS !!! :yay: AH! I don't even know how to say thank you to you! It works! You have saved my life! :D :yay:

Share this post


Link to post
Share on other sites

if (isserver) then { "runcode" addPublicVariableEventHandler {call compile format ["%1",_this select 1]} };

runcode = "diag_log ""some text"""; publicvariable "runcode";

runcode = "p1 setpos getpos something"; publicvariable "runcode";

Share this post


Link to post
Share on other sites

well, my happiness was too long))

It seems that there's problem now with transfering objects to that function...

["nul = [_obj, _caller] execVM 'mca_assemblyLine_LFRU.sqf'"] execVM "RoS.sqf"; // run on SERVER !

server's dial_log says that both _obj and _caller are any...

any ideas how to give objects to server's function?

Edited by McArcher

Share this post


Link to post
Share on other sites

Well of course they're any: you cant just send a local variable across. Keep in mind that this is a simple string.

You have to format it if you want to send variables: format["nul = [%1,%2] execVM 'mca_assemblyLine_LFRU.sqf'",_obj,_caller]

That is, the entire line would be: [format["nul = [%1,%2] execVM 'mca_assemblyLine_LFRU.sqf'",_obj,_caller]] execVM "RoS.sqf";

You may have to assign the format to variable first though, unsure if it works just slapped in.

Edited by Murklor

Share this post


Link to post
Share on other sites

using formatting to strings it says following both on client and server:

Error in expression <nul = [18140000# 1056663: wf_factory_light_east.p3d,RU_>

Error position: <# 1056663: wf_factory_light_east.p3d,RU_>

Error Пропущено ]

Error in expression <nul = [18140000# 1056663: wf_factory_light_east.p3d,RU_>

Error position: <# 1056663: wf_factory_light_east.p3d,RU_>

Error Пропущено ]

---------- Post added at 20:56 ---------- Previous post was at 20:52 ----------

maybe it wants %1 to be [%1] ??

Share this post


Link to post
Share on other sites

Dont really know what's wrong, but obviously you're getting something out of the variables. Look like unnamed object ids. Are the objects named?

[%1] would send _obj as an array, not an object. Depends on what your script file takes.

Share this post


Link to post
Share on other sites

Variables seem to be shown correctly (some text about my light_factory and my RU_player_1), but why don't they work?.... Named? Player unit is named in editor, warfare building has been created by a script and is standing on the ground....

something with the way to run all this maybe (syntax)?

---------- Post added at 22:06 ---------- Previous post was at 22:05 ----------

and... how can we put a formatted string as a parameter???

---------- Post added at 22:07 ---------- Previous post was at 22:06 ----------

maybe it should be compiled ? or compiled in receiving script?

---------- Post added at 22:07 ---------- Previous post was at 22:07 ----------

something like

call compile format [" [ nul = [%1, %2] execVM 'mca_assemblyLine_LFRU.sqf'] ] execVM ""RoS.sqf""; ", _obj, _caller];
?

---------- Post added at 22:10 ---------- Previous post was at 22:07 ----------

but it gives

Error in expression < [ nul = [145cd400# 1055828: wf_factory_light_e>

Error position: <= [145cd400# 1055828: wf_factory_light_e>

Error Пропущено ]

Error in expression < [ nul = [145cd400# 1055828: wf_factory_light_e>

Error position: <= [145cd400# 1055828: wf_factory_light_e>

Error Пропущено ]

---------- Post added at 22:20 ---------- Previous post was at 22:10 ----------

ah, it's the string for setVehicleInit, then string is ok...

Share this post


Link to post
Share on other sites
Player unit is named in editor, warfare building has been created by a script and is standing on the ground....

You probably need to name your factory.

To test, you can place a named warfare building in the editor and try it with that instead.

You shouldnt need to call compile it.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×