ayser 1 Posted March 16, 2013 While i'm editing Wasteland, i've added water barrels, but with this script, when someone takes water from the barrel, it takes 1 from every barrel. What should I edit to take only 1 from that certain barrel? foodCreation.sqf // @file Version: 1.0 // @file Name: Script Name // @file Author: [404] Deadbeat // @file Created: DD/MM/YYYY HH:MM // @file Args: if(!X_Server) exitWith {}; _objPos = _this select 0; _Objtype = foodContainers select (random (count foodContainers - 1)); _obj = createVehicle [_Objtype,_objPos,[], 10,"None"]; _randomnum = floor(random 4); // Random # up to 4 foodObject = _obj; if(_Objtype == "Land_Barrelwater_F") then { _obj setVariable["water",_randomnum,false]; // Gives 3 _obj addAction ["Take water","client\digestion\thirstConsume.sqf","",1,false,true,"","(_target distance _this) < 3"]; }; _obj setpos [getpos _obj select 0,getpos _obj select 1,0]; thirstConsume.sqf if(foodObject getVariable "water" <= 0) exitWith { hint "This crate of water is empty"; }; if(foodObject getVariable "water" > 0) then { hint "Wait..."; sleep 10; hint "OK"; sleep 3; player setVariable["water", (player getVariable "water")+1,true]; foodObject setVariable["water", (foodObject getVariable "water")-1,true]; hint format ["You take a bottle of water, there is %1 left", [foodObject getVariable "water"]]; }; Share this post Link to post Share on other sites
tophe 69 Posted March 16, 2013 While i'm editing Wasteland, i've added water barrels, but with this script, when someone takes water from the barrel, it takes 1 from every barrel. What should I edit to take only 1 from that certain barrel?foodCreation.sqf // @file Version: 1.0 // @file Name: Script Name // @file Author: [404] Deadbeat // @file Created: DD/MM/YYYY HH:MM // @file Args: if(!X_Server) exitWith {}; _objPos = _this select 0; _Objtype = foodContainers select (random (count foodContainers - 1)); _obj = createVehicle [_Objtype,_objPos,[], 10,"None"]; _randomnum = floor(random 4); // Random # up to 4 foodObject = _obj; if(_Objtype == "Land_Barrelwater_F") then { _obj setVariable["water",_randomnum,false]; // Gives 3 _obj addAction ["Take water","client\digestion\thirstConsume.sqf","",1,false,true,"","(_target distance _this) < 3"]; }; _obj setpos [getpos _obj select 0,getpos _obj select 1,0]; thirstConsume.sqf if(foodObject getVariable "water" <= 0) exitWith { hint "This crate of water is empty"; }; if(foodObject getVariable "water" > 0) then { hint "Wait..."; sleep 10; hint "OK"; sleep 3; player setVariable["water", (player getVariable "water")+1,true]; foodObject setVariable["water", (foodObject getVariable "water")-1,true]; hint format ["You take a bottle of water, there is %1 left", [foodObject getVariable "water"]]; }; On which object is the script run? Share this post Link to post Share on other sites
ayser 1 Posted March 16, 2013 On which object is the script run? Land_Barrelwater_F ----------------- I've tried to find the nearest of the object, and tried working with that, but, no dice :( It won't even find the object. _closestFoodObject = nearestObject [player, "foodObject"]; if(_closestFoodObject getVariable "water" <= 0) exitWith { hint "This crate of water is empty"; }; if(_closestFoodObject getVariable "water" > 0) then { hint "Wait..."; sleep 1; hint "OK"; sleep 3; player setVariable["water", (player getVariable "water")+1,true]; _closestFoodObject setVariable["water", (_closestFoodObject getVariable "water")-1,true]; hint format ["You take a bottle of water, there is %1 left", [_closestFoodObject getVariable "water"]]; }; ---------- Post added at 06:59 PM ---------- Previous post was at 06:37 PM ---------- If it makes anything more clearer, this is everything: foodSpawning.sqf // @file Version: 1.0 // @file Name: foodSpawning.sqf // @file Author: [404] Deadbeat, [404] Costlyy // @file Created: 20/11/2012 05:19 // @file Args: if(!X_Server) exitWith {}; private ["_counter","_pos","_markerName","_marker","_amountOfVehicles","_hint"]; _counter = 0; for "_i" from 1 to 16 do { _pos = getMarkerPos format ["Food_%1", _i]; _newpos = [_pos, 21, 40, 1, 0, 60 * (pi / 180), 0] call BIS_fnc_findSafePos; [_newpos] call foodCreation; _counter = _counter + 2; }; diag_log format["WASTELAND SERVER - %1 Food crates Spawned",_counter]; foodCreation.sqf // @file Version: 1.0 // @file Name: Script Name // @file Author: [404] Deadbeat // @file Created: DD/MM/YYYY HH:MM // @file Args: if(!X_Server) exitWith {}; _objPos = _this select 0; _Objtype = foodContainers select (random (count foodContainers - 1)); _obj = createVehicle [_Objtype,_objPos,[], 10,"None"]; _randomnum = floor(random 4); // Random # up to 4 foodObject = _obj; if(_Objtype == "Land_Barrelwater_F") then { _obj setVariable["water",4,false]; _obj addAction ["Take water","client\digestion\thirstConsume.sqf","",1,false,true,"","(_target distance _this) < 3"]; }; if(_Objtype == "Land_WoodenBox_F") then { _obj setVariable["canfood",3,true]; _obj addAction ["Take food","scripts\score4Barrels.sqf", "(_target distance _obj) < 4"]; }; _obj setpos [getpos _obj select 0,getpos _obj select 1,0]; thirstConsume.sqf //_closestFoodObject = nearestObject [player, "foodObject"]; _closestFoodObject = getPos player nearestObject "foodObject"; if(_closestFoodObject getVariable "water" <= 0) exitWith { hint "This crate of water is empty"; }; hint "3"; if(_closestFoodObject getVariable "water" > 0) then { hint "Wait..."; sleep 1; hint "OK"; sleep 3; player setVariable["water", (player getVariable "water")+1,true]; _closestFoodObject setVariable["water", (_closestFoodObject getVariable "water")-1,true]; hint format ["You take a bottle of water, there is %1 left", [_closestFoodObject getVariable "water"]]; }; hint "4"; if(foodObject getVariable "water" <= 0) exitWith { hint "This crate of water is empty"; }; hint "3"; if(foodObject getVariable "water" > 0) then { hint "Wait..."; sleep 1; hint "OK"; sleep 3; player setVariable["water", (player getVariable "water")+1,true]; foodObject setVariable["water", (foodObject getVariable "water")-1,true]; if(foodObject getVariable "water" > 1) then { hint format ["You take a bottle of water, there are %1 left", foodObject getVariable "water"]; }; if(foodObject getVariable "water" == 1) then { hint "You take a bottle of water, there is 1 left"; }; if(foodObject getVariable "water" <= 0) then { hint "You take the last bit of water"; }; }; Edited some code from the last post Share this post Link to post Share on other sites
tophe 69 Posted March 16, 2013 Have you checked all your variables? foodObject looks global to me... Share this post Link to post Share on other sites