Jump to content
Shifty65

Having trouble with my first script

Recommended Posts

Hey Guys I'm trying to make my own script for our server.
I always build my missions as far as possible in the editor, so without a lot of scripting.
But i really want to start building my own scripts.

I know the basics but to build one on my own it's hard to do.
This script that I'm trying to make is for Mp, it works perfect in SP.
This is what i want to make:

 

Players have to clear an office and find a key.
With that key the can open a door to a tunnel.
So if they go first to the tunnel entrance and wanna open the door it says (addAction)"Find Keys Nearby, to free POW's."

Then they have to go and find the keys.
When they find the key it says (addAction)"You got the Keys. Now open the door."

Then back to the door it says (addAction)"Door is open, Good job!!" and it opens the door (door1 hideObject true;).
It works perfect in SP and for the Player who found the keys the door opens, but for the other players the door stayed closed.

 

I hope somebody can help me with my first script.
I looked at a lot of tutorials for basic scripting but to write your first script is very difficult.
So i really hope someone can help me.

 

These are my scripts:

2 addActions
key1_pickup.sqf
openJailDoor.sqf

//-------------------------------------------

I have a picture of a key called "key1"
and a door called "door1"

 

//initPlayerLocal.sqf
    key1 addAction ["<t color='#f5f5f7'>Take the Key</t>", "scripts\key1_pickup.sqf", [], 7, true, true, "", "isNil 'key1taken' && player distance key1 < 3"];
    door1 addAction ["<t color='#f5f5f7'>Door Locked</t>", "scripts\openJailDoor.sqf", [], 7, true, true, "", "isNil 'door1taken' && player distance door1 < 3"];

 

//-------------------------------------------

//key1_pickup.sqf

if (isNull player) exitWith {};
if (!isNil "key1taken") exitWith {};

    removeAllActions key1;

    _p = switch (toUpper (stance player)) do
    {
        case "STAND": {"erc"};
        case "CROUCH": {"knl"};
        case "PRONE": {"pne"};
    };

    _w = switch (toLower (currentWeapon player)) do
    {
        case (toLower (primaryWeapon player)): {"rfl"};
        case (toLower (handgunWeapon player)): {"pst"};
        default {"non"};
    };

    _anim = format ["AmovP%1MstpSrasW%2Dnon_AinvP%1MstpSrasW%2Dnon_Putdown", _p, _w];
    player playMove _anim;
    
sleep 1;

    deleteVehicle key1;

    key1taken = true;
    publicVariableServer "key1taken";

sleep 1;

        _output =
        "<t color='#ffffff' size='1' font='PuristaBold' shadow='1'>You got the Keys."+        
        "<t color='#ffffff' size='0.8' font='PuristaLight' shadow='1'><br/>Now open up the door.</t>";
        [[_output, 0, 0.5, 8, 1],"BIS_fnc_dynamicText"] call BIS_fnc_MP;    
    
//-------------------------------------------

//openJailDoor.sqf

if (isNull player) exitWith {};
if (!isNil "key1taken") then
    {
        door1 hideObject true;

sleep 1;
        
            _output =
            "<t color='#ffffff' size='1' font='PuristaBold' shadow='1'>Door is open,"+        
            "<t color='#ffffff' size='0.8' font='PuristaLight' shadow='1'><br/>Good job!!</t>";
            [[_output, 0, 0.5, 8, 1],"BIS_fnc_dynamicText"] call BIS_fnc_MP;
    }
else
    {
            _output =
            "<t color='#ffffff' size='1' font='PuristaBold' shadow='1'>Find Keys Nearby,"+        
            "<t color='#ffffff' size='0.8' font='PuristaLight' shadow='1'><br/>To free POW's.</t>";
            [[_output, 0, 0.5, 8, 1],"BIS_fnc_dynamicText"] call BIS_fnc_MP;
    };

Share this post


Link to post
Share on other sites

Welcome to the forum.

Scripting for MP is harder because all objects/players/groups... are not located on the same PC and commands and functions require attention to these localities to work.

locality

MP scripting

So, don't use any more bis_fnc_MP, use remoteExec

A "picture of a key" doesn't make sense as is. I guess you have an object and it's a picture/file you placed in your scenario in editor.

If you run an action by addAction, the code is local to the caller (player) It's OK for your anim playMove and deleteVehicle are fine also in this context.

Now for your openJailDoor.sqf:

hideObject is arguments_global.gifeffects_local.gif So ,the effect will stay local to the caller. you need to remoteExec it everywhere,  or use the hideObjectGlobal command Exec_Server.gif remoteExec from server (better in this case).

[door1,true] remoteExec ["hideObjectGlobal",2];

Btw, could you tell me what is your door and how this could work? I guess your door is an object on its own, not a part (selection) of building.

 

Share this post


Link to post
Share on other sites

I made a movie of it so you can see what my idea is.

https://youtu.be/dqyZPXixlDA

 

The door are 2 planks turned over.

The key is a picture.paa of a jail-key on a noticeboard with 1 noticeboard behind (only a nail) and those 2 noticeboards are hide/unhide.

  • Like 1

Share this post


Link to post
Share on other sites

@pierremgi

Thank you so much for your help pierremgi, it works perfect.

 

  • Like 1

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

×