OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: Acecool on 18 Aug 2008, 02:42:18
-
I read about 100 threads on locking and unlocking which I understand... but, I made a vehicle spawning script, the car starts out locked and I only want the person that bought it to be able to lock or unlock it...
civ1 - civ15 and cop1 - cop5 are the player names....
; Set the civ1 - civ15 and cop1 - cop5 title...
_name = "Not Set"
{call format ["if (player == %1) then {_name = ""%1""}", _x]} forEach allarray
_unit = objNull
call format ["_unit = %1", _name]
;Transaction done
#complete
call format ["%1 groupChat ""%1 you purchased: %2 and now have $%3 in your pocket and $%4 in your bank account.""",_name,_itemname,_cash,_bank]
~1
_pos = getPos _unit
call format ["_vehicle = ""%1"" createVehicle _pos; _vehicle lock true; _vehicle addaction [""[Unlock]"", ""Scripts\Vehicles\Unlock.sqs""]; [_vehicle] exec ""Scripts\Environment\Recycler.sqs""",_itemcname];
Exit
This part works by making the vehicle - some variables are in the script....
The action gets added to the vehicle, not sure it is added for the owner only or not.. but anyway this is the lock and unlock script, as copied from a thread in this forum...
Lock.sqs
_car = _this select 0
_unit = _this select 1
_action = _this select 2
_car removeaction _action
_car lock true
_car addaction ["[Unlock]","Scripts\Vehicles\Unlock.sqs"]
exit
Unlock.sqs
_car = this select 0
_unit = _this select 1
_action = _this select 2
_car removeaction _action
_car lock false
_car addaction ["[Lock]","Scripts\Vehicles\Lock.sqs"]
exit
I get the error:
_car this select 0 |#|': Error select: Type Object, expected Array
-
_shop addaction ["Buy Skoda $500", "BuyCar.sqs", ["Skoda"]];
BuyCar.sqs
_vehicle = ((_this select 3) select 0)
_unit = _this select 1;
_car = _vehicle createVehicle (getPos _unit)
? (player == _unit) : _car addaction ["Lock", "Lock.sqs"]
Lock.sqs
_vehicle = _this select 0
_id = _this select 2
_unit = _this select 1
_vehicle lock TRUE
_vehicle removeaction _id
_unit groupchat "Vehicle Locked"
_vehicle addaction ["Unlock", "Unlock.sqs"]
Unlock.sqs
_vehicle = _this select 0
_id = _this select 2
_unit = _this select 1
_vehicle lock FALSE
_vehicle removeaction _id
_unit groupchat "Vehicle UnLocked"
_vehicle addaction ["Lock", "Lock.sqs"]
Hope that helps. I can help more if not.
-
Basically, the only thing that changed there was adding (Player == _unit) which I added in, I am guessing that part works, but I get unexpected OBJECT expected array error in the script...
Its like its not detecting the action id when pressed....
EDIT LOL, I think I found the main problem...
_car = this select 0
_unit = _this select 1
_action = _this select 2
no _ before this on _car
NEW PROBLEM!!!!
Ok, so only the owner can lock and unlock the car, works great... but the lock only applies to the owner... any other player in multiplayer can get in the vehicle, locked or unlocked....
-
well ya can do this:
;Put all your players in here that you want the car to lock for.
car_lock_array = [unit1,unit2,unit3,unit4]
{? (player == _x) : _veh lock TRUE} foreach car_lock_array
Alternatively (Though I am not to familiar with publicVariable to much):
_veh = _this select 0
;Keep this in so it locks for the player who activated it too
_veh lock TRUE
;Lock for everyone else
veh = _veh;
lockveh = "veh lock TRUE"
publicvariable "lockveh"
Though the first should work fine, and for some reason is the way I prefer.