Advertisement
Guest User

Dynamic Robberies

a guest
May 19th, 2016
2,147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 29.22 KB | None | 0 0
  1. #define     FILTERSCRIPT
  2. #include    <a_samp>
  3. #include    <streamer>      // by Incognito - http://forum.sa-mp.com/showthread.php?t=102865
  4. #include    <sqlitei>       // by Slice - http://forum.sa-mp.com/showthread.php?t=303682
  5. #include    <izcmd>         // by Yashas - http://forum.sa-mp.com/showthread.php?t=576114
  6.  
  7. #define     MAX_ROBBERIES       (40)
  8. #define     ATTACH_INDEX        (4)     // required for SetPlayerAttachedObject
  9. #define     PLACE_COOLDOWN      (3)     // a robbery place can't be robbed again for x minutes (Default: 3)
  10.  
  11. enum    _:E_ROBBERY_DIALOG
  12. {
  13.     DIALOG_ROBBERY = 10350,
  14.     // admin
  15.     DIALOG_ADD_ROBBERY_1,
  16.     DIALOG_ADD_ROBBERY_2,
  17.     DIALOG_ADD_ROBBERY_3,
  18.     DIALOG_ADD_ROBBERY_FINAL,
  19.     DIALOG_REMOVE_ROBBERY
  20. }
  21.  
  22. enum    E_ROBBERY
  23. {
  24.     // robbery name
  25.     Name[32],
  26.     // pos data
  27.     Float: PosX,
  28.     Float: PosY,
  29.     Float: PosZ,
  30.     IntID,
  31.     VWID,
  32.     // robbery data
  33.     Amount,
  34.     ReqTime,
  35.     SafeTime,
  36.     // record
  37.     RecordAmount,
  38.     RecordBy[MAX_PLAYER_NAME],
  39.     // temp
  40.     OccupiedBy,
  41.     Cooldown,
  42.     Timer,
  43.     Checkpoint,
  44.     Text3D: Label,
  45.     bool: Exists
  46. }
  47.  
  48. enum    _:E_ROBBERY_STAGE
  49. {
  50.     STAGE_CRACKING,
  51.     STAGE_OPENING,
  52.     STAGE_ROBBING
  53. }
  54.  
  55. enum    E_PLAYER_ROBBERY
  56. {
  57.     SafeObject[2],
  58.     MoneyStolen,
  59.     RobID,
  60.     RobTime,
  61.     RobStage,
  62.     RobberyTimer
  63. }
  64.  
  65. new
  66.     RobberyData[MAX_ROBBERIES][E_ROBBERY];
  67.    
  68. new
  69.     PlayerRobberyData[MAX_PLAYERS][E_PLAYER_ROBBERY],
  70.     PlayerText: RobberyText[MAX_PLAYERS] = {PlayerText: -1, ...};
  71.    
  72. new
  73.     DB: RobberyDatabase,
  74.     DBStatement: LoadRobberies,
  75.     DBStatement: AddRobbery,
  76.     DBStatement: UpdateRecord,
  77.     DBStatement: RemoveRobbery;
  78.  
  79. formatInt(intVariable, iThousandSeparator = ',', iCurrencyChar = '$')
  80. {
  81.     /*
  82.         By Kar
  83.         https://gist.github.com/Kar2k/bfb0eafb2caf71a1237b349684e091b9/8849dad7baa863afb1048f40badd103567c005a5#file-formatint-function
  84.     */
  85.     static
  86.         s_szReturn[ 32 ],
  87.         s_szThousandSeparator[ 2 ] = { ' ', EOS },
  88.         s_szCurrencyChar[ 2 ] = { ' ', EOS },
  89.         s_iVariableLen,
  90.         s_iChar,
  91.         s_iSepPos,
  92.         bool:s_isNegative
  93.     ;
  94.  
  95.     format( s_szReturn, sizeof( s_szReturn ), "%d", intVariable );
  96.  
  97.     if(s_szReturn[0] == '-')
  98.         s_isNegative = true;
  99.     else
  100.         s_isNegative = false;
  101.  
  102.     s_iVariableLen = strlen( s_szReturn );
  103.  
  104.     if ( s_iVariableLen >= 4 && iThousandSeparator)
  105.     {
  106.         s_szThousandSeparator[ 0 ] = iThousandSeparator;
  107.  
  108.         s_iChar = s_iVariableLen;
  109.         s_iSepPos = 0;
  110.  
  111.         while ( --s_iChar > _:s_isNegative )
  112.         {
  113.             if ( ++s_iSepPos == 3 )
  114.             {
  115.                 strins( s_szReturn, s_szThousandSeparator, s_iChar );
  116.  
  117.                 s_iSepPos = 0;
  118.             }
  119.         }
  120.     }
  121.     if(iCurrencyChar) {
  122.         s_szCurrencyChar[ 0 ] = iCurrencyChar;
  123.         strins( s_szReturn, s_szCurrencyChar, _:s_isNegative );
  124.     }
  125.     return s_szReturn;
  126. }
  127.  
  128. RandomEx(min, max) //Y_Less
  129.     return random(max - min) + min;
  130.  
  131. ConvertToMinutes(time)
  132. {
  133.     // http://forum.sa-mp.com/showpost.php?p=3223897&postcount=11
  134.     new string[15];//-2000000000:00 could happen, so make the string 15 chars to avoid any errors
  135.     format(string, sizeof(string), "%02d:%02d", time / 60, time % 60);
  136.     return string;
  137. }
  138.  
  139. Robbery_FindFreeID()
  140. {
  141.     for(new i; i < MAX_ROBBERIES; i++) if(!RobberyData[i][Exists]) return i;
  142.     return -1;
  143. }
  144.  
  145. Robbery_Cooldown(id)
  146. {
  147.     RobberyData[id][Cooldown] = PLACE_COOLDOWN * 60;
  148.     RobberyData[id][Timer] = SetTimerEx("ResetPlace", 1000, true, "i", id);
  149.    
  150.     new string[160];
  151.     format(string, sizeof(string), "Robbery(%d)\n\n{FFFFFF}%s\n{2ECC71}%s - %s {FFFFFF}every {F1C40F}5 {FFFFFF}seconds.\n{E74C3C}Available in %s", id, RobberyData[id][Name], formatInt(floatround(RobberyData[id][Amount] / 4)), formatInt(RobberyData[id][Amount]), ConvertToMinutes(RobberyData[id][Cooldown]));
  152.     UpdateDynamic3DTextLabelText(RobberyData[id][Label], 0xF1C40FFF, string);
  153.     return 1;
  154. }
  155.  
  156. Robbery_InitPlayer(playerid)
  157. {
  158.     PlayerRobberyData[playerid][SafeObject][0] = PlayerRobberyData[playerid][SafeObject][1] = PlayerRobberyData[playerid][RobID] = PlayerRobberyData[playerid][RobberyTimer] = -1;
  159.     PlayerRobberyData[playerid][MoneyStolen] = PlayerRobberyData[playerid][RobTime] = PlayerRobberyData[playerid][RobStage] = 0;
  160.    
  161.     RobberyText[playerid] = CreatePlayerTextDraw(playerid, 40.000000, 295.000000, "_");
  162.     PlayerTextDrawBackgroundColor(playerid, RobberyText[playerid], 255);
  163.     PlayerTextDrawFont(playerid, RobberyText[playerid], 1);
  164.     PlayerTextDrawLetterSize(playerid, RobberyText[playerid], 0.240000, 1.100000);
  165.     PlayerTextDrawColor(playerid, RobberyText[playerid], -1);
  166.     PlayerTextDrawSetOutline(playerid, RobberyText[playerid], 1);
  167.     PlayerTextDrawSetProportional(playerid, RobberyText[playerid], 1);
  168.     PlayerTextDrawSetSelectable(playerid, RobberyText[playerid], 0);
  169.    
  170.     SetPVarInt(playerid, "robberyID", -1);
  171.    
  172.     // preload anims
  173.     ApplyAnimation(playerid, "COP_AMBIENT", "null", 0.0, 0, 0, 0, 0, 0);
  174.     ApplyAnimation(playerid, "ROB_BANK", "null", 0.0, 0, 0, 0, 0, 0);
  175.     return 1;
  176. }
  177.  
  178. Robbery_ResetPlayer(playerid, check = 0)
  179. {
  180.     new id = PlayerRobberyData[playerid][RobID];
  181.     if(check && id != -1 && PlayerRobberyData[playerid][MoneyStolen] > 0) Robbery_Cooldown(id);
  182.     if(id != -1 && RobberyData[id][OccupiedBy] == playerid) RobberyData[id][OccupiedBy] = -1;
  183.  
  184.     for(new i; i < 2; i++) if(IsValidDynamicObject(PlayerRobberyData[playerid][SafeObject][i])) DestroyDynamicObject(PlayerRobberyData[playerid][SafeObject][i]);
  185.     KillTimer(PlayerRobberyData[playerid][RobberyTimer]);
  186.     RemovePlayerAttachedObject(playerid, ATTACH_INDEX);
  187.     if(!IsPlayerInAnyVehicle(playerid)) ClearAnimations(playerid);
  188.     PlayerTextDrawHide(playerid, RobberyText[playerid]);
  189.     Streamer_Update(playerid);
  190.    
  191.     PlayerRobberyData[playerid][SafeObject][0] = PlayerRobberyData[playerid][SafeObject][1] = PlayerRobberyData[playerid][RobberyTimer] = -1;
  192.     PlayerRobberyData[playerid][MoneyStolen] = PlayerRobberyData[playerid][RobTime] = PlayerRobberyData[playerid][RobStage] = 0;
  193.    
  194.     SetPVarInt(playerid, "robberyID", -1);
  195.     return 1;
  196. }
  197.  
  198. public OnFilterScriptInit()
  199. {
  200.     print("  [Robberies] Initializing...");
  201.     for(new i, mp = GetPlayerPoolSize(); i <= mp; i++) if(IsPlayerConnected(i)) Robbery_InitPlayer(i);
  202.     for(new i; i < MAX_ROBBERIES; i++)
  203.     {
  204.         RobberyData[i][OccupiedBy] = RobberyData[i][Timer] = RobberyData[i][Checkpoint] = -1;
  205.         RobberyData[i][Label] = Text3D: -1;
  206.     }
  207.    
  208.     // Open Database
  209.     RobberyDatabase = db_open("robbery_db.db");
  210.     db_query(RobberyDatabase, "CREATE TABLE IF NOT EXISTS robberies (ID INTEGER, Name TEXT, PosX FLOAT, PosY FLOAT, PosZ FLOAT, Interior INTEGER, Virtual INTEGER, Amount INTEGER, RequiredTime INTEGER, SafeTime INTEGER, RecAmount INTEGER, RecBy TEXT)");
  211.    
  212.     // Prepare Statements
  213.     LoadRobberies = db_prepare(RobberyDatabase, "SELECT * FROM robberies");
  214.     AddRobbery = db_prepare(RobberyDatabase, "INSERT INTO robberies (ID, Name, PosX, PosY, PosZ, Interior, Virtual, Amount, RequiredTime, SafeTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
  215.     UpdateRecord = db_prepare(RobberyDatabase, "UPDATE robberies SET RecAmount=?, RecBy=? WHERE ID=?");
  216.     RemoveRobbery = db_prepare(RobberyDatabase, "DELETE FROM robberies WHERE ID=?");
  217.    
  218.     // Load Robberies
  219.     new id, name[32], Float: pos[3], intid, vwid, amount, reqt, safet, recamount, recby[MAX_PLAYER_NAME];
  220.     stmt_bind_result_field(LoadRobberies, 0, DB::TYPE_INTEGER, id);
  221.     stmt_bind_result_field(LoadRobberies, 1, DB::TYPE_STRING, name, 32);
  222.     stmt_bind_result_field(LoadRobberies, 2, DB::TYPE_FLOAT, pos[0]);
  223.     stmt_bind_result_field(LoadRobberies, 3, DB::TYPE_FLOAT, pos[1]);
  224.     stmt_bind_result_field(LoadRobberies, 4, DB::TYPE_FLOAT, pos[2]);
  225.     stmt_bind_result_field(LoadRobberies, 5, DB::TYPE_INTEGER, intid);
  226.     stmt_bind_result_field(LoadRobberies, 6, DB::TYPE_INTEGER, vwid);
  227.     stmt_bind_result_field(LoadRobberies, 7, DB::TYPE_INTEGER, amount);
  228.     stmt_bind_result_field(LoadRobberies, 8, DB::TYPE_INTEGER, reqt);
  229.     stmt_bind_result_field(LoadRobberies, 9, DB::TYPE_INTEGER, safet);
  230.     stmt_bind_result_field(LoadRobberies, 10, DB::TYPE_INTEGER, recamount);
  231.     stmt_bind_result_field(LoadRobberies, 11, DB::TYPE_STRING, recby, MAX_PLAYER_NAME);
  232.  
  233.     if(stmt_execute(LoadRobberies))
  234.     {
  235.         print("  [Robberies] Loading robbery data...");
  236.  
  237.         new label[160], loaded;
  238.         while(stmt_fetch_row(LoadRobberies))
  239.         {
  240.             RobberyData[id][Name] = name;
  241.            
  242.             RobberyData[id][PosX] = pos[0];
  243.             RobberyData[id][PosY] = pos[1];
  244.             RobberyData[id][PosZ] = pos[2];
  245.             RobberyData[id][IntID] = intid;
  246.             RobberyData[id][VWID] = vwid;
  247.            
  248.             RobberyData[id][Amount] = amount;
  249.             RobberyData[id][ReqTime] = reqt;
  250.             RobberyData[id][SafeTime] = safet;
  251.            
  252.             RobberyData[id][RecordAmount] = 0;
  253.             RobberyData[id][RecordBy] = recby;
  254.            
  255.             RobberyData[id][Checkpoint] = CreateDynamicCP(pos[0], pos[1], pos[2], 1.25, vwid, intid, .streamdistance = 5.0);
  256.  
  257.             format(label, sizeof(label), "Robbery(%d)\n\n{FFFFFF}%s\n{2ECC71}%s - %s {FFFFFF}every {F1C40F}5 {FFFFFF}seconds.\n{2ECC71}Available", id, name, formatInt(floatround(amount / 4)), formatInt(amount));
  258.             RobberyData[id][Label] = CreateDynamic3DTextLabel(label, 0xF1C40FFF, pos[0], pos[1], pos[2] + 0.25, 10.0, _, _, 1, vwid, intid);
  259.            
  260.             RobberyData[id][Exists] = true;
  261.             loaded++;
  262.         }
  263.  
  264.         printf("  [Robberies] Loaded %d robberies.", loaded);
  265.     }
  266.    
  267.     return 1;
  268. }
  269.  
  270. public OnFilterScriptExit()
  271. {
  272.     for(new i, mp = GetPlayerPoolSize(); i <= mp; i++)
  273.     {
  274.         if(!IsPlayerConnected(i)) continue;
  275.         Robbery_ResetPlayer(i);
  276.         PlayerTextDrawDestroy(i, RobberyText[i]);
  277.     }
  278.    
  279.     db_close(RobberyDatabase);
  280.     print("  [Robberies] Unloaded.");
  281.     return 1;
  282. }
  283.  
  284. public OnPlayerConnect(playerid)
  285. {
  286.     Robbery_InitPlayer(playerid);
  287.     return 1;
  288. }
  289.  
  290. public OnPlayerDisconnect(playerid, reason)
  291. {
  292.     Robbery_ResetPlayer(playerid);
  293.     return 1;
  294. }
  295.  
  296. public OnPlayerDeath(playerid, killerid, reason)
  297. {
  298.     if(IsPlayerConnected(killerid) && PlayerRobberyData[playerid][MoneyStolen] > 0)
  299.     {
  300.         new string[144], name[MAX_PLAYER_NAME];
  301.         GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  302.         format(string, sizeof(string), "[ROBBERY] {FFFFFF}You killed the robber {F1C40F}%s(%d) {FFFFFF}and took the money they stole. {2ECC71}(%s)", name, playerid, formatInt(PlayerRobberyData[playerid][MoneyStolen]));
  303.         SendClientMessage(killerid, 0x3498DBFF, string);
  304.        
  305.         Robbery_Cooldown(PlayerRobberyData[playerid][RobID]);
  306.     }
  307.    
  308.     Robbery_ResetPlayer(playerid);
  309.     return 1;
  310. }
  311.  
  312. public OnPlayerStateChange(playerid, newstate, oldstate)
  313. {
  314.     if(newstate != PLAYER_STATE_WASTED) Robbery_ResetPlayer(playerid);
  315.     return 1;
  316. }
  317.  
  318. #define PRESSED(%0) \
  319.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  320.  
  321. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  322. {
  323.     if(PRESSED(KEY_NO) && PlayerRobberyData[playerid][RobberyTimer] != -1) Robbery_ResetPlayer(playerid, 1);
  324.     return 1;
  325. }
  326.  
  327. public OnPlayerEnterDynamicCP(playerid, checkpointid)
  328. {
  329.     if(!IsPlayerInAnyVehicle(playerid))
  330.     {
  331.         for(new i; i < MAX_ROBBERIES; i++)
  332.         {
  333.             if(!RobberyData[i][Exists]) continue;
  334.             if(checkpointid == RobberyData[i][Checkpoint])
  335.             {
  336.                 SetPVarInt(playerid, "robberyID", i);
  337.  
  338.                 if(!IsPlayerConnected(RobberyData[i][OccupiedBy]) && RobberyData[i][Timer] == -1)
  339.                 {
  340.                     new title[64];
  341.                     format(title, sizeof(title), "{F1C40F}Robbery: {FFFFFF}%s", RobberyData[i][Name]);
  342.                     ShowPlayerDialog(playerid, DIALOG_ROBBERY, DIALOG_STYLE_MSGBOX, title, "Do you want to rob this place?", "Rob", "Close");
  343.                 }
  344.  
  345.                 break;
  346.             }
  347.         }
  348.     }
  349.    
  350.     return 1;
  351. }
  352.  
  353. public OnPlayerLeaveDynamicCP(playerid, checkpointid)
  354. {
  355.     if(PlayerRobberyData[playerid][RobberyTimer] != -1)
  356.     {
  357.         if(PlayerRobberyData[playerid][MoneyStolen] > 0)
  358.         {
  359.             new id = PlayerRobberyData[playerid][RobID];
  360.             if(id != -1) Robbery_Cooldown(id);
  361.            
  362.             new string[128];
  363.             format(string, sizeof(string), "~n~~n~~n~~b~~h~~h~Robbery Cancelled~n~~w~Money Stolen: ~g~~h~~h~%s", formatInt(PlayerRobberyData[playerid][MoneyStolen]));
  364.             GameTextForPlayer(playerid, string, 3000, 3);
  365.             GivePlayerMoney(playerid, PlayerRobberyData[playerid][MoneyStolen]);
  366.         }
  367.        
  368.         Robbery_ResetPlayer(playerid);
  369.     }
  370.    
  371.     SetPVarInt(playerid, "robberyID", -1);
  372.     return 1;
  373. }
  374.  
  375. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  376. {
  377.     switch(dialogid)
  378.     {
  379.         /* ---------------------------------------------------------------------- */
  380.         case DIALOG_ROBBERY:
  381.         {
  382.             if(!response) return 1;
  383.             if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You can't do this in a vehicle.");
  384.             new id = GetPVarInt(playerid, "robberyID");
  385.             if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in a robbery checkpoint.");
  386.             if(IsPlayerConnected(RobberyData[id][OccupiedBy])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}This robbery place is occupied.");
  387.             if(!IsPlayerInDynamicCP(playerid, RobberyData[id][Checkpoint])) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in the robbery checkpoint.");
  388.             new Float: x, Float: y, Float: z, Float: a;
  389.             GetPlayerPos(playerid, x, y, z);
  390.             GetPlayerFacingAngle(playerid, a);
  391.            
  392.             x += (1.25 * floatsin(-a, degrees));
  393.             y += (1.25 * floatcos(-a, degrees));
  394.             PlayerRobberyData[playerid][SafeObject][0] = CreateDynamicObject(19618, x, y, z-0.55, 0.0, 0.0, a, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid));
  395.  
  396.             a += 90.0;
  397.             x += (0.42 * floatsin(-a, degrees)) + (-0.22 * floatsin(-(a - 90.0), degrees));
  398.             y += (0.42 * floatcos(-a, degrees)) + (-0.22 * floatcos(-(a - 90.0), degrees));
  399.             PlayerRobberyData[playerid][SafeObject][1] = CreateDynamicObject(19619, x, y, z-0.55, 0.0, 0.0, a + 270.0, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid));
  400.            
  401.             PlayerRobberyData[playerid][MoneyStolen] = 0;
  402.             PlayerRobberyData[playerid][RobID] = id;
  403.             PlayerRobberyData[playerid][RobTime] = RobberyData[id][SafeTime];
  404.             PlayerRobberyData[playerid][RobStage] = STAGE_CRACKING;
  405.             PlayerRobberyData[playerid][RobberyTimer] = SetTimerEx("Robbery", 1000, true, "ii", playerid, id);
  406.             RobberyData[id][OccupiedBy] = playerid;
  407.            
  408.             SetPlayerAttachedObject(playerid, ATTACH_INDEX, 18634, 6, 0.054000, 0.013999, -0.087999, -94.399963, -25.899974, 175.799911);
  409.             ApplyAnimation(playerid, "COP_AMBIENT", "COPBROWSE_LOOP", 4.0, 1, 0, 0, 0, 0);
  410.            
  411.             new string[128];
  412.             format(string, sizeof(string), "~b~~h~Robbery~n~~n~~w~Cracking safe...~n~Complete in ~r~%s", ConvertToMinutes(RobberyData[id][SafeTime]));
  413.             PlayerTextDrawSetString(playerid, RobberyText[playerid], string);
  414.             PlayerTextDrawShow(playerid, RobberyText[playerid]);
  415.            
  416.             if(RobberyData[id][RecordAmount] > 0)
  417.             {
  418.                 format(string, sizeof(string), "[ROBBERY] {F1C40F}%s {FFFFFF}holds the record for this place with {2ECC71}%s {FFFFFF}stolen.", RobberyData[id][RecordBy], formatInt(RobberyData[id][RecordAmount]));
  419.                 SendClientMessage(playerid, 0x3498DBFF, string);
  420.             }
  421.            
  422.             SendClientMessage(playerid, 0x3498DBFF, "[ROBBERY] {FFFFFF}You can press {F1C40F}~k~~CONVERSATION_NO~ {FFFFFF}to cancel the robbery.");
  423.             Streamer_Update(playerid);
  424.             return 1;
  425.         }
  426.         /* ---------------------------------------------------------------------- */
  427.         case DIALOG_ADD_ROBBERY_1:
  428.         {
  429.             if(!IsPlayerAdmin(playerid) || !response) return 1;
  430.             if(isnull(inputtext)) return ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_1, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 1)", "{E74C3C}Input can't be empty.\n\n{FFFFFF}Write a name for the robbery:", "Next", "Close");
  431.             SetPVarString(playerid, "robberyName", inputtext);
  432.             ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_2, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 2)", "Safe cracking duration (in seconds):", "Next", "Back");
  433.             return 1;
  434.         }
  435.         /* ---------------------------------------------------------------------- */
  436.         case DIALOG_ADD_ROBBERY_2:
  437.         {
  438.             if(!IsPlayerAdmin(playerid)) return 1;
  439.             if(!response) return ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_1, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 1)", "Write a name for the robbery:", "Next", "Close");
  440.             if(isnull(inputtext)) return ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_2, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 2)", "{E74C3C}Input can't be empty.\n\n{FFFFFF}Safe cracking duration (in seconds):", "Next", "Back");
  441.             SetPVarInt(playerid, "robberySafeDur", strval(inputtext));
  442.             ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_3, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 3)", "Robbery duration (in seconds - must be multiples of 5):", "Next", "Back");
  443.             return 1;
  444.         }
  445.         /* ---------------------------------------------------------------------- */
  446.         case DIALOG_ADD_ROBBERY_3:
  447.         {
  448.             if(!IsPlayerAdmin(playerid)) return 1;
  449.             if(!response) return ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_2, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 2)", "Safe cracking duration (in seconds):", "Next", "Back");
  450.             if(isnull(inputtext)) return ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_3, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 3)", "{E74C3C}Input can't be empty.\n\n{FFFFFF}Robbery duration (in seconds - must be multiples of 5):", "Next", "Back");
  451.             new dur = strval(inputtext);
  452.             if(dur < 1 || (dur % 5) != 0) return ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_3, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 3)", "{E74C3C}Invalid duration.\n\n{FFFFFF}Robbery duration (in seconds - must be multiples of 5):", "Next", "Back");
  453.             SetPVarInt(playerid, "robberyDur", dur);
  454.             ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_FINAL, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 4)", "Money amount:", "Finish", "Back");
  455.             return 1;
  456.         }
  457.         /* ---------------------------------------------------------------------- */
  458.         case DIALOG_ADD_ROBBERY_FINAL:
  459.         {
  460.             if(!IsPlayerAdmin(playerid)) return 1;
  461.             if(!response) return ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_3, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 3)", "Robbery duration (in seconds - must be multiples of 5):", "Next", "Back");
  462.             if(isnull(inputtext)) return ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_FINAL, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 4)", "{E74C3C}Input can't be empty.\n\n{FFFFFF}Money amount:", "Finish", "Back");
  463.             if(strval(inputtext) < 1) return ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_FINAL, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 4)", "{E74C3C}Invalid amount.\n\n{FFFFFF}Money amount:", "Finish", "Back");
  464.  
  465.             new id = Robbery_FindFreeID();
  466.             if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Can't create any more robberies.");
  467.             new Float: x, Float: y, Float: z, vwid = GetPlayerVirtualWorld(playerid), intid = GetPlayerInterior(playerid), string[160];
  468.             GetPlayerPos(playerid, x, y, z);
  469.  
  470.             GetPVarString(playerid, "robberyName", RobberyData[id][Name], 32);
  471.             RobberyData[id][PosX] = x;
  472.             RobberyData[id][PosY] = y;
  473.             RobberyData[id][PosZ] = z;
  474.             RobberyData[id][IntID] = intid;
  475.             RobberyData[id][VWID] = vwid;
  476.             RobberyData[id][Amount] = strval(inputtext);
  477.             RobberyData[id][ReqTime] = GetPVarInt(playerid, "robberyDur");
  478.             RobberyData[id][SafeTime] = GetPVarInt(playerid, "robberySafeDur");
  479.             RobberyData[id][RecordAmount] = 0;
  480.             RobberyData[id][RecordBy][0] = EOS;
  481.            
  482.             RobberyData[id][OccupiedBy] = -1;
  483.             RobberyData[id][Cooldown] = 0;
  484.             RobberyData[id][Timer] = -1;
  485.            
  486.             RobberyData[id][Checkpoint] = CreateDynamicCP(x, y, z, 1.25, vwid, intid, .streamdistance = 5.0);
  487.  
  488.             format(string, sizeof(string), "Robbery(%d)\n\n{FFFFFF}%s\n{2ECC71}%s - %s {FFFFFF}every {F1C40F}5 {FFFFFF}seconds.\n{2ECC71}Available", id, RobberyData[id][Name], formatInt(floatround(RobberyData[id][Amount] / 4)), formatInt(RobberyData[id][Amount]));
  489.             RobberyData[id][Label] = CreateDynamic3DTextLabel(string, 0xF1C40FFF, x, y, z + 0.25, 10.0, _, _, 1, vwid, intid);
  490.            
  491.             RobberyData[id][Exists] = true;
  492.  
  493.             stmt_bind_value(AddRobbery, 0, DB::TYPE_INTEGER, id);
  494.             stmt_bind_value(AddRobbery, 1, DB::TYPE_STRING, RobberyData[id][Name], 32);
  495.             stmt_bind_value(AddRobbery, 2, DB::TYPE_FLOAT, x);
  496.             stmt_bind_value(AddRobbery, 3, DB::TYPE_FLOAT, y);
  497.             stmt_bind_value(AddRobbery, 4, DB::TYPE_FLOAT, z);
  498.             stmt_bind_value(AddRobbery, 5, DB::TYPE_INTEGER, intid);
  499.             stmt_bind_value(AddRobbery, 6, DB::TYPE_INTEGER, vwid);
  500.             stmt_bind_value(AddRobbery, 7, DB::TYPE_INTEGER, RobberyData[id][Amount]);
  501.             stmt_bind_value(AddRobbery, 8, DB::TYPE_INTEGER, RobberyData[id][ReqTime]);
  502.             stmt_bind_value(AddRobbery, 9, DB::TYPE_INTEGER, RobberyData[id][SafeTime]);
  503.             if(stmt_execute(AddRobbery)) SendClientMessage(playerid, 0x3498DBFF, "[ROBBERY] {FFFFFF}Robbery created.");
  504.             return 1;
  505.         }
  506.         /* ---------------------------------------------------------------------- */
  507.         case DIALOG_REMOVE_ROBBERY:
  508.         {
  509.             if(!IsPlayerAdmin(playerid) || !response) return 1;
  510.             new id = strval(inputtext);
  511.             if(!RobberyData[id][Exists]) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Robbery doesn't exist.");
  512.             for(new i, mp = GetPlayerPoolSize(); i <= mp; i++)
  513.             {
  514.                 if(!IsPlayerConnected(i)) continue;
  515.                 if(PlayerRobberyData[i][RobID] == id) Robbery_ResetPlayer(i);
  516.             }
  517.            
  518.             if(RobberyData[id][Timer] != -1) KillTimer(RobberyData[id][Timer]);
  519.             DestroyDynamicCP(RobberyData[id][Checkpoint]);
  520.             DestroyDynamic3DTextLabel(RobberyData[id][Label]);
  521.            
  522.             RobberyData[id][OccupiedBy] = RobberyData[id][Timer] = RobberyData[id][Checkpoint] = -1;
  523.             RobberyData[id][Label] = Text3D: -1;
  524.             RobberyData[id][Exists] = false;
  525.            
  526.             stmt_bind_value(RemoveRobbery, 0, DB::TYPE_INTEGER, id);
  527.             if(stmt_execute(RemoveRobbery)) SendClientMessage(playerid, 0x3498DBFF, "[ROBBERY] {FFFFFF}Robbery removed.");
  528.             return 1;
  529.         }
  530.         /* ---------------------------------------------------------------------- */
  531.     }
  532.    
  533.     return 0;
  534. }
  535.  
  536. forward Robbery(playerid, id);
  537. public Robbery(playerid, id)
  538. {
  539.     new string[128];
  540.     if(PlayerRobberyData[playerid][RobTime] > 1) {
  541.         PlayerRobberyData[playerid][RobTime]--;
  542.  
  543.         switch(PlayerRobberyData[playerid][RobStage])
  544.         {
  545.             case STAGE_CRACKING:
  546.             {
  547.                 format(string, sizeof(string), "~b~~h~Robbery~n~~n~~w~Cracking safe...~n~Complete in ~r~%s", ConvertToMinutes(PlayerRobberyData[playerid][RobTime]));
  548.                 PlayerTextDrawSetString(playerid, RobberyText[playerid], string);
  549.             }
  550.            
  551.             case STAGE_OPENING:
  552.             {
  553.                 format(string, sizeof(string), "~b~~h~Robbery~n~~n~~w~Opening safe door...~n~Complete in ~r~%s", ConvertToMinutes(PlayerRobberyData[playerid][RobTime]));
  554.                 PlayerTextDrawSetString(playerid, RobberyText[playerid], string);
  555.             }
  556.  
  557.             case STAGE_ROBBING:
  558.             {
  559.                 if(PlayerRobberyData[playerid][RobTime] % 5 == 0)
  560.                 {
  561.                     PlayerRobberyData[playerid][MoneyStolen] += RandomEx(floatround(RobberyData[id][Amount] / 4), RobberyData[id][Amount]);
  562.                     PlayerPlaySound(playerid, 1083, 0.0, 0.0, 0.0);
  563.                 }
  564.                
  565.                 format(string, sizeof(string), "~b~~h~Robbery~n~~n~~w~Money Stolen: ~g~~h~~h~%s~n~Complete in ~r~%s", formatInt(PlayerRobberyData[playerid][MoneyStolen]), ConvertToMinutes(PlayerRobberyData[playerid][RobTime]));
  566.                 PlayerTextDrawSetString(playerid, RobberyText[playerid], string);
  567.             }
  568.         }
  569.     }else if(PlayerRobberyData[playerid][RobTime] == 1) {
  570.         switch(PlayerRobberyData[playerid][RobStage])
  571.         {
  572.             case STAGE_CRACKING:
  573.             {
  574.                 new Float: x, Float: y, Float: z, Float: a;
  575.                 GetDynamicObjectPos(PlayerRobberyData[playerid][SafeObject][1], x, y, z);
  576.                 GetDynamicObjectRot(PlayerRobberyData[playerid][SafeObject][1], a, a, a);
  577.                 MoveDynamicObject(PlayerRobberyData[playerid][SafeObject][1], x, y, z+0.015, 0.005, 0.0, 0.0, a+230.0);
  578.                
  579.                 PlayerRobberyData[playerid][RobTime] = 4;
  580.                 PlayerRobberyData[playerid][RobStage] = STAGE_OPENING;
  581.                 PlayerTextDrawSetString(playerid, RobberyText[playerid], "~b~~h~Robbery~n~~n~~w~Opening safe door...~n~Complete in ~r~00:04");
  582.                 RemovePlayerAttachedObject(playerid, ATTACH_INDEX);
  583.                 ApplyAnimation(playerid, "ROB_BANK", "CAT_Safe_Open", 4.0, 0, 0, 0, 0, 0, 1);
  584.                 PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
  585.             }
  586.            
  587.             case STAGE_OPENING:
  588.             {
  589.                 PlayerRobberyData[playerid][RobTime] = RobberyData[id][ReqTime];
  590.                 PlayerRobberyData[playerid][RobStage] = STAGE_ROBBING;
  591.                 SetPlayerAttachedObject(playerid, ATTACH_INDEX, 1550, 1, 0.029999, -0.265000, 0.017000, 6.199993, 88.800003, 0.0);
  592.                 format(string, sizeof(string), "~b~~h~Robbery~n~~n~~w~Money Stolen: ~g~~h~~h~$0~n~Complete in ~r~%s", ConvertToMinutes(RobberyData[id][ReqTime]));
  593.                 PlayerTextDrawSetString(playerid, RobberyText[playerid], string);
  594.                 ApplyAnimation(playerid, "ROB_BANK", "CAT_Safe_Rob", 4.0, 1, 0, 0, 0, 0, 1);
  595.                 PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
  596.             }
  597.  
  598.             case STAGE_ROBBING:
  599.             {
  600.                 Robbery_Cooldown(id);
  601.  
  602.                 format(string, sizeof(string), "~n~~n~~n~~b~~h~~h~Robbery Complete~n~~w~Money Stolen: ~g~~h~~h~%s", formatInt(PlayerRobberyData[playerid][MoneyStolen]));
  603.                 GameTextForPlayer(playerid, string, 3000, 3);
  604.                 GivePlayerMoney(playerid, PlayerRobberyData[playerid][MoneyStolen]);
  605.                 PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
  606.  
  607.                 new name[MAX_PLAYER_NAME];
  608.                 GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  609.                 format(string, sizeof(string), "[ROBBERY] {FFFFFF}%s(%d) robbed {2ECC71}%s {FFFFFF}from {F1C40F}%s.", name, playerid, formatInt(PlayerRobberyData[playerid][MoneyStolen]), RobberyData[id][Name]);
  610.                 SendClientMessageToAll(0x3498DBFF, string);
  611.  
  612.                 if(PlayerRobberyData[playerid][MoneyStolen] > RobberyData[id][RecordAmount])
  613.                 {
  614.                     RobberyData[id][RecordAmount] = PlayerRobberyData[playerid][MoneyStolen];
  615.                     RobberyData[id][RecordBy] = name;
  616.                    
  617.                     SendClientMessage(playerid, 0x3498DBFF, "[ROBBERY] {FFFFFF}You broke this robbery place's record!");
  618.                    
  619.                     format(string, sizeof(string), "[ROBBERY] {FFFFFF}Because of that, you'll be rewarded with 15 percent bonus. {2ECC71}(%s)", formatInt(floatround(PlayerRobberyData[playerid][MoneyStolen] * 0.15)));
  620.                     SendClientMessage(playerid, 0x3498DBFF, string);
  621.                    
  622.                     GivePlayerMoney(playerid, floatround(PlayerRobberyData[playerid][MoneyStolen] * 0.15));
  623.                    
  624.                     stmt_bind_value(UpdateRecord, 0, DB::TYPE_INTEGER, RobberyData[id][RecordAmount]);
  625.                     stmt_bind_value(UpdateRecord, 1, DB::TYPE_STRING, RobberyData[id][RecordBy], MAX_PLAYER_NAME);
  626.                     stmt_bind_value(UpdateRecord, 2, DB::TYPE_INTEGER, id);
  627.                     stmt_execute(UpdateRecord);
  628.                 }
  629.                
  630.                 Robbery_ResetPlayer(playerid);
  631.             }
  632.         }
  633.     }
  634.    
  635.     return 1;
  636. }
  637.  
  638. forward ResetPlace(id);
  639. public ResetPlace(id)
  640. {
  641.     new string[160];
  642.     if(RobberyData[id][Cooldown] > 1) {
  643.         RobberyData[id][Cooldown]--;
  644.  
  645.         format(string, sizeof(string), "Robbery(%d)\n\n{FFFFFF}%s\n{2ECC71}%s - %s {FFFFFF}every {F1C40F}5 {FFFFFF}seconds.\n{E74C3C}Available in %s", id, RobberyData[id][Name], formatInt(floatround(RobberyData[id][Amount] / 4)), formatInt(RobberyData[id][Amount]), ConvertToMinutes(RobberyData[id][Cooldown]));
  646.         UpdateDynamic3DTextLabelText(RobberyData[id][Label], 0xF1C40FFF, string);
  647.     }else if(RobberyData[id][Cooldown] == 1) {
  648.         KillTimer(RobberyData[id][Timer]);
  649.         RobberyData[id][Cooldown] = 0;
  650.         RobberyData[id][Timer] = -1;
  651.        
  652.         format(string, sizeof(string), "Robbery(%d)\n\n{FFFFFF}%s\n{2ECC71}%s - %s {FFFFFF}every {F1C40F}5 {FFFFFF}seconds.\n{2ECC71}Available", id, RobberyData[id][Name], formatInt(floatround(RobberyData[id][Amount] / 4)), formatInt(RobberyData[id][Amount]));
  653.         UpdateDynamic3DTextLabelText(RobberyData[id][Label], 0xF1C40FFF, string);
  654.     }
  655.    
  656.     return 1;
  657. }
  658.  
  659. CMD:createrobbery(playerid, params[])
  660. {
  661.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  662.     new id = Robbery_FindFreeID();
  663.     if(id == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Can't create any more robberies.");
  664.     ShowPlayerDialog(playerid, DIALOG_ADD_ROBBERY_1, DIALOG_STYLE_INPUT, "{F1C40F}Robbery: {FFFFFF}Add (step 1)", "Write a name for the robbery:", "Next", "Close");
  665.     return 1;
  666. }
  667.  
  668. CMD:removerobbery(playerid, params[])
  669. {
  670.     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  671.     new string[1024], total;
  672.     format(string, sizeof(string), "ID\tName\n");
  673.    
  674.     for(new i; i < MAX_ROBBERIES; i++)
  675.     {
  676.         if(!RobberyData[i][Exists]) continue;
  677.         format(string, sizeof(string), "%s%d\t%s\n", string, i, RobberyData[i][Name]);
  678.         total++;
  679.     }
  680.    
  681.     if(total == 0) {
  682.         SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}No created robberies.");
  683.     }else{
  684.         ShowPlayerDialog(playerid, DIALOG_REMOVE_ROBBERY, DIALOG_STYLE_TABLIST_HEADERS, "{F1C40F}Robbery: {FFFFFF}Remove", string, "Remove", "Close");
  685.     }
  686.    
  687.     return 1;
  688. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement