Advertisement
kreison

RNS V2.1 (for FCNPC)

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