Advertisement
kreison

RNS V2.1 (for RNPC)

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