Sign in to follow this  
Followers 0
MudBone

Better snow script- advice needed

6 posts in this topic

Posted (edited)

I have a great snow script that I like much better than the one built into Namalsk. Its random (comes and goes) and check if you are inside a vehicle or building. I've tested it on Namalsk by creating a local mission with an init file. Works fine. When I add it to my Exile mission .pbo  it doesn't work. I looked through the logs and can't find an error relating to it and the script runs locally (I assume) for each player. 

What am I missing here? Is Exile blocking it in some fashion? Does my init need something more specific to call the script properly? Is there another / better way for me to test / debug this?

All credit to IndeedPete for the script
Purpose: Creates light snow fall around unit. Also checks if unit is inside a vehicle or building / under a roof.

My init:

[] execVM "addons\EnigmaRevive\init.sqf";                 // Enigma Revive
[] execVM "snow.sqf";                                     // Snow script
#include "A3XAI_Client\A3XAI_initclient.sqf";            //A3XAI Mod


if (!isDedicated && hasInterface) then {
[] execvm "addons\killMessages\KillMessages.sqf";        // Kill Messages by GR8
};

_GF = [] execVM "addons\fog\fog.sqf";                    //creepy ground fog between certain times

 

The snow script:

Spoiler

 

/*
Name: snowFall
Author: IndeedPete
Purpose: Creates light snow fall around unit. Also checks if unit is inside a vehicle or building / under a roof.
----------
Parameters:
_unit - OBJECT (OPTIONAL): Unit to simulate snow around. - MyUnit - DEFAULT: Player
_condition - CODE (OPTIONAL): While condition that is being checked in addition to (alive _unit). - {SomeVariable > 0} - DEFAULT: {true}

Returns:
Script handle.
*/

private ["_unit", "_condition", "_handle"];
_unit = [_this, 0, player, [ObjNull]] call BIS_fnc_param;
_condition = [_this, 1, {true}, [{}]] call BIS_fnc_param;

_handle = [_unit, _condition] spawn {
    _unit = _this select 0;
    _condition = _this select 1;
    
    if (!isNull(_unit getVariable ["IP_Snow", ObjNull])) exitWith {["Already running!"] call BIS_fnc_error};
    
    while {(alive _unit) && (call _condition)} do {
        _obj = vehicle _unit;
        _pos = if (_obj == _unit) then {
            (getposASL _obj)
        } else {
            _res = getposASL _obj;
            _res set [2, ((_res select 2) + 2)];
            _res
        };

        if (count(lineIntersectsObjs [_pos, [(_pos select 0),(_pos select 1),((_pos select 2) + 20)]]) == 0) then {
            if (isNull(_unit getVariable ["IP_Snow", ObjNull])) then {
                _snow = "#particleSource" createVehicleLocal (getPos _obj);
                _snow setParticleParams [["\A3\data_f\ParticleEffects\Universal\smoke.p3d", 1,0,1,0],"","Billboard",1,10,[0,0,0],[0,0,-10],10,1,0,1,[0.12,0.12],[[1,1,1,0.5],[1,1,1,0.5]],[0,1],0.25,1,"","", _obj];
                _snow setParticleRandom [0, [25, 25, 18], [0, 0, 0], 0, 0.01, [0, 0, 0, 0.1], 0, 0];
                _snow setParticleCircle [0.0, [0, 0, 0]];
                _snow setDropInterval 0.003;
                _unit setVariable ["IP_Snow", _snow];
            };
        } else {
            if (!isNull(_unit getVariable ["IP_Snow", ObjNull])) then {
                deleteVehicle (_unit getVariable "IP_Snow");
                _unit setVariable ["IP_Snow", ObjNull];
            };
        };

        sleep 0.03;
    };
    
    if (!isNull(_unit getVariable ["IP_Snow", ObjNull])) then {
        deleteVehicle (_unit getVariable "IP_Snow");
        _unit setVariable ["IP_Snow", ObjNull];
    };
};

_handle

 

 

 

Edited by MudBone

Share this post


Link to post
Share on other sites

First of all, all scripts that are supposed to be run only on the client should have an hasInterface check around them otherwise the server executes them too.

Second of all, there is no error logging present in the script. That makes it impossible to debug. So have fun with diag_log text "hey this is a log line"

Share this post


Link to post
Share on other sites
Advertisement

Posted (edited)

Afraid I am not much of coder...just a tinkerer trying to run a server for our group. Thanks for the insight though. I learn something new here every day.

 

One thing I dont understand is why it wold work locally in a mission I run in the editor and yet won't run from the mission once downloaded.

Edited by MudBone

Share this post


Link to post
Share on other sites

@MudBone 

Ill give you some debug hints and tips.

First, turn on script errors inside your arma launcher. Go to Parameters > Advanced > Authors and tick the box. This will display client side script errors in game in ugly black boxes. Do this first and run your server again, see if you are receiving anything related to the snow script. These errors will give you line numbers and the error. As an example -

#_var 

undefined variable in expression _var line 16 blah.sqf...

If you are not receiving errors. You still need to know if the script is even executing. So do the following - 

Try executing the script from initPlayerLocal.sqf , as this is a client side script you either need to wrap it in an if (!isDedicated) then { or run it from initPlayerLocal.sqf, currently you are executing this script both on server initialization and whenever a client joins.
 

Alter the snow script to the following , I have put a 30 second sleep timer on the script and displayed a hint, this hint will display at the top right of your screen if the script executes properly on the connecting client. So as a start, if you do not see this hint display, you know something is wrong. 

Assume you get the hint displaying considering you say this works fine on a mission you have made, id suspect no further errors however running script errors will tell you how and where the script might be failing.

 

Hope this helps

 

Spoiler

/*
Name: snowFall
Author: IndeedPete
Purpose: Creates light snow fall around unit. Also checks if unit is inside a vehicle or building / under a roof.
----------
Parameters:
_unit - OBJECT (OPTIONAL): Unit to simulate snow around. - MyUnit - DEFAULT: Player
_condition - CODE (OPTIONAL): While condition that is being checked in addition to (alive _unit). - {SomeVariable > 0} - DEFAULT: {true}

Returns:
Script handle.
*/

sleep 30;

hint "Snow script should be working";

private ["_unit", "_condition", "_handle"];
_unit = [_this, 0, player, [ObjNull]] call BIS_fnc_param;
_condition = [_this, 1, {true}, [{}]] call BIS_fnc_param;

_handle = [_unit, _condition] spawn {
    _unit = _this select 0;
    _condition = _this select 1;
    
    if (!isNull(_unit getVariable ["IP_Snow", ObjNull])) exitWith {["Already running!"] call BIS_fnc_error};
    
    while {(alive _unit) && (call _condition)} do {
        _obj = vehicle _unit;
        _pos = if (_obj == _unit) then {
            (getposASL _obj)
        } else {
            _res = getposASL _obj;
            _res set [2, ((_res select 2) + 2)];
            _res
        };

        if (count(lineIntersectsObjs [_pos, [(_pos select 0),(_pos select 1),((_pos select 2) + 20)]]) == 0) then {
            if (isNull(_unit getVariable ["IP_Snow", ObjNull])) then {
                _snow = "#particleSource" createVehicleLocal (getPos _obj);
                _snow setParticleParams [["\A3\data_f\ParticleEffects\Universal\smoke.p3d", 1,0,1,0],"","Billboard",1,10,[0,0,0],[0,0,-10],10,1,0,1,[0.12,0.12],[[1,1,1,0.5],[1,1,1,0.5]],[0,1],0.25,1,"","", _obj];
                _snow setParticleRandom [0, [25, 25, 18], [0, 0, 0], 0, 0.01, [0, 0, 0, 0.1], 0, 0];
                _snow setParticleCircle [0.0, [0, 0, 0]];
                _snow setDropInterval 0.003;
                _unit setVariable ["IP_Snow", _snow];
            };
        } else {
            if (!isNull(_unit getVariable ["IP_Snow", ObjNull])) then {
                deleteVehicle (_unit getVariable "IP_Snow");
                _unit setVariable ["IP_Snow", ObjNull];
            };
        };

        sleep 0.03;
    };
    
    if (!isNull(_unit getVariable ["IP_Snow", ObjNull])) then {
        deleteVehicle (_unit getVariable "IP_Snow");
        _unit setVariable ["IP_Snow", ObjNull];
    };
};

_handle

 

 

1 person likes this

Share this post


Link to post
Share on other sites
On 5/4/2016 at 10:44 PM, John said:

@MudBone 

Ill give you some debug hints and tips.

First, turn on script errors inside your arma launcher. Go to Parameters > Advanced > Authors and tick the box. This will display client side script errors in game in ugly black boxes. Do this first and run your server again, see if you are receiving anything related to the snow script. These errors will give you line numbers and the error. As an example -

#_var 

undefined variable in expression _var line 16 blah.sqf...

If you are not receiving errors. You still need to know if the script is even executing. So do the following - 

Try executing the script from initPlayerLocal.sqf , as this is a client side script you either need to wrap it in an if (!isDedicated) then { or run it from initPlayerLocal.sqf, currently you are executing this script both on server initialization and whenever a client joins.
 

Alter the snow script to the following , I have put a 30 second sleep timer on the script and displayed a hint, this hint will display at the top right of your screen if the script executes properly on the connecting client. So as a start, if you do not see this hint display, you know something is wrong. 

Assume you get the hint displaying considering you say this works fine on a mission you have made, id suspect no further errors however running script errors will tell you how and where the script might be failing.

 

Hope this helps

 

  Hide contents


/*
Name: snowFall
Author: IndeedPete
Purpose: Creates light snow fall around unit. Also checks if unit is inside a vehicle or building / under a roof.
----------
Parameters:
_unit - OBJECT (OPTIONAL): Unit to simulate snow around. - MyUnit - DEFAULT: Player
_condition - CODE (OPTIONAL): While condition that is being checked in addition to (alive _unit). - {SomeVariable > 0} - DEFAULT: {true}

Returns:
Script handle.
*/

sleep 30;

hint "Snow script should be working";

private ["_unit", "_condition", "_handle"];
_unit = [_this, 0, player, [ObjNull]] call BIS_fnc_param;
_condition = [_this, 1, {true}, [{}]] call BIS_fnc_param;

_handle = [_unit, _condition] spawn {
    _unit = _this select 0;
    _condition = _this select 1;
    
    if (!isNull(_unit getVariable ["IP_Snow", ObjNull])) exitWith {["Already running!"] call BIS_fnc_error};
    
    while {(alive _unit) && (call _condition)} do {
        _obj = vehicle _unit;
        _pos = if (_obj == _unit) then {
            (getposASL _obj)
        } else {
            _res = getposASL _obj;
            _res set [2, ((_res select 2) + 2)];
            _res
        };

        if (count(lineIntersectsObjs [_pos, [(_pos select 0),(_pos select 1),((_pos select 2) + 20)]]) == 0) then {
            if (isNull(_unit getVariable ["IP_Snow", ObjNull])) then {
                _snow = "#particleSource" createVehicleLocal (getPos _obj);
                _snow setParticleParams [["\A3\data_f\ParticleEffects\Universal\smoke.p3d", 1,0,1,0],"","Billboard",1,10,[0,0,0],[0,0,-10],10,1,0,1,[0.12,0.12],[[1,1,1,0.5],[1,1,1,0.5]],[0,1],0.25,1,"","", _obj];
                _snow setParticleRandom [0, [25, 25, 18], [0, 0, 0], 0, 0.01, [0, 0, 0, 0.1], 0, 0];
                _snow setParticleCircle [0.0, [0, 0, 0]];
                _snow setDropInterval 0.003;
                _unit setVariable ["IP_Snow", _snow];
            };
        } else {
            if (!isNull(_unit getVariable ["IP_Snow", ObjNull])) then {
                deleteVehicle (_unit getVariable "IP_Snow");
                _unit setVariable ["IP_Snow", ObjNull];
            };
        };

        sleep 0.03;
    };
    
    if (!isNull(_unit getVariable ["IP_Snow", ObjNull])) then {
        deleteVehicle (_unit getVariable "IP_Snow");
        _unit setVariable ["IP_Snow", ObjNull];
    };
};

_handle

 

 

 

 

Following your instructions I see the following error:

18:09:47   Error Undefined variable in expression: _this
18:09:47 File mpmissions\__CUR_MP.Namalsk\addons\letitsnow\snow.sqf, line 19

 

Line 19 is:

_unit = [_this, 0, player, [ObjNull]] call BIS_fnc_param;

I do however see the  hint you included.

Share this post


Link to post
Share on other sites
Spoiler

/*
Name: snowFall
Author: IndeedPete
Purpose: Creates light snow fall around unit. Also checks if unit is inside a vehicle or building / under a roof.
----------
Parameters:
_unit - OBJECT (OPTIONAL): Unit to simulate snow around. - MyUnit - DEFAULT: Player
_condition - CODE (OPTIONAL): While condition that is being checked in addition to (alive _unit). - {SomeVariable > 0} - DEFAULT: {true}

Returns:
Script handle.
*/

sleep 30;

private ["_unit", "_condition", "_handle"];
_unit = player;
_condition = [_this, 1, {true}, [{}]] call BIS_fnc_param;

hint "Snow script should be working";

_handle = [_unit, _condition] spawn {
    _unit = _this select 0;
    _condition = _this select 1;
    
    if (!isNull(_unit getVariable ["IP_Snow", ObjNull])) exitWith {["Already running!"] call BIS_fnc_error};
    
    while {(alive _unit) && (call _condition)} do {
        _obj = vehicle _unit;
        _pos = if (_obj == _unit) then {
            (getposASL _obj)
        } else {
            _res = getposASL _obj;
            _res set [2, ((_res select 2) + 2)];
            _res
        };

        if (count(lineIntersectsObjs [_pos, [(_pos select 0),(_pos select 1),((_pos select 2) + 20)]]) == 0) then {
            if (isNull(_unit getVariable ["IP_Snow", ObjNull])) then {
                _snow = "#particleSource" createVehicleLocal (getPos _obj);
                _snow setParticleParams [["\A3\data_f\ParticleEffects\Universal\smoke.p3d", 1,0,1,0],"","Billboard",1,10,[0,0,0],[0,0,-10],10,1,0,1,[0.12,0.12],[[1,1,1,0.5],[1,1,1,0.5]],[0,1],0.25,1,"","", _obj];
                _snow setParticleRandom [0, [25, 25, 18], [0, 0, 0], 0, 0.01, [0, 0, 0, 0.1], 0, 0];
                _snow setParticleCircle [0.0, [0, 0, 0]];
                _snow setDropInterval 0.003;
                _unit setVariable ["IP_Snow", _snow];
            };
        } else {
            if (!isNull(_unit getVariable ["IP_Snow", ObjNull])) then {
                deleteVehicle (_unit getVariable "IP_Snow");
                _unit setVariable ["IP_Snow", ObjNull];
            };
        };

        sleep 0.03;
    };
    
    if (!isNull(_unit getVariable ["IP_Snow", ObjNull])) then {
        deleteVehicle (_unit getVariable "IP_Snow");
        _unit setVariable ["IP_Snow", ObjNull];
    };
};

_handle

 

Try replacing snow.sqf with the above. Let me know how you go.

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.