Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: A scripting challenge

  1. #1

    Question A scripting challenge

    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:
    Code:
    this addMPEventHandler [""mpkilled"", {T1K = _this select 1; nul=[]exec ""T1Action.sqf""}]
    This is the script that gets run:
    Code:
    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:
    Code:
    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.

  2. #2
    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
    Last edited by Xeno; Jul 5 2011 at 10:17.

  3. #3
    Warrant Officer Demonized's Avatar
    Join Date
    Nov 16 2010
    Location
    Back from afk 2013
    Posts
    2,614
    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:
    Code:
    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.
    My scripts:
    Spoiler:

    what to do when posting any kind of code dammit!!

    Any new mission editor or scripter in Arma2 should have read Mr Murrays Editing Guide Deluxe at least once, it still applies for A2 even though it was made for Armed Assault.

  4. #4
    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.

  5. #5
    .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

  6. #6
    Master Gunnery Sergeant twirly's Avatar
    Join Date
    Sep 13 2010
    Location
    Gods Own (NZ)
    Posts
    1,302
    Quote Originally Posted by Vapour View Post
    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!

    "Learn by doing!" - Quoted from a post by Imutep

    OUTERRA - OUTERRA - OUTERRA - OUTERRA - BLOWMIND!

  7. #7

  8. #8
    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.

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

    Code:
    [] exec "file.sqf" (f like fox)
    all the time and it works without any problems.

  10. #10
    Quote Originally Posted by RogueTrooper View Post
    Sorry folks, but I am using (with a few exceptions)

    Code:
    [] exec "file.sqf" (f like fox)
    all the time and it works without any problems.
    That might not be the best idea: http://forums.bistudio.com/showthread.php?t=87387

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •