Skip to content

Commit 9cde307

Browse files
author
Cre8or
committed
Improved player-build houses functionality
- Player-built houses can now be deleted by selling them - Fixed some buildable houses not being recognised as such (e.g. "Land_GarageShelter_01_F") by comparing the classname to the list of buildable houses defined in fn_initVar - The lease status of player-built houses now persists properly across sessions - Obsolete building IDs from previous sessions no longer clutter up the players' "leased" and "leasedata" arrays (automatic cleanup on loadGame) - Enforced all new custom variables (including "OT_forceSaveUnowned" from the previous commits) to be broadcasted across the network (for consistency)
1 parent b17c8f2 commit 9cde307

7 files changed

Lines changed: 75 additions & 15 deletions

File tree

addons/overthrow_main/functions/UI/dialogs/fn_mainMenu.sqf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ if(typename _b isEqualTo "ARRAY") then {
8585
_txt = "";
8686

8787
if(_building call OT_fnc_hasOwner) then {
88-
8988
_owner = _building call OT_fnc_getOwner;
9089
_ownername = players_NS getVariable format["name%1",_owner];
9190
if(isNil "_ownername") then {_ownername = "Someone"};
@@ -309,7 +308,9 @@ if(typename _b isEqualTo "ARRAY") then {
309308
};
310309
};
311310

312-
if(!((typeof _building) in OT_allRealEstate + [OT_flag_IND])) then {
311+
// Fetch the list of buildable houses
312+
private _buildableHouses = (OT_Buildables param [9, []]) param [2, []];
313+
if(!((typeof _building) in OT_allRealEstate + [OT_flag_IND]) and {!(typeOf _building in _buildableHouses)}) then {
313314
ctrlEnable [1609,false];
314315
ctrlEnable [1610,false];
315316
ctrlEnable [1608,false];

addons/overthrow_main/functions/actions/fn_build.sqf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ buildOnMouseUp = {
267267
if(_money < modePrice) then {
268268
"You cannot afford that" call OT_fnc_notifyMinor;
269269
}else{
270+
270271
_created = objNULL;
271272
playSound "3DEN_notificationDefault";
272273
player setVariable ["money",_money-modePrice,true];
@@ -279,6 +280,7 @@ buildOnMouseUp = {
279280
clearItemCargoGlobal _x;
280281
[_x,getplayeruid player] call OT_fnc_setOwner;
281282
_x call OT_fnc_initObjectLocal;
283+
282284
}foreach(_objects);
283285
_created = _objects select 0;
284286
deleteVehicle modeTarget;
@@ -288,6 +290,12 @@ buildOnMouseUp = {
288290
modeTarget = objNull;
289291
};
290292

293+
// If the object is a house, mark it as being player-built (will be used to save the leasing status)
294+
private _buildableHouses = (OT_Buildables param [9, []]) param [2, []];
295+
if ((typeof _created) in _buildableHouses) then {
296+
_created setVariable ["OT_house_isPlayerBuilt", true, true];
297+
};
298+
291299
if(modeCode != "") then {
292300
_created setVariable ["OT_init",modeCode,true];
293301
[_created,modeValue,modeCode] remoteExec ["OT_fnc_initBuilding",2];

addons/overthrow_main/functions/actions/fn_buyBuilding.sqf

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,32 @@ if(_handled) then {
4343
[player,"Building Purchased",format["Bought: %1 in %2 for $%3",getText(configFile >> "CfgVehicles" >> (typeof _building) >> "displayName"),(getpos _building) call OT_fnc_nearestTown,_price]] call BIS_fnc_createLogRecord;
4444
_building addEventHandler ["Dammaged",OT_fnc_buildingDamagedHandler];
4545
}else{
46-
if ((typeof _building) in OT_allRealEstate) then {
46+
// Fetch the list of buildable houses
47+
private _buildableHouses = (OT_Buildables param [9, []]) param [2, []];
48+
if((typeof _building) in OT_allRealEstate or {((typeOf _building) in _buildableHouses)}) then {
4749
private _id = [_building] call OT_fnc_getBuildID;
4850
[_building,nil] call OT_fnc_setOwner;
4951
private _leased = player getVariable ["leased",[]];
5052
_leased deleteAt (_leased find _id);
5153
player setVariable ["leased",_leased,true];
54+
55+
private _leasedata = player getVariable ["leasedata",[]];
56+
private _leasedataID = (_leasedata apply {_x select 0}) findIf {_x == _id};
57+
_leasedata deleteAt _leasedataID;
58+
player setVariable ["leasedata",_leasedata,true];
59+
5260
deleteMarker _mrkid;
5361
_owned deleteAt (_owned find _id);
5462
[player,"Building Sold",format["Sold: %1 in %2 for $%3",getText(configFile >> "CfgVehicles" >> (typeof _building) >> "displayName"),(getpos _building) call OT_fnc_nearestTown,_sell]] call BIS_fnc_createLogRecord;
5563
[_sell] call OT_fnc_money;
64+
65+
// Fallback for unknown buildings
5666
}else{
57-
deleteVehicle _building;
5867
_owned deleteAt (_owned find ([_building] call OT_fnc_getBuildID));
5968
};
69+
70+
// Always attempt to remove the building, because it might be played-placed (for map-placed buildings, this won't do anything)
71+
deleteVehicle _building;
6072
};
6173

6274
player setVariable ["owned",_owned,true];

addons/overthrow_main/functions/actions/fn_leaseBuilding.sqf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ if(typename _b isEqualTo "ARRAY") then {
5656
};
5757
if(_err) exitWith {};
5858
if(_handled) then {
59+
60+
// If the house is player-built, we set its lease variable to true
61+
if (_building getVariable ["OT_house_isPlayerBuilt", false]) then {
62+
_building setVariable ["OT_house_isLeased", true, true];
63+
};
64+
5965
private _id = ([_building] call OT_fnc_getBuildID);
6066
_leased = player getvariable ["leased",[]];
6167
_leased pushback _id;

addons/overthrow_main/functions/factions/GUER/fn_GUERLoop.sqf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ if ((date select 4) != _lastmin) then {
364364
if(count _p > 0) then {
365365
_veh = _currentCls createVehicle _p;
366366
//[_veh,(server getVariable ["generals",[]]) select 0] call OT_fnc_setOwner;
367-
_veh setVariable ["OT_forceSaveUnowned", true, false]; // Save this vehicle even if it is unowned (we know somebody must have requested it at the factory, so they'll come back and claim it... eventually)
367+
_veh setVariable ["OT_forceSaveUnowned", true, true]; // Save this vehicle even if it is unowned (we know somebody must have requested it at the factory, so they'll come back and claim it... eventually)
368368
clearWeaponCargoGlobal _veh;
369369
clearMagazineCargoGlobal _veh;
370370
clearBackpackCargoGlobal _veh;

addons/overthrow_main/functions/save/fn_loadGame.sqf

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ sleep 0.3;
162162
};
163163
*/
164164

165-
if(count _x > 7) then {
165+
if(count _x > 7) then { // index range 0..6
166166
(_x select 7) params ["_fuel","_dmg"];
167167
//Fuel in tank
168168
_veh setFuel _fuel;
@@ -198,6 +198,21 @@ sleep 0.3;
198198
};
199199
};
200200

201+
// If the object is a player-built house, fetch its variables
202+
private _houseParams = _x param [8, []];
203+
if !(_houseParams isEqualTo []) then {
204+
_veh setVariable ["OT_house_isPlayerBuilt", true, true];
205+
206+
private _isLeased = _houseParams param [0, false];
207+
if (_isLeased) then {
208+
_veh setVariable ["OT_house_isLeased", true, true];
209+
210+
private _leasedBuilt = [_owner,"leasedBuilt",[]] call OT_fnc_getOfflinePlayerAttribute;
211+
_leasedBuilt pushBack _veh;
212+
[_owner,"leasedBuilt",_leasedBuilt] call OT_fnc_setOfflinePlayerAttribute;
213+
};
214+
};
215+
201216
if (_posFormat == 1) then {
202217
_veh setPosWorld _pos; // format 1 is the new posWorld format
203218
} else {
@@ -223,7 +238,7 @@ sleep 0.3;
223238

224239
// If this vehicle doesn't have an owner, set the forceSaveunowned flag to true so it gets saved again (until somebody owns it)
225240
if (_owner isEqualTo "") then {
226-
_veh setVariable ["OT_forceSaveUnowned", true, false];
241+
_veh setVariable ["OT_forceSaveUnowned", true, true];
227242
// Otherwise, set the owner (as per usual)
228243
} else {
229244
[_veh,_owner] call OT_fnc_setOwner;
@@ -432,6 +447,7 @@ private _built = (allMissionObjects "Static");
432447
private _vars = players_NS getVariable [_uid,[]];
433448
private _leased = [_uid,"leased",[]] call OT_fnc_getOfflinePlayerAttribute;
434449
private _leasedata = [];
450+
private _leasedNew = [];
435451
{
436452
_x params ["_name","_val"];
437453
if(_name isEqualTo "owned") then {
@@ -459,12 +475,24 @@ private _built = (allMissionObjects "Static");
459475
};
460476
if(_x in _leased) then {
461477
_leasedata pushback [_x,typeof _bdg,_pos,_pos call OT_fnc_nearestTown];
478+
_leasedNew pushBack _x;
462479
};
463480
};
464481
}foreach(_val);
465482
};
466483
}foreach(_vars);
484+
485+
// Add the built houses
486+
{
487+
private _ID = [_x] call OT_fnc_getBuildID;
488+
private _pos = position _x;
489+
_leasedata pushBack [_ID, typeof _x,_pos,_pos call OT_fnc_nearestTown];
490+
_leasedNew pushBack _ID;
491+
} forEach ([_uid,"leasedBuilt",[]] call OT_fnc_getOfflinePlayerAttribute);
492+
467493
[_uid,"leasedata",_leasedata] call OT_fnc_setOfflinePlayerAttribute;
494+
[_uid,"leased",_leasedNew] call OT_fnc_setOfflinePlayerAttribute; // Overwrite the "leased" data to get rid of the IDs that point to buildings which no longer exist (player-built houses)
495+
[_uid,"leasedBuilt",[]] call OT_fnc_setOfflinePlayerAttribute;
468496
}foreach(players_NS getvariable ["OT_allPlayers",[]]);
469497
sleep 2; //let the variables propagate
470498
server setVariable ["StartupType","LOAD",true];

addons/overthrow_main/functions/save/fn_saveGame.sqf

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ private _vehicles = (_tocheck) apply {
140140
};
141141
};
142142
private _params = [
143-
_type,
144-
[getPosWorld _x,_simCheck, 1], // 1 stands for the new posWorld format
145-
[vectorDir _x,vectorUp _x],
146-
_s,
147-
["", _x call OT_fnc_getOwner] select (_x call OT_fnc_hasOwner), // Save an empty string if the object doesn't have an owner (yet)
148-
_x getVariable ["name",""],
149-
_x getVariable ["OT_init",""]
143+
/* 0 */ _type,
144+
/* 1 */ [getPosWorld _x,_simCheck, 1], // 1 stands for the new posWorld format
145+
/* 2 */ [vectorDir _x,vectorUp _x],
146+
/* 3 */ _s,
147+
/* 4 */ ["", _x call OT_fnc_getOwner] select (_x call OT_fnc_hasOwner), // Save an empty string if the object doesn't have an owner (yet)
148+
/* 5 */ _x getVariable ["name",""],
149+
/* 6 */ _x getVariable ["OT_init",""]
150150
];
151151
if(_type isKindOf ["AllVehicles", _cfgVeh] && {!(_x getVariable ["OT_garrison",false])}) then {
152152
private _veh = _x;
@@ -161,7 +161,12 @@ private _vehicles = (_tocheck) apply {
161161
if(!(_attachedClass isEqualTo "") && { alive _attached }) then {
162162
_att = [_attachedClass,(_attached weaponsTurret [0]) apply { [_x,_attached ammo _x] }];
163163
};
164-
_params pushback [fuel _x,getAllHitPointsDamage _x,_x call ace_refuel_fnc_getFuel,_x getVariable ["OT_locked",false],_ammo,_att];
164+
/* 7 */ _params set [7, [fuel _x,getAllHitPointsDamage _x,_x call ace_refuel_fnc_getFuel,_x getVariable ["OT_locked",false],_ammo,_att]];
165+
};
166+
167+
// If the house is player-built, save some extra variables
168+
if (_x getVariable ["OT_house_isPlayerBuilt", false]) then {
169+
/* 8 */ _params set [8, [_x getVariable ["OT_house_isLeased", false]]];
165170
};
166171
_params
167172
};

0 commit comments

Comments
 (0)