Some Coding Questions (_this select and other)

kikyou2

Valued Member!
Hi there,

I'm currently working hard to understand as much arma code as possible as I customize my server much and want to reach the fully potencial which is available.

There are some things I don't understand in Scripting with dayz with arma code maybe someone would be kind and explain some things to me :)

Often in Scripts of the server.pbo or the dayz client files there are commands with _this select. I choose an example from the server_playerdied.sqf which is used for the deathmessages and stuff.

Code:
private["_characterID","_minutes","_newObject","_playerID","_key","_playerName","_playerID","_myGroup","_group","_victim", "_killer", "_weapon", "_message", "_distance","_loc_message","_victimName","_killerName","_killerPlayerID"];
//[unit, weapon, muzzle, mode, ammo, magazine, projectile]
_characterID =_this select 0;
_minutes =_this select 1;
_newObject =_this select 2;
_playerID =_this select 3;
_playerName =_this select 4;

So as far as I read about the _this select function it is used to get informations from a special object. But how I know from which object the _this select 0 commands try to get the informations.

Also I read that the command _this select 0; would put the first information in the array of the object into the _characterID variable.

But how can I know or learn which info is stored where? If I look at other scripts there are often _this select commands and I don't know how to detect which info is stored in the object and which number I have to use if I want to have a special information.

Thanks in advance for all users who are willing to help me out! :)

Regards

kikyou2
 
The values obtained from statements like "_this select 0" are taken from the variables that are passed onto the script. For example, if I called a script like this:

_value = [_var1, _var2] call fnc_function;

Inside the script "fnc_function" I would be able to access _var1 and _var2 using _this select 0; and _this select 1; respectively. If I had passed on a third variable, like:

_value = [_var1, _var2, _var3] call fnc_function;

Then _this select 2; would give me _var3 while inside fnc_function.
 
Ah yes I have seen often that some markers starts scripts like this.

But if we stick with the example of the server_playerdied.sqf, there is no call for the script like in your example where I can look for the array of passed variables as I can see from here.

Where I can see which variables are passed to the script?

Here is the full script, maybe that helps

Thank you very much for you quick and helpfull response! ;)

Code:
private["_characterID","_minutes","_newObject","_playerID","_key","_playerName","_playerID","_myGroup","_group","_victim", "_killer", "_weapon", "_message", "_distance","_loc_message","_victimName","_killerName","_killerPlayerID"];
//[unit, weapon, muzzle, mode, ammo, magazine, projectile]
_characterID =_this select 0;
_minutes =_this select 1;
_newObject =_this select 2;
_playerID =_this select 3;
_playerName =_this select 4;
 
_victim removeAllEventHandlers "MPHit";
 
_victim = _this select 2;
_victimName = _victim getVariable["bodyName", "nil"];
 
_killer = _victim getVariable["AttackedBy", "nil"];
_killerName = _victim getVariable["AttackedByName", "nil"];
 
// when a zombie kills a player _killer, _killerName and _weapon will be "nil"
// we can use this to determine a zombie kill and send a customized message for that. right now no killmsg means it was a zombie.
if (_killerName != "nil") then
{
_weapon = _victim getVariable["AttackedByWeapon", "nil"];
_distance = _victim getVariable["AttackedFromDistance", "nil"];
 
if (_victimName == _killerName) then 
{
_message = format["%1 killed himself",_victimName];
_loc_message = format["PKILL: %1 killed himself", _victimName];
}
else 
{
_killerPlayerID = getPlayerUID _killer;
_message = format["%1 was killed by %2 with weapon %3 from %4m",_victimName, _killerName, _weapon, _distance];
_loc_message = format["PKILL: %1 (%5) was killed by %2 (%6) with weapon %3 from %4m", _victimName, _killerName, _weapon, _distance, _playerID, _killerPlayerID];
};
 
diag_log _loc_message;
[nil, nil, rspawn, [_killer, _message], { (_this select 0) globalChat (_this select 1) }] call RE;
//[nil, nil, rHINT, _message] call RE;
 
// Cleanup
_victim setVariable["AttackedBy", "nil", true];
_victim setVariable["AttackedByName", "nil", true];
_victim setVariable["AttackedByWeapon", "nil", true];
_victim setVariable["AttackedFromDistance", "nil", true];
};
 
dayz_disco = dayz_disco - [_playerID];
 
The call for server_playerdied.sqf seems to be in \init\publicEH_server.sqf. I don't really know much more than this, but I think it is what you're looking for.
 
Yes there is a function call, but I think that there the function is a own value which is passed to the "registerServerRpc".

Code:
["dayzDeath",{ (_this select 1) call server_playerDied; }] call registerServerRpc;

So I don't know but it don't seem that there is the array which I'm searching for.

In my head I think its something like the player for which the script is executed (the player who died) is a object where are several informations stored in a array.

So if this is true it should be an array like this for the player (if we stick to my example).

example
Code:
_characterID =_this select 0;[/SIZE]
[SIZE=3]_minutes =_this select 1;[/SIZE]
[SIZE=3]_newObject =_this select 2;[/SIZE]
[SIZE=3]_playerID =_this select 3;[/SIZE]
[SIZE=3]_playerName =_this select 4;

array
Code:
[CharacterID, aTimeValue, anyotherValue, PlayerID, NameofthePlayer]

And for that array I'm searching for that I can understand why _this select 3 is _playerID and not like 5 and that I know which informations I can use from it.

Thanks!
 
Code:
private["_array","_source","_kills","_killsV","_humanity","_wait","_myKills"];
if (deathHandled) exitWith {};
 
deathHandled = true;
//Death
 
_body =        player;
_playerID =    getPlayerUID player;
 
//Send Death Notice
//["dayzDeath",[dayz_characterID,0,_body,_playerID,dayz_playerName]] call callRpcProcedure;
        dayzDeath = [dayz_characterID,0,_body,_playerID,dayz_playerName];
        publicVariable "dayzDeath";
 
_id = [player,20,true,getPosATL player] spawn player_alertZombies;
 
sleep 0.5;
 
player setDamage 1;
0.1 fadeSound 0;
 
player setVariable ["NORRN_unconscious", false, true];
player setVariable ["unconsciousTime", 0, true];
player setVariable ["USEC_isCardiac",false,true];
player setVariable ["medForceUpdate",true,true];
//remove combat timer on death
player setVariable ["startcombattimer", 0, true];
r_player_unconscious = false;
r_player_cardiac = false;
 
_id = player spawn spawn_flies;
 
_humanity =        0;
_wait =        0;
 
_array = _this;
if (count _array > 0) then {
    _source = _array select 0;
    _method = _array select 1;
    if (!isNull _source) then {
        if (_source != player) then {
            _canHitFree =    player getVariable ["freeTarget",false];
            _isBandit = (["Bandit",typeOf player,false] call fnc_inString);
            _myKills =        ((player getVariable ["humanKills",0]) / 30) * 1000;
            if (!_canHitFree and !_isBandit) then {
                //Process Morality Hit
                _humanity = -(2000 - _myKills);
                _kills =        _source getVariable ["humanKills",0];
                _source setVariable ["humanKills",(_kills + 1),true];
                _wait = 300;
            } else {
                //Process Morality Hit
                //_humanity = _myKills * 100;
                _killsV =        _source getVariable ["banditKills",0];
                _source setVariable ["banditKills",(_killsV + 1),true];
                _wait = 0;
            };
            if (_humanity < 0) then {
                _wait = 0;
            };
            if (!_canHitFree and !_isBandit) then {
                //["dayzHumanity",[_source,_humanity,_wait]] call broadcastRpcCallAll;
                dayzHumanity = [_source,_humanity,_wait];
                publicVariable "dayzHumanity";
            };
        };
    };
    _body setVariable ["deathType",_method,true];
};
 
terminate dayz_musicH;
terminate dayz_lootCheck;
terminate dayz_slowCheck;
terminate dayz_animalCheck;
terminate dayz_monitor1;
terminate dayz_medicalH;
terminate dayz_gui;
terminate dayz_zedCheck;
terminate dayz_locationCheck;
terminate dayz_combatCheck;
terminate dayz_spawnCheck;
 
//Reset (just in case)
//deleteVehicle dayz_playerTrigger;
disableUserInput false;
r_player_dead = true;
 
"dynamicBlur" ppEffectEnable true;"dynamicBlur" ppEffectAdjust [4]; "dynamicBlur" ppEffectCommit 0.2;
 
"colorCorrections" ppEffectEnable true;
"colorCorrections" ppEffectAdjust [1, 1, 0, [1, 1, 1, 0.0], [1, 1, 1, 0.01],  [1, 1, 1, 0.0]];
"colorCorrections" ppEffectCommit 1;
 
//Player is Dead!
3 fadeSound 0;
0 cutText ["", "BLACK",10];
dayz_DeathActioned = true;
sleep 1;
 
TitleText[localize "str_player_12","PLAIN DOWN",5];
 
dayz_originalPlayer enableSimulation true;
 
addSwitchableUnit dayz_originalPlayer;
setPlayable dayz_originalPlayer;
selectPlayer dayz_originalPlayer;
 
_myGroup = group _body;
[_body] joinSilent dayz_firstGroup;
deleteGroup _myGroup;
 
3 cutRsc ["default", "PLAIN",3];
4 cutRsc ["default", "PLAIN",3];
 
if (count _array > 0) then {
    _body setVariable ["deathType",_method,true];
};
 
_body setVariable["combattimeout", 0, true];
 
//["dayzFlies",player] call broadcastRpcCallAll;
sleep 2;
 
1 cutRsc ["DeathScreen","BLACK OUT",3];
 
 
playMusic "dayz_track_death_1";
 
"dynamicBlur" ppEffectAdjust [0]; "dynamicBlur" ppEffectCommit 5;
"colorCorrections" ppEffectAdjust [1, 1, 0, [1, 1, 1, 0.0], [1, 1, 1, 1],  [1, 1, 1, 1]];"colorCorrections" ppEffectCommit 5;

from player_died.sqf

notice

Code:
        dayzDeath = [dayz_characterID,0,_body,_playerID,dayz_playerName];
        publicVariable "dayzDeath";
 
Ah you finally found the key that it makes sense for me @Hangender!

Thank you very much

I didn't thought about looking into the client files for a call so now it makes sense.

For the special thing "player" is there any chance to get all values which are inside it listed?

Or can I only call things from it with http://community.bistudio.com/wiki/getVariable? :)
 
player is just a reference to the unit (type object) that the client is controlling. There is really nothing special about player at all and yes you can use getvariable to find out values but there isn't really a need as most of the stuff is just medical stats that you can find out by looking at database
 
K thx for your help,

I got some more questions

Code:
_ownerID = _obj getVariable ["characterID","0"];

In this case the variable is passed from a local array isn't it? Or am I wrong and this is passed from the database?

If its from a local array how the information getting into the array after a restart.

I'm asking this cause I'm trying to replace in some parts of code that the PlayerUID is used instead of the PlayerID.

--------------------------

Also I have another question about the private [] array

For example:

Code:
private["_func_ownerRemove","_qtyS","_qtyW","_qtyL","_qtyM","_qtyG","_qtyT","_removable","_eTool","_result","_building","_dialog","_classname","_requirements","_objectID","_objectUID","_obj","_cnt","_id","_tblProb","_locationPlayer","_randNum2","_smallWloop","_medWloop","_longWloop","_wait","_longWait","_medWait","_highP","_medP","_lowP","_failRemove","_canRemove","_randNum","_text","_dir","_pos","_isWater","_inVehicle","_onLadder","_hasToolbox","_canDo","_hasEtool"];

For what is this used and why are there alwys stored all used variables of the code in it? Would there be problems if a variable isn't listed there?

--------------------------

There is just one thing left. Maybe someone knows where is stated that the Server writes the CharacterID to the Database?

Thank you very much for your help!
 
For the first question, that line of code takes the value of the variable "characterID" that has been stored inside the object named _obj, and assigns this value to the variable _ownerID. The "0" after "characterID" is the default value to pass into _ownerID if "characterID" hasn't been assigned a value. You can only use getVariable to retrieve a value that has been previously set using setVariable. The BI wiki is incredibly useful in explaining setVariable/getVariable.

For the second question, the private[]; array marks the names of the variables contained within as "local" variables. These variables will only be accessible by the current script. If you want to pass on a local variable (example: _variable) to another script, you'll have you pass it on like [_variable] execVM "script.sqf". If you don't mark a variable as local, you run the risk of having it accessible by an outer script (one that calls the current script) or an inner script (one that the current script calls).
 
Back
Top