Jump to content
Sign in to follow this  
Guest jacobaby

Cpp exec global scripts?

Recommended Posts

Guest jacobaby

For a certain project I would like to know if anybody has a workaround for the "Init" eventhandler not executing scripts globally? I have a script I would like to run on all clients as if it was being done from a units INIT line in the editor.

Interestingly "incomingmissile" does execute on all clients, but when i tried using a true "dammage" EHandler, again the effects were only seen server side.

Any help would be appreciated, I have been looking at this so long I cant see the woods for the trees.........

Cheers

TJ

Share this post


Link to post
Share on other sites

Any ideas peeps? This is for YOUR benifit at the end of the day...

Share this post


Link to post
Share on other sites
Guest jacobaby

Update.

I would still like to hear about ideas any of you may have, but it seems that the placement of "class eventhandlers" in the CPP affects whether the scripts will work globally when executed by eventhandlers..........

anyone?

TJ

Share this post


Link to post
Share on other sites
Guest BratZ

Unfortunately I mainly work with vehicles and we could use fuel maybe for that.

I am curious tho...if "getin" were used on a soldier?

Wonder if that would activate when the game starts and a player is using it?

We also know that useractions are global,but need some way of auto running them

Share this post


Link to post
Share on other sites

Yes, what I did for the Addon version of CoC Network Services (coming out fairly soon) is from the inited script I toggle the fuel EH by setting fuel to 0... u can set it back also. That will trigger that Fuel EH on every machine on the network,in the fuel script you can do your actual init stuff.

Share this post


Link to post
Share on other sites

I'd lke my manager script to only execute once as it cycles within itself.

I'm curious ...when does the fuel eventhandler change?

When fuel amount changes?

I wondering if you can remove eventhandlers that are added within the cpp?

Then I could have the init change the fuel to activate all the fuel eventhandler client scripts,then remove the fuel eventhandler as its not needed anymore?

Share this post


Link to post
Share on other sites

When fuel changes to 0 or from 0. (from empty or to empty)

If one does

setFuel 0

~2

setFuel 0

it will only trigger once if there was actually some fuel before.

Share this post


Link to post
Share on other sites

And changing the fuel with a "init" eventhandler (server) will activate all clients?

Share this post


Link to post
Share on other sites

There are work arounds. Correct, the 'init' event handler is a server side handle only. However, you may use 'GetIn'. It is a server and client side handler. I use the the 'GetIn' event handler for the F18. If you place your script there, it will execute when a player gets in the vehicle. If you need to run for player only, check to see if the unit is local, ex:"?(Local _Soldier):_isLocal=true". Using a combination of the local check and the 'GetIn' event handler you should get the desired results. Otherwise, you may use the 'GetIn' event handler alone to execute the script on all clients including the server. Hope this helps.

Share this post


Link to post
Share on other sites

Problem with getin tho is that it only executes when someone gets in, this is a problem as even if you start the game in a vehicle, it doesnt execute.

You think changing the fuel from the "init" will change the fuel on all clients?

Suppose I will have to test

Share this post


Link to post
Share on other sites

What do you mean you have to test? I already answered your question above

Quote[/b] ]Yes, what I did for the Addon version of CoC Network Services (coming out fairly soon) is from the inited script I toggle the fuel EH by setting fuel to 0... u can set it back also. That will trigger that Fuel EH on every machine on the network,in the fuel script you can do your actual init stuff.

The reason I am talking about the fuel EH is because it solves this local init problem. smile_o.gif

Share this post


Link to post
Share on other sites

The 'GetIn' eventhandler does get called when you start a game with someone in a vehicle. I have tried it and it works fine for me.

Share this post


Link to post
Share on other sites

LOL Sorry BN880, thats what I was asking, lol

Thankx ,thats the route I am taking then.I just didnt understand that if init only runs on server,if it would change the fuel on all clients.Just got my 2.5 year old a computer so we should be able to lan test this now anyways.Cant get my older son to play OFP hardly anymore.

Pennywise , no sorry getin doesnt.

I have events attached to my canopy (closes and locks canopy when you getin)

And when I start the game flying,guess what...canopy stays open. (my model starts with canopy open btw) No canopy action happens, otherwise it would close

Share this post


Link to post
Share on other sites
smile_o.gif The limitation of that is you need to have a simulation which uses fuel, like car, tank, boat, plane etc. You know what I mean.

Share this post


Link to post
Share on other sites

Isnt a soldier also a vehicle? Cant you add and remove some fuel still to activate?

The problem lies with weapons it seems, no fuel there

Share this post


Link to post
Share on other sites

Fired EH seems to also be global, don't know about weapons in general though. A soldier? Don't think that will work.

Share this post


Link to post
Share on other sites

To my knowledge and many others, everything works on the F18 as is, server and client side. Canopy opens and closes as it should and the wings fold up and down as they should; this also works when you start the plane out flying. BTW, the canopy starts out open and will close if you start out flying. Please do download it and try it out. Its on ofpec for download now. Did you try placing your code in the 'init' event handler? Do you have conditions in the event handler? I believe I may be wrong about the 'init' eventhander. It should get called upon mission start on all clients. However if you use createVehicle the 'init' will only be called on server side. I know I used one of the two events, 'init' or 'getin', to do all the client side work. Try placing the canopy animation in the 'init' and 'getin' eventhandlers. That should allow you to start the mission with the plane flying and canopy closed, and close the canopy when a player gets in. Otherwise, my addon wouldnt work at all. Anyways, glad to hear you got a solution. Goodluck with it all!

Share this post


Link to post
Share on other sites
Did you try placing your code in the 'init' event handler? Do you have conditions in the event handler? I believe I may be wrong about the 'init' eventhander. It should get called upon mission start on all clients. However if you use createVehicle the 'init' will only be called on server side. I know I used one of the two events, 'init' or 'getin', to do all the client side work.

Have a look at the original question (ie the reason for this thread). No init EH's from addons do not start on all clients at mission start, you can use getIn, fuel, fired EH's from your init EH to make a complete Multiplayer initialization.

You must have been using GetIn

Share this post


Link to post
Share on other sites
Quote[/b] ]Have a look at the original question (ie the reason for this thread)

I was responding to Bratty. He claims the 'GetIn' event handler does not get called when you start a plane out flying, which I did get a change to test and it works fine. bn880, Your right, I did use the 'GetIn' EH. I dont have this stuff handy at work to check myself. I tested the 'init' as well and it does not execute on any client, only the server; I wont argue that. As for the original question:

Quote[/b] ]

For a certain project I would like to know if anybody has a workaround for the "Init" eventhandler not executing scripts globally?

I was simply stating that the 'GetIn' event handler could be used as an alternative to the 'Init' event handler. That shouldnt be to far off topic.

Share this post


Link to post
Share on other sites

Still somewhat confused the fact that the "init" eventhandler only runs server side,but yet changing the fuel on the server will change all the clients,how do I determine what commands that are ran from the server will also run on the clients.

Share this post


Link to post
Share on other sites

Heres one way to test the event handlers:

1st save this script to your addon folder:

"eventCalled.sqs"

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_option = _this select 0

~1

?(option==0):player globalChat "Init Called"

?(option==1):player globalChat "GetIn Called"

?(option==2):player globalChat "GetOut Called"

?(option==3):player globalChat "IncomingMissile Called"

?(option==4):player globalChat "fired Called"

Be sure you have the one second wait or else you wont see your messages print out.

2nd place this in your eventhandle class for your addon:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

class eventhandlers

{

 init  = "[0] exec ""eventCalled.sqs""";

 getin = "[1] exec ""eventCalled.sqs""";

 getout= "[2] exec ""eventCalled.sqs""";

 incomingMissile = "[3] exec ""eventCalled.sqs""";

 fired = "[4] exec ""eventCalled.sqs""";

};

I used a similar test a while back when I was learning about the event handlers.  All you have to do is create a sample mission, preferably on desert Island.  Run your sample mission in hosted and dedicated server modes and observe the output.  It will tell you immediately how the behave in different modes.

Share this post


Link to post
Share on other sites
I was responding to Bratty.  He claims the 'GetIn' event handler does not get called when you start a plane out flying, which I did get a change to test and it works fine.  

Hmm.. look at this

getin="(_this select 0) animate [""corcanopy"", 1]";

When I start the game, my canopy is still open,therefore that line did not execute,what test did you run? You must have a script running thats closing the canopy

It works after that,i am saying it doesn't appear to run because the soldier didnt getin is my guess

Share this post


Link to post
Share on other sites

Bratty,

It looks like you are executing the same animation sequence for both cases, when soldier is present and not present.  

Quote[/b] ]

When I start the game, my canopy is still open,therefore that line did not execute,what test did you run?

This is similar to my test if your interested.  Your right about testing for a soldier.  If a soldier is present in the vehicle when mission starts you want to call:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

(_this select 0) animate ["corcanopy", 0]

Otherwise, if a soldier is not present call:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

(_this select 0) animate ["corcanopy", 1]

This is of course assuming that a 0 is close and a 1 is open for your animation sequence.

Test code should look like this:

"canopyControl.sqs"

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_obj = (_this select 0)

_Pilots=crew _obj

_Pilots_count  = count Pilots

?(_Pilots_count  > 0):(_this select 0) animate ["corcanopy", 0]

?(_Pilots_count  == 0):(_this select 0) animate ["corcanopy",1]

Then, in your event class place

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

getin = "[_this select 0] exec ""canopyControl.sqs""";

That should handle the canopy closing when you start in mission with a soldier and open when not present.

Share this post


Link to post
Share on other sites

Back to the original problem... ;)

We want to run a script for every unit in a mission right at the start, regardless of their class, without a trigger.

This counts out the fuel eh because it is dependant on simulation.

Anyway, we have concluded that it is near impossible to do this. If anyone has any ideas, plz share ;D

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  

×