LKS90 1 Posted December 31, 2013 (edited) Hey there! I would like some critique/help for my quad respawn script. It creates a Quad at a marker called "quadRespawn". The quad should automatically respawn when killed and there should be a marker on the quadbike which is alive right now. Here are the 2 scripts which I think could in theory make that possible. Problem is, it doesn't work, there are no syntax errors (in arma or squint) and I'm at a loss. I would like to learn sqf scripting, therefore I would appreciate it if someone would help me with my scripts instead of pointing me towards working scripts which are made for every possible edge case and only have to be called. Further notes: My plan is to make the mission SP for the moment, it is run in MP though, because of the player respawn templates which I really like. Locality shouldn't be much of an issue, but I am honestly not really sure about how locality practically effects everything, still need to learn some stuff :P. Edit: The quadRespawnScript is called in the init.sqf once, to spawn a quad at the beginning. I also changed it a little bit, now it complains about line 7 in liveMarker.sqf. The _unit variable is unassigned : /. Edit²: My Idea now would be to change it somewhat: Create a carpool, add the quad to it in the respawnScript and create markers for every object in the carpool (futureproof, yay :D). ______________ Edit³ Back to status quo, it just doesn't work. Here are all the scripts right now: quadRespawnScript.sqf: private ["_pool","_count","_name"]; _pool = _this select 0; _count = count _pool; _name = format ["quadBike%1", _count]; // Is a String recurse = { execVM "quadRespawnScript.sqf" }; addEH = " this addMPEventHandler [""mpkilled"", recurse] "; addName = " _name = this; "; "B_G_Quadbike_01_F" createUnit [getMarkerPos "quadRespawn", group player, addEH + ";" + addName]; carPool = carPool + [_name]; // Want to use as objectName publicVariable "carPool"; liveMarker.sqf: private ["_pool"]; _pool = _this select 0; {[_x] call markerFunction} foreach _pool; markerFunction = { private ["_unit","_name","_text","_marker"]; _unit = _this select 0; _name = "quadMarker"; _text = "Quadbike"; _marker = createMarker [_name, position _unit]; _marker setMarkerText _text; _marker setMarkerColor "ColorBLUFOR"; _marker setMarkerType "b_unknown"; while {alive _unit} do { _marker setMarkerPos (getPos _unit); sleep 0.75; }; deleteMarker _marker; }; init.sqf: [west,5] call BIS_fnc_respawnTickets; [west, "WEST1"] call BIS_fnc_addRespawnInventory; carPool = []; publicVariable "carPool"; [carPool] execVM "quadRespawnScript.sqf"; [carPool] execVM "liveMarker.sqf"; Edited January 1, 2014 by LKS90 Share this post Link to post Share on other sites
LKS90 1 Posted January 4, 2014 Even my most basic scripts don't want to work. : / enlargePool = { vehicleCount = vehicleCount + 1; maxVehicles = maxVehicles + 1; }; addEH = "this addMPEventHandler [""mpkilled"", enlargePool]"; while {true} do { if(vehicleCount < maxVehicles) then { "B_G_Quadbike_01_F" createUnit [getMarkerPos "quadRespawn", vehiclePool, addEH]; }; }; [west,5] call BIS_fnc_respawnTickets; [west, "WEST1"] call BIS_fnc_addRespawnInventory; execVM "vehicleScript.sqf"; maxVehicles = 1; vehiclePool = []; vehicleCount = count vehiclePool; Share this post Link to post Share on other sites
das attorney 858 Posted January 4, 2014 Be careful of using addMPEventHandler. This is from the biki: Triggered when the unit is hit/damaged. EH can be added on any machine and EH code will trigger globally on every connected client and server. Add it only on server because if you have 10 machines on network and add this EH to every machine, when triggered the EH code will be executed 10 x 10 = 100 times. http://community.bistudio.com/wiki/Arma_3:_Event_Handlers#MPHit So it might be that you are increasing your numbers more than you should. I assume that because you are adding the EH in the format: this addMPEventHandler... then it is added on all player machines. How are you running your scripts? There doesn't seem to be any definition of whether the server should run them or clients. Share this post Link to post Share on other sites
LKS90 1 Posted January 4, 2014 (edited) The problem at the moments is that it doesn't even spawn a single Unit : /. At the moment I don't have it decided if the server or the client should run it, as it is meant for singleplayer only (and because I had no idea it could/has to be defined somehwere :D). _____ Edit: lks_eventHandlerCode = {vehicleCount = vehicleCount + 1; maxVehicles = maxVehicles + 1;}; if (isServer) then{ while {true} do { if(vehicleCount < maxVehicles) then { "B_G_Quadbike_01_F" createUnit [getMarkerPos "quadRespawn", vehiclePool, "this addMPEventHandler [ ""mpkilled"", _this call lks_eventHandlerCode ]" ]; }; sleep 0.75; }; } the code right now (with some testing). Edited January 4, 2014 by LKS90 Share this post Link to post Share on other sites
das attorney 858 Posted January 4, 2014 I wouldn't worry about any of this to be honest. From what you said: It creates a Quad at a marker called "quadRespawn". The quad should automatically respawn when killed and there should be a marker on the quadbike which is alive right now. My plan is to make the mission SP for the moment, it is run in MP though, because of the player respawn templates which I really like. If you want it to work in MP straightaway, without any messing about in SP, then use this command: http://community.bistudio.com/wiki/respawnVehicle So place a marker called "respawn_vehicle_west" without the "" (assuming you are west). Then run the following code in the init or similar: _quad = createVehicle ["B_G_Quadbike_01_F", getMarkerPos "respawn_vehicle_west", [], 0, "none"]; _quad respawnVehicle [30]; Or, put a quadbike down in the editor, and put this in it's init: this respawnVehicle [30]; Hope that helps you. Share this post Link to post Share on other sites