Mongoose_84 0 Posted December 19, 2006 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; } 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 [...]; 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"? Share this post Link to post Share on other sites
Mongoose_84 0 Posted December 19, 2006 just in case anyone wanted to do something similar - i got it to work now: Quote[/b] ]_nearest = ObjNull; _distNearest = -1; {_distX = (_this distance _x); if ((alive _x) AND (_x != _this) AND (_distNearest == -1 OR _distX < _distNearest)) then {_nearest = _x; _distNearest = _distX}} forEach units group _this; if (_distNearest == -1) then {goto "newUnit"}; _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; exit; #newUnit {_this addMagazine '8Rnd_9x18_Makarov'} forEach [1,2,3,4,5,6,7,8]; _this addWeapon 'Makarov'; _this selectWeapon 'Makarov'; it's quite handy, because it makes you respawn into group members, while there are any left without ending the game, if there aren't. (i mean to use this in a kind of rts-style map, where your group size can change dynamically) what's missing so far, is that it won't work, if the nearest unit is inside a vehicle. i would also like to hear any other suggestions of how to improve this code. for example: is it possible to adept the current stance (prone, standing, kneeling) also? and is there a way to make the new unit draw it's weapons instantly (without animation)? edit: oh and does anyone know the return value for "primaryWeapon _x" (and accordingly secondary/side arm), if it is none at all? edit2: ok i read, that it returns "" in that case, but i couldn't find a function for the sidearm/handgun that does, what primaryWeapon/secondaryWeapon does for the other weapon slots... if anyone wants to join my monologue, just go ahead Share this post Link to post Share on other sites