Author Topic: lock/unlock script  (Read 2735 times)

iulix2012

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
lock/unlock script
« on: May 26, 2013, 12:02:32 pm »
Code: [Select]
else if( cmd == "lock"){
  if ( player.Vehicle ){
MessagePlayer( "Your vehicle is locked!", player );
 player.Vehicle.Locked = true;
}else{
MessagePlayer( "You must be in a vehicle to use this command!", player );
}
}
else if( cmd == "unlock"){
  if ( player.Vehicle ){
MessagePlayer( "Your vehicle is unlocked!", player );
 player.Vehicle.Locked = false;
}else{

MessagePlayer( "You must be in a vehicle to use this command!", player );
}
}
« Last Edit: May 26, 2013, 01:02:36 pm by Thijn »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: lock/unlock script
« Reply #1 on: May 26, 2013, 01:02:55 pm »
Moved and added code tags.

NC

  • Full Member
  • ***
  • Posts: 101
  • Karma: +2/-3
  • cipa
    • View Profile
Re: lock/unlock script
« Reply #2 on: May 26, 2013, 07:34:50 pm »
1. Use TABulators.
2. You could add a check for the lock (unlock) command if the vehicle is already closed (opened). Why should someone close a closed car :)?

Website online:
My YT channel: http://www.youtube.com/user/1234sdg131

Yamaza

  • Newbie
  • *
  • Posts: 12
  • Karma: +2/-1
    • View Profile
Re: lock/unlock script
« Reply #3 on: July 02, 2013, 09:39:01 pm »
I have a more efficient script for this...:

Code: [Select]
function onPlayerCommand( pPlayer, szCommand, szArgs )
{
if ( szCommand == "lock" )
{
if ( !pPlayer.Spawned )
{
MessagePlayer( "You're not spawned.", pPlayer );
return;
}

if ( !pPlayer.Vehicle )
{
MessagePlayer( "You're not in a vehicle.", pPlayer );
return;
}

if ( pPlayer.VehicleSeat > 0 )
{
MessagePlayer( "You're not the driver on this vehicle.", pPlayer );
return;
}

if ( !szArgs )
{
MessagePlayer( "Locks or unlocks the doors of your vehicle. Usage: /" + szCommand + " < ON / OFF >", pPlayer );
return;
}

local veh = pPlayer.Vehicle;

switch ( szArgs )
{
case "on":
if ( veh.Locked )
{
MessagePlayer( "This vehicle is already locked.", pPlayer );
return;
}

veh.Locked = true;
MessagePlayer( "You have locked the doors of the vehicle.", pPlayer );
break;

case "off":
if ( !veh.Locked )
{
MessagePlayer( "This vehicle is already unlocked.", pPlayer );
return;
}

veh.Locked = false;
MessagePlayer( "You have unlock the doors of the vehicle.", pPlayer );
break;

default:
MessagePlayer( "Unknown usage! Usage: /" + szCommand + " < ON / OFF >", pPlayer );
break;
}
}

return 1;
}

Credits: Me
« Last Edit: July 07, 2013, 03:57:02 pm by Yamaza »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: lock/unlock script
« Reply #4 on: July 04, 2013, 05:52:47 pm »
Why is it more efficient when it has more lines? :P

Yamaza

  • Newbie
  • *
  • Posts: 12
  • Karma: +2/-1
    • View Profile
Re: lock/unlock script
« Reply #5 on: July 05, 2013, 04:08:39 pm »
Because the code runs faster, without else and else if. This more optimized. I checked it with a test of milliseconds. :P

 

© Liberty Unleashed Team.