robotmonkey

SA-MP - rTurret Example Filterscript v1.5

Jul 1st, 2015
376
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ================================================================
  2. //  rTurret v1.5 Example Filterscript
  3. //      Created for SA-MP 0.3.4
  4. //      © 2015 by Corekt
  5. // ================================================================
  6.  
  7. #define FILTERSCRIPT
  8. #include <a_samp>
  9. #include <rturret>
  10. #include <zcmd>
  11. #include <sscanf2>
  12.  
  13. public OnFilterScriptInit()
  14. {
  15.     // Add any remove buildings (This only works once)
  16.     //CA_RemoveBuilding();
  17.    
  18.     // Initialize the collision world (This removes any objects and creates the collision world)
  19.     CA_Init();
  20.    
  21.     // Create objects
  22.     //CreateDynamicObject_SC();
  23.  
  24.     return 1;
  25. }
  26.  
  27. public OnPlayerSpawn(playerid)
  28. {
  29.     return 1;
  30. }
  31.  
  32. public OnPlayerDeath(playerid, killerid, reason)
  33. {
  34.     return 1;
  35. }
  36.  
  37. public OnTurretCreate(turretid)
  38. {
  39.     new
  40.         txt[32];
  41.        
  42.     ToggleTurretHealth(turretid, true, 100.0);
  43.     format(txt, sizeof(txt), "Turret %d\nHealth: %.1f", turretid, GetTurretHealth(turretid));
  44.     SetTurretText(turretid, -1, txt);
  45.     return 1;
  46. }
  47.  
  48. public OnTurretDeath(turretid, killerid, weaponid)
  49. {
  50.     new
  51.         Float:x, Float:y, Float:z;
  52.        
  53.     GetTurretPos(turretid, x, y, z);
  54.     CreateExplosion(x, y, z, 12, 10.0);
  55.     return 1;
  56. }
  57.  
  58. public OnTurretHitPlayer(turretid, playerid)
  59. {
  60.     return 1;
  61. }
  62.  
  63. public OnPlayerShootTurret(playerid, weaponid, turretid, Float:fX, Float:fY, Float:fZ)
  64. {
  65.     new
  66.         txt[32];
  67.        
  68.     format(txt, sizeof(txt), "Turret %d\nHealth: %.1f", turretid, GetTurretHealth(turretid));
  69.     SetTurretText(turretid, -1, txt);
  70.     return 1;
  71. }
  72.  
  73. public OnTurretBulletCollision(turretid, Float:x, Float:y, Float:z)
  74. {
  75.     foreach(new i : rTurretPlayersInBigArea[turretid])
  76.         PlayerPlaySound(i, 31803, 0, 0, 0);
  77.        
  78.     return 1;
  79. }
  80.  
  81. CMD:turretcmds(playerid, params[])
  82. {
  83.     SendClientMessage(playerid, -1, "==========rTurret Commands Index==========");
  84.     SendClientMessage(playerid, -1, "/createturret /setturretbehavior /setturretrotspeed /activateturret /activateallturrets /deactivateturret");
  85.     SendClientMessage(playerid, -1, "/deactivateallturrets /toggleturretcheckarea /toggleturretplaysound /toggleturretvisible /toggleturretaim3d");
  86.     SendClientMessage(playerid, -1, "/toggleturretpredictiveaim /setturrettext /setturretrate /destroyturret /destroyallturrets");
  87.     SendClientMessage(playerid, -1, "/toggleturrethealth /toggleturretlos /toggleturretlosaim");
  88.     SendClientMessage(playerid, -1, "==========================================");
  89.     return 1;
  90. }
  91.  
  92. CMD:createturret(playerid, params[])
  93. {
  94.     new
  95.         msg[64],
  96.         turretid,
  97.         Float:range,
  98.         rate, Float:speed, Float:dmg,
  99.         Float:x, Float:y, Float:z, Float:a;
  100.        
  101.     if (sscanf(params, "fdff", range, rate, speed, dmg))
  102.         return SendClientMessage(playerid, -1, "USAGE: /createturret [range] [rate] [speed] [dmg]");
  103.        
  104.     GetPlayerPos(playerid, x, y, z);
  105.     GetPlayerFacingAngle(playerid, a);
  106.     turretid =
  107.         CreateTurret(TURRET_BEHAVIOR_STATIONARY, INVALID_PLAYER_ID,
  108.         x + (2 * floatsin(-a, degrees)), y + (2 * floatcos(-a, degrees)), z - 1, .rz = a + 90, .range = range, .rate = rate, .speed = speed, .dmg = dmg);
  109.     if (turretid != INVALID_TURRET) {
  110.         format(msg, sizeof(msg), "Created Turret %d", turretid);
  111.         SendClientMessage(playerid, -1, msg);
  112.     } else
  113.         SendClientMessage(playerid, -1, "Error; Could not create Turret");
  114.     return 1;
  115. }
  116.  
  117. CMD:setturretbehavior(playerid, params[])
  118. {
  119.     new
  120.         msg[64],
  121.         turretid,
  122.         behavior;
  123.        
  124.     if (sscanf(params, "dd", turretid, behavior) || behavior < 0 || behavior >= TURRET_BEHAVIOR_MAX) {
  125.         format(msg, sizeof(msg), "USAGE: /setturretbehavior [turretid] [behavior (0-%d)]", TURRET_BEHAVIOR_MAX - 1);
  126.         return SendClientMessage(playerid, -1, msg);
  127.     }
  128.        
  129.     if (!IsValidTurret(turretid))
  130.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  131.        
  132.     format(msg, sizeof(msg), "Turret %d behavior set to %d.", turretid, behavior);
  133.     SetTurretBehavior(turretid, behavior);
  134.     SendClientMessage(playerid, -1, msg);
  135.     return 1;
  136. }
  137.  
  138. CMD:setturretrotspeed(playerid, params[])
  139. {
  140.     new
  141.         msg[128],
  142.         turretid,
  143.         Float:speed;
  144.        
  145.     if (sscanf(params, "df", turretid, speed))
  146.         return SendClientMessage(playerid, -1, "USAGE: /setturretrotspeed [turretid] [speed]");
  147.        
  148.     if (!SetTurretRotSpeed(turretid, speed))
  149.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  150.        
  151.     format(msg, sizeof(msg), "Turret %d's rotate speed (for turret rotation behaviors) set to %f", turretid, speed);
  152.     SendClientMessage(playerid, -1, msg);
  153.     return 1;
  154. }
  155.  
  156. CMD:activateturret(playerid, params[])
  157. {
  158.     new
  159.         msg[64],
  160.         turretid;
  161.        
  162.     if (sscanf(params, "d", turretid))
  163.         return SendClientMessage(playerid, -1, "USAGE: /activateturret [turretid]");
  164.        
  165.     if (!IsValidTurret(turretid))
  166.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  167.        
  168.     if (ToggleTurretActive(turretid, 1))
  169.         format(msg, sizeof(msg), "Activated Turret %d.", turretid);
  170.     else
  171.         format(msg, sizeof(msg), "ERROR: Turret %d is already active.", turretid);
  172.        
  173.     SendClientMessage(playerid, -1, msg);
  174.     return 1;
  175. }
  176.  
  177. CMD:activateallturrets(playerid, params[])
  178. {
  179.     new
  180.         count,
  181.         msg[64];
  182.        
  183.     foreach(new i : rTurrets)
  184.         if (ToggleTurretActive(i, 1))
  185.             count++;
  186.            
  187.     format(msg, sizeof(msg), "Activated %d turret(s).", count);
  188.     SendClientMessage(playerid, -1, msg);
  189.     return 1;
  190. }
  191.  
  192. CMD:deactivateturret(playerid, params[])
  193. {
  194.     new
  195.         msg[64],
  196.         turretid;
  197.        
  198.     if (sscanf(params, "d", turretid))
  199.         return SendClientMessage(playerid, -1, "USAGE: /deactivateturret [turretid]");
  200.        
  201.     if (!IsValidTurret(turretid))
  202.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  203.        
  204.     if (ToggleTurretActive(turretid, 0))
  205.         format(msg, sizeof(msg), "Deactivated Turret %d.", turretid);
  206.     else
  207.         format(msg, sizeof(msg), "ERROR: Turret %d is already deactivated.", turretid);
  208.        
  209.     SendClientMessage(playerid, -1, msg);
  210.     return 1;
  211. }
  212.  
  213. CMD:deactivateallturrets(playerid, params[])
  214. {
  215.     new
  216.         count,
  217.         msg[64];
  218.        
  219.     foreach(new i : rTurrets)
  220.         if (ToggleTurretActive(i, 0))
  221.             count++;
  222.            
  223.     format(msg, sizeof(msg), "Deactivated %d turret(s).", count);
  224.     SendClientMessage(playerid, -1, msg);
  225.     return 1;
  226. }
  227.  
  228. CMD:toggleturrethealth(playerid, params[])
  229. {
  230.     new
  231.         msg[128],
  232.         toggle,
  233.         turretid;
  234.        
  235.     if (sscanf(params, "dd", turretid, toggle) || (toggle != 0 && toggle != 1))
  236.         return SendClientMessage(playerid, -1, "USAGE: /toggleturrethealth [turretid] [0/1]");
  237.        
  238.     if (!IsValidTurret(turretid))
  239.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  240.        
  241.     if (ToggleTurretHealth(turretid, toggle))
  242.         format(msg, sizeof(msg), "Successfully toggled Turret Health (%d, Health: %f) for Turret %d.", toggle, GetTurretHealth(turretid), turretid);
  243.     else
  244.         format(msg, sizeof(msg), "ERROR: Could not toggle Turret Health (%d) for Turret %d", toggle, turretid);
  245.        
  246.     SendClientMessage(playerid, -1, msg);
  247.     return 1;
  248. }
  249.  
  250. CMD:toggleturretlos(playerid, params[])
  251. {
  252.     new
  253.         msg[128],
  254.         toggle,
  255.         turretid;
  256.        
  257.     if (sscanf(params, "dd", turretid, toggle) || (toggle != 0 && toggle != 1))
  258.         return SendClientMessage(playerid, -1, "USAGE: /toggleturretlos [turretid] [0/1]");
  259.        
  260.     if (!IsValidTurret(turretid))
  261.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  262.        
  263.     if (ToggleTurretLOS(turretid, toggle))
  264.         format(msg, sizeof(msg), "Successfully toggled Turret LoS (%d) for Turret %d.", toggle, turretid);
  265.     else
  266.         format(msg, sizeof(msg), "ERROR: Could not toggle Turret LoS (%d) for Turret %d", toggle, turretid);
  267.        
  268.     SendClientMessage(playerid, -1, msg);
  269.     return 1;  
  270. }
  271.  
  272. CMD:toggleturretlosaim(playerid, params[])
  273. {
  274.     new
  275.         msg[128],
  276.         toggle,
  277.         turretid;
  278.        
  279.     if (sscanf(params, "dd", turretid, toggle) || (toggle != 0 && toggle != 1))
  280.         return SendClientMessage(playerid, -1, "USAGE: /toggleturretlosaim [turretid] [0/1]");
  281.        
  282.     if (!IsValidTurret(turretid))
  283.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  284.        
  285.     if (ToggleTurretLOSAim(turretid, toggle))
  286.         format(msg, sizeof(msg), "Successfully toggled Turret LoS Aim (%d) for Turret %d.", toggle, turretid);
  287.     else
  288.         format(msg, sizeof(msg), "ERROR: Could not toggle Turret LoS Aim (%d) for Turret %d", toggle, turretid);
  289.        
  290.     SendClientMessage(playerid, -1, msg);
  291.     return 1;
  292. }
  293.  
  294. CMD:toggleturretcheckarea(playerid, params[])
  295. {
  296.     new
  297.         msg[128],
  298.         toggle,
  299.         turretid;
  300.        
  301.     if (sscanf(params, "dd", turretid, toggle) || (toggle != 0 && toggle != 1))
  302.         return SendClientMessage(playerid, -1, "USAGE: /toggleturretcheckarea [turretid] [0/1]");
  303.        
  304.     if (!IsValidTurret(turretid))
  305.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  306.        
  307.     if (ToggleTurretCheckArea(turretid, toggle))
  308.         format(msg, sizeof(msg), "Successfully toggled Turret Check Area (%d) for Turret %d.", toggle, turretid);
  309.     else
  310.         format(msg, sizeof(msg), "ERROR: Could not toggle Turret Check Area (%d) for Turret %d", toggle, turretid);
  311.        
  312.     SendClientMessage(playerid, -1, msg);
  313.     return 1;
  314. }
  315.  
  316. CMD:toggleturretplaysound(playerid, params[])
  317. {
  318.     new
  319.         msg[128],
  320.         toggle,
  321.         turretid;
  322.        
  323.     if (sscanf(params, "dd", turretid, toggle) || (toggle != 0 && toggle != 1))
  324.         return SendClientMessage(playerid, -1, "USAGE: /toggleturretplaysound [turretid] [0/1]");
  325.        
  326.     if (!IsValidTurret(turretid))
  327.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  328.        
  329.     if (ToggleTurretPlaySound(turretid, toggle))
  330.         format(msg, sizeof(msg), "Successfully toggled Turret Sound (%d) for Turret %d.", toggle, turretid);
  331.     else
  332.         format(msg, sizeof(msg), "ERROR: Could not toggle Turret Sound (%d) for Turret %d", toggle, turretid);
  333.        
  334.     SendClientMessage(playerid, -1, msg);
  335.     return 1;
  336. }
  337.  
  338. CMD:toggleturretvisible(playerid, params[])
  339. {
  340.     new
  341.         msg[128],
  342.         toggle,
  343.         turretid;
  344.        
  345.     if (sscanf(params, "dd", turretid, toggle) || (toggle != 0 && toggle != 1))
  346.         return SendClientMessage(playerid, -1, "USAGE: /toggleturretvisible [turretid] [0/1]");
  347.        
  348.     if (!IsValidTurret(turretid))
  349.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  350.        
  351.     if (ToggleTurretVisible(turretid, toggle))
  352.         format(msg, sizeof(msg), "Successfully toggled Turret Visibility (%d) for Turret %d.", toggle, turretid);
  353.     else
  354.         format(msg, sizeof(msg), "ERROR: Could not toggle Turret Visibility (%d) for Turret %d", toggle, turretid);
  355.        
  356.     SendClientMessage(playerid, -1, msg);
  357.     return 1;
  358. }
  359.  
  360. CMD:toggleturretaim3d(playerid, params[])
  361. {
  362.     new
  363.         msg[128],
  364.         toggle,
  365.         turretid;
  366.        
  367.     if (sscanf(params, "dd", turretid, toggle) || (toggle != 0 && toggle != 1))
  368.         return SendClientMessage(playerid, -1, "USAGE: /toggleturretaim3d [turretid] [0/1]");
  369.        
  370.     if (!IsValidTurret(turretid))
  371.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  372.        
  373.     if (ToggleTurretAim3dSpace(turretid, toggle))
  374.         format(msg, sizeof(msg), "Successfully toggled Turret Aim 3D Space (%d) for Turret %d.", toggle, turretid);
  375.     else
  376.         format(msg, sizeof(msg), "ERROR: Could not toggle Turret Aim 3D Space (%d) for Turret %d", toggle, turretid);
  377.        
  378.     SendClientMessage(playerid, -1, msg);
  379.     return 1;
  380. }
  381.  
  382. CMD:toggleturretpredictiveaim(playerid, params[])
  383. {
  384.     new
  385.         msg[128],
  386.         toggle,
  387.         turretid;
  388.        
  389.     if (sscanf(params, "dd", turretid, toggle) || (toggle != 0 && toggle != 1))
  390.         return SendClientMessage(playerid, -1, "USAGE: /toggleturretpredictiveaim [turretid] [0/1]");
  391.        
  392.     if (!IsValidTurret(turretid))
  393.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  394.        
  395.     if (ToggleTurretPredictiveAim(turretid, toggle))
  396.         format(msg, sizeof(msg), "Successfully toggled Turret Predictive Aim (%d) for Turret %d.", toggle, turretid);
  397.     else
  398.         format(msg, sizeof(msg), "ERROR: Could not toggle Turret Predictive Aim (%d) for Turret %d", toggle, turretid);
  399.        
  400.     SendClientMessage(playerid, -1, msg);
  401.     return 1;
  402. }
  403.  
  404. CMD:setturrettext(playerid, params[])
  405. {
  406.     new
  407.         color,
  408.         msg[128],
  409.         turretid,
  410.         text[64];
  411.        
  412.     if (sscanf(params, "dds[64]", turretid, color, text))
  413.         return SendClientMessage(playerid, -1, "USAGE: /setturrettext [turretid] [color] [text]");
  414.        
  415.     if (!SetTurretText(turretid, color, text))
  416.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  417.     else {
  418.         format(msg, sizeof(msg), "Turret %d text (color: %d) set to %s", turretid, color, text);
  419.         SendClientMessage(playerid, color, msg);
  420.     }
  421.     return 1;
  422. }
  423.  
  424. CMD:setturretrate(playerid, params[])
  425. {
  426.     new
  427.         rate,
  428.         msg[64],
  429.         turretid;
  430.        
  431.     if (sscanf(params, "dd", turretid, rate))
  432.         return SendClientMessage(playerid, -1, "USAGE: /setturretrate [turretid] [rate]");
  433.        
  434.     if (!SetTurretFireRate(turretid, rate))
  435.         return SendClientMessage(playerid, -1, "ERROR: Invalid turret.");
  436.     else {
  437.         format(msg, sizeof(msg), "Turret %d's fire rate set to %d", turretid, rate);
  438.         SendClientMessage(playerid, -1, msg);
  439.     }
  440.     return 1;
  441. }
  442.  
  443. CMD:destroyturret(playerid, params[])
  444. {
  445.     new
  446.         msg[64],
  447.         turretid;
  448.        
  449.     if (sscanf(params, "d", turretid))
  450.         return SendClientMessage(playerid, -1, "USAGE: /destroyturret [turret ID]");
  451.        
  452.     if (DestroyTurret(turretid))
  453.         format(msg, sizeof(msg), "Destroyed Turret %d", turretid);
  454.     else
  455.         format(msg, sizeof(msg), "ERROR: Could not destroy Turret %d", turretid);
  456.        
  457.     SendClientMessage(playerid, -1, msg);
  458.     return 1;
  459. }
  460.  
  461. CMD:destroyallturrets(playerid, params[])
  462. {
  463.     new
  464.         next,
  465.         count,
  466.         msg[64];
  467.        
  468.     foreach(new i : rTurrets) {
  469.         if (DestroyTurret(i, next)) {
  470.             count++;
  471.             i = next;
  472.         }
  473.     }
  474.     format(msg, sizeof(msg), "Destroyed %d turrets.", count);
  475.     SendClientMessage(playerid, -1, msg);
  476.     return 1;
  477. }
RAW Paste Data