Home   Help Search Login Register  

Author Topic: Lock Unlock car for owner only?  (Read 2075 times)

0 Members and 1 Guest are viewing this topic.

Offline Acecool

  • Members
  • *
Lock Unlock car for owner only?
« 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....


Code: [Select]
; 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
Code: [Select]
_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
Code: [Select]
_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
« Last Edit: 18 Aug 2008, 02:49:46 by Acecool »

Offline ModestNovice

  • Members
  • *
Re: Lock Unlock car for owner only?
« Reply #1 on: 18 Aug 2008, 03:26:11 »
_shop addaction ["Buy Skoda $500", "BuyCar.sqs", ["Skoda"]];

BuyCar.sqs
Code: [Select]
_vehicle = ((_this select 3) select 0)
_unit = _this select 1;

_car = _vehicle createVehicle (getPos _unit)
? (player == _unit) : _car addaction ["Lock", "Lock.sqs"]

Lock.sqs
Code: [Select]
_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
Code: [Select]
_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.
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley

Offline Acecool

  • Members
  • *
Re: Lock Unlock car for owner only?
« Reply #2 on: 18 Aug 2008, 04:16:40 »
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....
« Last Edit: 19 Aug 2008, 07:53:50 by Acecool »

Offline ModestNovice

  • Members
  • *
Re: Lock Unlock car for owner only?
« Reply #3 on: 20 Aug 2008, 05:13:36 »
well ya can do this:
Code: [Select]
;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):
Code: [Select]
_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.
« Last Edit: 20 Aug 2008, 05:15:34 by DaChevs »
"The road became empty and the people disappeared. The clouds ran away; opened up the sky, and one by one I watched every constellation die."
- Sean "Slug" Daley