Advertisement
Guest User

fixded

a guest
Jun 26th, 2011
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. /*
  2. ###########################################
  3. Car lock and unlock by tony tony
  4. ############################################
  5. */
  6.  
  7. #include <a_samp>
  8.  
  9. #define COLOR_YELLOW 0xFFFF00AA
  10.  
  11. new locked[MAX_PLAYERS][MAX_VEHICLES];
  12. new vehid[MAX_PLAYERS];
  13. new unlocktimer;
  14. forward unlock(playerid,vehicleid);
  15.  
  16. public OnPlayerDisconnect(playerid)
  17. {
  18. new i2;
  19. for(i2=0;i2<MAX_VEHICLES;i2++)
  20. {
  21. if (locked[playerid][i2] == 1)
  22. {
  23. new i;
  24. for(i=0;i<MAX_PLAYERS;i++)
  25. {
  26. SetVehicleParamsForPlayer(i2,i, 0, 0);
  27. }
  28. }
  29. locked[playerid][i2] = 0;
  30. }
  31. return 1;
  32. }
  33.  
  34. public OnPlayerCommandText(playerid, cmdtext[])
  35. {
  36. if (strcmp(cmdtext, "/lock", true)==0)
  37. {
  38. if(IsPlayerInAnyVehicle(playerid))
  39. {
  40. new State=GetPlayerState(playerid);
  41. if(State!=PLAYER_STATE_DRIVER)
  42. {
  43. SendClientMessage(playerid,0xFFFF00AA,"You can only lock the doors as the driver.");
  44. return 1;
  45. }
  46. new i;
  47. for(i=0;i<MAX_PLAYERS;i++)
  48. {
  49. if(i != playerid)
  50. {
  51. SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 1);
  52. }
  53. }
  54. SendClientMessage(playerid, 0xFFFF00AA, "Vehicle locked!");
  55. new Float:pX, Float:pY, Float:pZ;
  56. GetPlayerPos(playerid,pX,pY,pZ);
  57. PlayerPlaySound(playerid,1056,pX,pY,pZ);
  58. locked[playerid][GetPlayerVehicleID(playerid)] = 1;
  59. }
  60. else
  61. {
  62. SendClientMessage(playerid, 0xFFFF00AA, "You're not in a vehicle!");
  63. }
  64. return 1;
  65. }
  66.  
  67.  
  68. if (strcmp(cmdtext, "/unlock", true)==0)
  69. {
  70. if(IsPlayerInAnyVehicle(playerid))
  71. {
  72. new State=GetPlayerState(playerid);
  73. if(State!=PLAYER_STATE_DRIVER)
  74. {
  75. SendClientMessage(playerid,0xFFFF00AA,"You can only lock the doors as the driver.");
  76. return 1;
  77. }
  78. new i;
  79. for(i=0;i<MAX_PLAYERS;i++)
  80. {
  81. SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i, 0, 0);
  82. }
  83. SendClientMessage(playerid, 0xFFFF00AA, "Vehicle unlocked!");
  84. new Float:pX, Float:pY, Float:pZ;
  85. GetPlayerPos(playerid,pX,pY,pZ);
  86. PlayerPlaySound(playerid,1057,pX,pY,pZ);
  87. locked[playerid][GetPlayerVehicleID(playerid)] = 0;
  88. }
  89. else
  90. {
  91. SendClientMessage(playerid, 0xFFFF00AA, "You're not in a vehicle!");
  92. }
  93. return 1;
  94. }
  95. return 0;
  96. }
  97.  
  98. public OnPlayerEnterVehicle(playerid,vehicleid)
  99. {
  100. vehid[playerid] = vehicleid;
  101. return 1;
  102. }
  103.  
  104. public OnPlayerStateChange(playerid,newstate,oldstate)
  105. {
  106. if(oldstate == PLAYER_STATE_DRIVER)
  107. {
  108. if (locked[playerid][vehid[playerid]] == 1)
  109. {
  110. unlocktimer = SetTimerEx("unlock",300000,false,"ii",playerid,vehid[playerid]);
  111. SendClientMessage(playerid,COLOR_YELLOW,"This vehicle will be automatic unlocked in 5 minutes.");
  112. locked[playerid][vehid[playerid]] = 2;
  113. }
  114. }
  115. if (newstate == PLAYER_STATE_DRIVER)
  116. {
  117. if (locked[playerid][vehid[playerid]] == 2)
  118. {
  119. KillTimer(unlocktimer);
  120. locked[playerid][vehid[playerid]] = 1;
  121. new Float:pX, Float:pY, Float:pZ;
  122. GetPlayerPos(playerid,pX,pY,pZ);
  123. PlayerPlaySound(playerid,1056,pX,pY,pZ);
  124. SendClientMessage(playerid,COLOR_YELLOW,"This vehicle is locked.");
  125.  
  126. }
  127. }
  128. return 1;
  129. }
  130.  
  131. public unlock(playerid,vehicleid)
  132. {
  133. new i;
  134. for(i=0;i<MAX_PLAYERS;i++)
  135. {
  136. SetVehicleParamsForPlayer(vehicleid,i, 0, 0);
  137. }
  138. locked[playerid][vehicleid] = 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement