Jump to content
Sign in to follow this  
vapour

A scripting challenge

Recommended Posts

Hi

Is anyone up to a bit of a scripting challenge?

This has got me beat, and I suspect it may have to involve public event handlers.

Public event handlers confuse the crap out of me, no matter how much I try to read about them.

In this PBO: http://www.mediafire.com/?b9n7e9xjc1tjbz6 I have five terrorists that will get shot.

Once someone approaches the dead body, they can use the action menu to identify the terrorist that has been shot. On identification a hint appears naming the dead terrorist and the killer. In the task list the terrorist gets marked off as killed.

So what is happening is that an 'MPEventHandler' sets off a script when the terrorist is killed.

This is the MPEventHandler:

this addMPEventHandler [""mpkilled"", {T1K = _this select 1; nul=[]exec ""T1Action.sqf""}]

This is the script that gets run:

if (!isServer) exitWith {};
_a2=T1 addaction ["<t color = '#F7FE2E'>Identify body</t>", "T1.sqf"];

The script does an 'AddAction' to the dead body so that "Identify body" turns up in the action menu when the body is approached.

Running the action sets off a second script:

if (!isServer) exitWith {};
objT1 setTaskState "SUCCEEDED";
hint format["Boris Zaitsev successfully eliminated by %1",T1K];
T1K addRating 1000;
T1 removeAction 0;

Works great in testing with one player, but as soon as it's served up to more players, it all turns to custard.

"Identify body" appears in the action menu multiple times.

Only the person who executes the action sees the hint and gets the green task success.

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites

Multiple errors...

First of all, you execute a sqf script with exec instead of execVM.

Second, "if (!isServer) exitWith {};" means it will only run on the server thus it will not add the action on a client

(currently not triggered as you use exec, use !isDedicated for clients).

Third, hint is a local command and will only show a text where it was executed so you have to use another

method to show the hint on other clients too (and remove/replace !isServer exitWith there too).

Not much of a challenge. Try to learn and understand MP locality. And be aware that a host is both, client and server, contrary to a dedicated server which is always the server only.

Xeno

Edited by Xeno

Share this post


Link to post
Share on other sites

after you have adjusted to the specific details Xeno mentioned, do this to make it work for all players.

just use publicVariable and MP framwork:

objT1 setTaskState "SUCCEEDED";
publicVariable "objT1";  // this will give all clients the updated taskstate.
[nil,nil,rHINT,"Enjoy the game."] call RE;  // this will show a hint on every client.

Share this post


Link to post
Share on other sites

Thanks heaps for your help guys, but everything for me was a complete failure.

Xeno, where you said "First of all, you execute a sqf script with exec instead of execVM" - I couldn't see where I was executing a script using execVM - All my scripts are executed using exec like you said.

Using !Dedicated, things haven't changed at all. The addAction still comes up multiple times, and only the executor of the addAction sees the hints, successful objectives etc . . .

Demonized, I'm afraid that the rHint thing stuffs up my formating of the hint and wont let me include adding in the killers name.

This is all obviously above me so I'll try and work out some other way of doing this.

Share this post


Link to post
Share on other sites

.sqf need to be executed by using

nul = execvm "myscriptname.sqf"

The way xeno wrote it he meant you have used exec, where as you need to use execvm.

Not sure wether you use the nul = with MP though :)

Share this post


Link to post
Share on other sites
Xeno, where you said "First of all, you execute a sqf script with exec instead of execVM" - I couldn't see where I was executing a script using execVM - All my scripts are executed using exec like you said.

Hi.... Xeno made a mistake there.

Execute .sqs with exec and .sqf with execVM. Not the other way around.

---------- Post added at 08:59 PM ---------- Previous post was at 08:58 PM ----------

EDIT: pinched at the post!

Share this post


Link to post
Share on other sites

I think that is what Xeno actually meant, it's just the way he typed it that some can take the wrong way.

I think he was like bullet pointing the first couple of mistakes saying what he had done wrong, not telling him how to do something.

Share this post


Link to post
Share on other sites

Sorry folks, but I am using (with a few exceptions)

[] exec "file.sqf" (f like fox)

all the time and it works without any problems.

Share this post


Link to post
Share on other sites
Sorry folks, but I am using (with a few exceptions)

[] exec "file.sqf" (f like fox)

all the time and it works without any problems.

It probably works if the actual code you have written in the SQF meets SQS specs.

Share this post


Link to post
Share on other sites
That might not be the best idea: http://forums.bistudio.com/showthread.php?t=87387

yeah, second that, it means that the file is not working the same way the sqf file is supposed to.

also they use it this way to combine sqs and sqf syntax wich is horrifying :D

at the least its VERY confusing and troublesome for a new scripter not knowing the limitations of this way of exec a sqf file, wich just further makes scripting even harder to understand.

Share this post


Link to post
Share on other sites

When you execute a sqf script with exec then some things do not work, exitWith to end a script for example (same for sqs exit, it does nothing in sqf scripts).

The sqs enigne is a line interpreter. That's the reason why sqf like script constructs in sqs scripts have to be written in one line (sqf on the other hand is working with scopes, scopes are not bound to one line).

So either you write a sqs script and use exec to run it or you write a sqf script and use execVM to run it. But don't mix things up, as you can see here it ends up in too many problems.

Xeno

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  

×