Mongoose_84
Dec 19 2006, 10:26
i'm currently working on a way to make respawning in MP work the way i want it to. i've been wondering for quite some time now, why some things won't work, that i thought were done right. now i realised that i can't just write down code the way i'm used to (from programming in C), but have to follow some strange rules (at least strange to me). i want to post what i've done so far and would really appreciate, if someone could explain to me, what i'm doing wrong, why it is wrong and how i do it right. (btw, even if all of the code already worked, it wouldn't do exactly as i want - just want this to work at all, so i can finalize it)
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
_nearest = objNull;
_distNearest = -1;
{
distX = _this distance _x;
if ((alive _x) AND (_distNearest == -1 OR distX < _distNearest)) then
{
_nearest = _x;
_distNearest = distX;
}
} forEach units group _this;
if (_distanceNearest == -1) then
{
{
_this addMagazine '8Rnd_9x18_Makarov'
} forEach [1,2,3,4,5,6,7,8];
_this addWeapon 'Makarov';
} else
{
_newWeapons = weapons _nearest;
_weaponsCount = count _newWeapons;
_newMagazines = magazines _nearest;
_magazinesCount = count _newMagazines;
newPosition = getPos _nearest;
newDirection = getDir _nearest;
deleteVehicle _nearest;
for [{_x = 0}, {_x < _magazinesCount}, {_x= _x + 1}] do
{
_this addMagazine (_newMagazines select _x);
};
for [{_x = 0}, {_x < _weaponsCount}, {_x= _x + 1}] do
{
_this addWeapon (_newWeapons select _x);
};
_this setPos newPosition;
_this setDir newDirection;
}
[/QUOTE]
edit: of course, "_this" is the newly respawned player (and i don't know why the empty spaces at the beginning of a line always seem to get less after copying and pasting the code...)
i'm afraid there's hardly anything that does work the way it is now (especially if/then). but for some reason, i always got a Makarov and one magazine for it on respawn. so i wrote that forEach-thing into only one line and then i got all eight.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
{_this addMagazine '8Rnd_9x18_Makarov'} forEach [...];
[/QUOTE]
but what about the rest?... i mean i can't be expected to squeeze all the code into a single line for it to work, can i? or does it mean, i have to say good bye to clean programming and start making excessive use of "goto"? http://forums.bistudio.com/oldsmileys/crazy_o.gif
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
_nearest = objNull;
_distNearest = -1;
{
distX = _this distance _x;
if ((alive _x) AND (_distNearest == -1 OR distX < _distNearest)) then
{
_nearest = _x;
_distNearest = distX;
}
} forEach units group _this;
if (_distanceNearest == -1) then
{
{
_this addMagazine '8Rnd_9x18_Makarov'
} forEach [1,2,3,4,5,6,7,8];
_this addWeapon 'Makarov';
} else
{
_newWeapons = weapons _nearest;
_weaponsCount = count _newWeapons;
_newMagazines = magazines _nearest;
_magazinesCount = count _newMagazines;
newPosition = getPos _nearest;
newDirection = getDir _nearest;
deleteVehicle _nearest;
for [{_x = 0}, {_x < _magazinesCount}, {_x= _x + 1}] do
{
_this addMagazine (_newMagazines select _x);
};
for [{_x = 0}, {_x < _weaponsCount}, {_x= _x + 1}] do
{
_this addWeapon (_newWeapons select _x);
};
_this setPos newPosition;
_this setDir newDirection;
}
[/QUOTE]
edit: of course, "_this" is the newly respawned player (and i don't know why the empty spaces at the beginning of a line always seem to get less after copying and pasting the code...)
i'm afraid there's hardly anything that does work the way it is now (especially if/then). but for some reason, i always got a Makarov and one magazine for it on respawn. so i wrote that forEach-thing into only one line and then i got all eight.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
{_this addMagazine '8Rnd_9x18_Makarov'} forEach [...];
[/QUOTE]
but what about the rest?... i mean i can't be expected to squeeze all the code into a single line for it to work, can i? or does it mean, i have to say good bye to clean programming and start making excessive use of "goto"? http://forums.bistudio.com/oldsmileys/crazy_o.gif