Guest User

Untitled

a guest
Aug 28th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.52 KB | None | 0 0
  1. /* RNS V2.0 created by Kreison */
  2.  
  3. // Defines
  4. #define MAX_ROBNPCS 10 // Max rob NPC number
  5. #define ALARM_STOP 120 // Time to stop alarm (in secs) ~ TO TYPES 2 AND 3
  6. #define ROB_INTERVAL 900 // Time interval to rob again after sucess (in secs)
  7. #define FAILROB_INTERVAL 60 // Time interval to rob again after failure (in secs)
  8. /* ON RNPC NPC NAME DONT WILL APPEAR */
  9. #define NPC_PREFIX "Shopman" // NPC name prefix
  10. #define NPC_SUFFIX "BRL" // NPC name suffix
  11.  
  12.  
  13. // Variables
  14. enum e_RobNPCInfo
  15. {
  16. rnIsCon,
  17. rnMax,
  18. rnMin,
  19. rnInt,
  20. rnSkin,
  21. rnWorld,
  22. rnAlarm,
  23. Float: rnX,
  24. Float: rnY,
  25. Float: rnZ,
  26. Float: rnAng,
  27. rnPlayer,
  28. rnPay,
  29. rnDelay
  30. }
  31. new RobNPC[MAX_ROBNPCS][e_RobNPCInfo];
  32. new RobNPCS_totaln;
  33. new IsAlarmOn[MAX_PLAYERS];
  34. // -- timers
  35. new timer_aimcheck[MAX_ROBNPCS];
  36. new timer_roubo[MAX_ROBNPCS];
  37. new timer_int[MAX_PLAYERS];
  38.  
  39.  
  40.  
  41. // Stocks
  42. stock IsRobNPC(playerid)
  43. {
  44. if (IsPlayerNPC(playerid) && RobNPC[playerid][rnIsCon]) { return 1; }
  45.  
  46. return 0;
  47. }
  48.  
  49.  
  50. stock rnRandom(min, max)
  51. {
  52. //Credits to y_less
  53. new rand = random(max-min)+min;
  54. return rand;
  55. }
  56.  
  57.  
  58. stock rnIsPlayerInRangeOfPoint(playerid, Float:range, Float:x, Float:y, Float:z, worldid)
  59. {
  60. if (IsPlayerInRangeOfPoint(playerid, range, x, y, z) && GetPlayerVirtualWorld(playerid) == worldid)
  61. {
  62. return 1;
  63. }
  64.  
  65. return 0;
  66. }
  67.  
  68.  
  69. stock AddRobNPC(skin, Float:x, Float:y, Float:z, Float:ang, worldid, interiorid, alarmtype = 0, pay = 1, min = 1000, max = 2000)
  70. {
  71. if (RobNPCS_totaln >= MAX_ROBNPCS) {
  72. print("[Robbery NPCs system] ERROR: The actual rob npc numbers exceed the MAX_ROBNPCS number.");
  73. return 0;
  74. } else if (min >= max) {
  75. print("[Robbery NPCs system] ERROR: The minimum amount received by rob is bigger or equal than the maximum!");
  76. return 0;
  77. }
  78.  
  79. // Timer to avoid bugs with npc id
  80. SetTimerEx("AddRobNPC2", 500, false, "iffffiiiiii", skin, Float:x, Float:y, Float:z, Float:ang, worldid, interiorid, alarmtype, pay, min, max);
  81.  
  82. return 1;
  83. }
  84.  
  85.  
  86. stock PreloadRAnims(playerid)
  87. {
  88. ApplyAnimation(playerid,"SHOP","null",0.0,0,0,0,0,0);
  89. ApplyAnimation(playerid,"PED","null",0.0,0,0,0,0,0);
  90. }
  91.  
  92.  
  93. stock PlayAlarm(npcid)
  94. {
  95. new Float: x, Float: y, Float: z;
  96. GetPlayerPos(npcid, x, y, z);
  97.  
  98. for(new i = 0; i < MAX_PLAYERS; i++)
  99. {
  100. if (rnIsPlayerInRangeOfPoint(i, 50.0, x, y, z, GetPlayerVirtualWorld(npcid)))
  101. {
  102. new ALARM_TYPE = RobNPC[npcid][rnAlarm];
  103. if (ALARM_TYPE == 0)
  104. {
  105. IsAlarmOn[i] = npcid;
  106. PlayerPlaySound(i, 3401, 0.0, 0.0, 0.0);
  107. timer_int[i] = SetTimerEx("IntCheck", 500, true, "ii", i, npcid);
  108. } else if (ALARM_TYPE == 1) {
  109. IsAlarmOn[i] = npcid;
  110. PlayerPlaySound(i, 3401, x, y, z);
  111. timer_int[i] = SetTimerEx("IntCheck", 500, true, "ii", i, npcid);
  112. } else if (ALARM_TYPE == 2) {
  113. IsAlarmOn[i] = npcid;
  114. PlayerPlaySound(i, 3401, 0.0, 0.0, 0.0);
  115. SetTimerEx("StopAlarm", ALARM_STOP*1000, false, "i", i);
  116. } else if (ALARM_TYPE == 3) {
  117. IsAlarmOn[i] = npcid;
  118. PlayerPlaySound(i, 3401, x, y, z);
  119. SetTimerEx("StopAlarm", ALARM_STOP*1000, false, "i", i);
  120. } else if (ALARM_TYPE == 4) {
  121. IsAlarmOn[i] = npcid;
  122. PlayerPlaySound(i, 3401, 0.0, 0.0, 0.0);
  123. } else if (ALARM_TYPE == 5) {
  124. IsAlarmOn[i] = npcid;
  125. PlayerPlaySound(i, 3401, x, y, z);
  126. }
  127. }
  128. }
  129. }
  130.  
  131.  
  132.  
  133. // Publics
  134. forward AddRobNPC2(skin, Float:x, Float:y, Float:z, Float:ang, worldid, interiorid, alarmtype, pay, min, max);
  135. public AddRobNPC2(skin, Float:x, Float:y, Float:z, Float:ang, worldid, interiorid, alarmtype, pay, min, max)
  136. {
  137. RobNPCS_totaln++;
  138.  
  139. new npcname[24];
  140. format(npcname, sizeof(npcname), "%s%i_%s", NPC_PREFIX, RobNPCS_totaln, NPC_SUFFIX);
  141. new npcid = ConnectRNPC(npcname);
  142.  
  143. RobNPC[RobNPCS_totaln][rnIsCon] = npcid;
  144. RobNPC[RobNPCS_totaln][rnSkin] = skin;
  145.  
  146. if (pay)
  147. {
  148. RobNPC[RobNPCS_totaln][rnPay] = 1;
  149. RobNPC[RobNPCS_totaln][rnMax] = max;
  150. RobNPC[RobNPCS_totaln][rnMin] = min;
  151. } else {
  152. RobNPC[RobNPCS_totaln][rnPay] = 0;
  153. }
  154.  
  155. RobNPC[RobNPCS_totaln][rnInt] = interiorid;
  156. RobNPC[RobNPCS_totaln][rnWorld] = worldid;
  157. RobNPC[RobNPCS_totaln][rnX] = x;
  158. RobNPC[RobNPCS_totaln][rnY] = y;
  159. RobNPC[RobNPCS_totaln][rnZ] = z;
  160. RobNPC[RobNPCS_totaln][rnAng] = ang;
  161. RobNPC[RobNPCS_totaln][rnAlarm] = alarmtype;
  162. }
  163.  
  164.  
  165. forward RobP1(npcid);
  166. public RobP1(npcid)
  167. {
  168. ClearAnimations(npcid);
  169. timer_roubo[npcid] = SetTimerEx("RobP2", 100, false, "i", npcid);
  170. }
  171.  
  172.  
  173. forward RobP2(npcid);
  174. public RobP2(npcid)
  175. {
  176. ClearAnimations(npcid);
  177. ApplyAnimation(npcid,"SHOP","SHP_Rob_GiveCash",4.1,0,1,1,1,0,1);
  178. timer_roubo[npcid] = SetTimerEx("RobP3", 3900, false, "i", npcid);
  179. }
  180.  
  181.  
  182. forward RobP3(npcid);
  183. public RobP3(npcid)
  184. {
  185. KillTimer(timer_aimcheck[npcid]);
  186.  
  187. ClearAnimations(npcid);
  188. ApplyAnimation(npcid,"PED","DUCK_cower",4.1,1,1,1,1,1,1);
  189.  
  190. PlayAlarm(npcid);
  191.  
  192. new moneyganho;
  193. new playerid = RobNPC[npcid][rnPlayer];
  194. if (RobNPC[npcid][rnPay])
  195. {
  196. moneyganho = rnRandom(RobNPC[npcid][rnMin],RobNPC[npcid][rnMax]);
  197. new rnMsg[35];
  198. format(rnMsg, sizeof(rnMsg), "~g~You stole~n~$%i", moneyganho);
  199. GivePlayerMoney(playerid, moneyganho);
  200. GameTextForPlayer(playerid, rnMsg, 2000, 0);
  201. } else {
  202. moneyganho = 0;
  203. }
  204.  
  205. CallLocalFunction("OnPlayerSucessRob", "iii", playerid, npcid, moneyganho);
  206.  
  207. SetTimerEx("RobDelay", ROB_INTERVAL*1000, false, "i", npcid);
  208. }
  209.  
  210.  
  211. forward AimCheck(playerid, npcid);
  212. public AimCheck(playerid, npcid)
  213. {
  214. new targetplayer = GetPlayerTargetPlayer(playerid);
  215. if (targetplayer != npcid)
  216. {
  217. ClearAnimations(npcid);
  218.  
  219. KillTimer(timer_roubo[npcid]);
  220. KillTimer(timer_aimcheck[npcid]);
  221.  
  222. PlayAlarm(npcid);
  223.  
  224. SetTimerEx("RobDelay", FAILROB_INTERVAL*1000, false, "i", npcid);
  225. SetTimerEx("AimCheck2", 100, false, "i", npcid);
  226.  
  227. CallLocalFunction("OnPlayerFailRob", "ii", playerid, npcid);
  228. }
  229. }
  230.  
  231.  
  232. forward AimCheck2(npcid);
  233. public AimCheck2(npcid)
  234. {
  235. ApplyAnimation(npcid,"PED","DUCK_cower",4.1,1,1,1,1,1,1);
  236. PlayAlarm(npcid);
  237. }
  238.  
  239.  
  240. forward RobDelay(npcid);
  241. public RobDelay(npcid)
  242. {
  243. RobNPC[npcid][rnDelay] = 0;
  244. ClearAnimations(npcid);
  245.  
  246. for(new i = 0; i < MAX_PLAYERS; i++)
  247. {
  248. if(IsAlarmOn[i] == npcid)
  249. {
  250. StopAlarm(i);
  251. }
  252. }
  253. }
  254.  
  255.  
  256. forward IntCheck(playerid, npcid);
  257. public IntCheck(playerid, npcid)
  258. {
  259. if(GetPlayerInterior(playerid) != RobNPC[npcid][rnInt])
  260. {
  261. StopAlarm(playerid);
  262. KillTimer(timer_int[playerid]);
  263. }
  264. }
  265.  
  266.  
  267. forward StopAlarm(playerid);
  268. public StopAlarm(playerid)
  269. {
  270. IsAlarmOn[playerid] = 0;
  271. PlayerPlaySound(playerid, 0, 0.0, 0.0, 0.0);
  272. }
  273.  
  274.  
  275.  
  276. // Callbacks SA-MP
  277. public OnPlayerConnect(playerid)
  278. {
  279. #if defined RN_OnPlayerConnect
  280. RN_OnPlayerConnect(playerid);
  281. #endif
  282.  
  283. if (!IsPlayerNPC(playerid)) { PreloadRAnims(playerid); }
  284. return 1;
  285. }
  286.  
  287.  
  288. public OnPlayerDisconnect(playerid, reason)
  289. {
  290. #if defined RN_OnPlayerDisconnect
  291. RN_OnPlayerDisconnect(playerid, reason);
  292. #endif
  293.  
  294. if (!IsPlayerNPC(playerid)) { KillTimer(timer_int[playerid]); }
  295. return 1;
  296. }
  297.  
  298.  
  299. public OnPlayerSpawn(playerid)
  300. {
  301. #if defined RN_OnPlayerSpawn
  302. RN_OnPlayerSpawn(playerid);
  303. #endif
  304.  
  305. // When NPC spawn, paramaters will be seted
  306. if(IsRobNPC(playerid))
  307. {
  308. SetPlayerSkin(playerid, RobNPC[playerid][rnSkin]);
  309. SetPlayerInterior(playerid, RobNPC[playerid][rnInt]);
  310. SetPlayerPos(playerid, RobNPC[playerid][rnX], RobNPC[playerid][rnY], RobNPC[playerid][rnZ]);
  311. SetPlayerFacingAngle(playerid, RobNPC[playerid][rnAng]);
  312. SetPlayerVirtualWorld(playerid, RobNPC[playerid][rnWorld]);
  313.  
  314. PreloadRAnims(playerid);
  315.  
  316. RNPC_SetShootable(playerid, 0);
  317. }
  318. return 1;
  319. }
  320.  
  321.  
  322. public OnPlayerUpdate(playerid)
  323. {
  324. #if defined RN_OnPlayerUpdate
  325. RN_OnPlayerUpdate(playerid);
  326. #endif
  327.  
  328. new targetplayer = GetPlayerTargetPlayer(playerid);
  329. if(IsRobNPC(targetplayer) && !RobNPC[targetplayer][rnDelay] && GetPlayerWeapon(playerid) >= 22 && GetPlayerWeapon(playerid) <= 38)
  330. {
  331. ClearAnimations(targetplayer);
  332. ApplyAnimation(targetplayer,"SHOP","SHP_Rob_HandsUp",4.1,0,1,1,1,0,1);
  333.  
  334. RobNPC[targetplayer][rnDelay] = 1;
  335. RobNPC[targetplayer][rnPlayer] = playerid;
  336.  
  337. timer_roubo[targetplayer] = SetTimerEx("RobP1", 2000, false, "i", targetplayer);
  338. timer_aimcheck[targetplayer] = SetTimerEx("AimCheck", 500, true, "ii", playerid, targetplayer);
  339. }
  340. }
  341.  
  342.  
  343. public OnPlayerDeath(playerid, killerid, reason)
  344. {
  345. #if defined RN_OnPlayerDeath
  346. RN_OnPlayerDeath(playerid, killerid, reason);
  347. #endif
  348.  
  349. if (IsAlarmOn[playerid]) { StopAlarm(playerid); }
  350.  
  351. return 1;
  352. }
  353.  
  354.  
  355.  
  356. // Hooks
  357. #if defined _ALS_OnPlayerUpdate
  358. #undef OnPlayerUpdate
  359. #else
  360. #define _ALS_OnPlayerUpdate
  361. #endif
  362. #define OnPlayerUpdate RN_OnPlayerUpdate
  363. #if defined RN_OnPlayerUpdate
  364. forward RN_OnPlayerUpdate(playerid);
  365. #endif
  366.  
  367.  
  368. #if defined _ALS_OnPlayerConnect
  369. #undef OnPlayerConnect
  370. #else
  371. #define _ALS_OnPlayerConnect
  372. #endif
  373. #define OnPlayerConnect RN_OnPlayerConnect
  374. #if defined RN_OnPlayerConnect
  375. forward RN_OnPlayerConnect(playerid);
  376. #endif
  377.  
  378.  
  379. #if defined _ALS_OnPlayerDisconnect
  380. #undef OnPlayerDisconnect
  381. #else
  382. #define _ALS_OnPlayerDisconnect
  383. #endif
  384. #define OnPlayerDisconnect RN_OnPlayerDisconnect
  385. #if defined RN_OnPlayerDisconnect
  386. forward RN_OnPlayerDisconnect(playerid, reason);
  387. #endif
  388.  
  389.  
  390. #if defined _ALS_OnPlayerSpawn
  391. #undef OnPlayerSpawn
  392. #else
  393. #define _ALS_OnPlayerSpawn
  394. #endif
  395. #define OnPlayerSpawn RN_OnPlayerSpawn
  396. #if defined RN_OnPlayerSpawn
  397. forward RN_OnPlayerSpawn(playerid);
  398. #endif
  399.  
  400.  
  401. #if defined _ALS_OnPlayerDeath
  402. #undef OnPlayerDeath
  403. #else
  404. #define _ALS_OnPlayerDeath
  405. #endif
  406. #define OnPlayerDeath RN_OnPlayerDeath
  407. #if defined RN_OnPlayerDeath
  408. forward RN_OnPlayerDeath(playerid, killerid, reason);
  409. #endif
  410.  
  411.  
  412.  
  413. // Callbacks of include
  414. forward OnPlayerSucessRob(playerid, npcid, value);
  415. forward OnPlayerFailRob(playerid, npcid);
Advertisement
Add Comment
Please, Sign In to add comment