Approved Breaker Punisher

Plug-ins compatibility with Zombie Escape 1.x only!


Rain1153
Senior Member
Senior Member
India
Posts: 278
Joined: 6 years ago
Contact:

#21

Post by Rain1153 » 5 years ago

no it doesn't happen
LOL

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#22

Post by Raheem » 5 years ago

Try and confirm that this is working so i update main plugin:
    1. #include <zombie_escape>
    2.  
    3. // Define
    4. #define ACCESS ADMIN_RCON
    5.  
    6. // Variables
    7. new g_szDamageData[33][41], Float:g_flLastTouched[33], g_iEnt[33],
    8. g_iMaxPlayers, g_szConfigDir[64], g_szFile[64], g_szDir[64]
    9.  
    10. // Cvars
    11. new g_pCvarDamageTime
    12.  
    13. public plugin_init()
    14. {
    15.     register_plugin("[ZE] Breaker Punisher","1.0","Raheem")
    16.    
    17.     // Ham
    18.     RegisterHam(Ham_TakeDamage, "func_breakable", "Fw_TakeDamage_Post", 1)
    19.     RegisterHam(Ham_Touch, "func_breakable", "Fw_TouchBreakable_Pre", 0)
    20.    
    21.     // CVARs
    22.     g_pCvarDamageTime = register_cvar("breaker_damage_time", "2") // If this time passed, damage player make to entity will not be counted and this player won't be punished
    23.    
    24.     // Commands
    25.     register_clcmd("ze_breakmenu", "BreakableMenu")
    26.    
    27.     // Constants
    28.     g_iMaxPlayers = get_member_game(m_nMaxPlayers)
    29.    
    30.     // Get config folder
    31.     get_localinfo("amxx_configsdir", g_szConfigDir, charsmax(g_szConfigDir))
    32.    
    33.     // Get file path
    34.     new szMapName[64]
    35.     get_mapname(szMapName, charsmax(szMapName))
    36.    
    37.     formatex(g_szFile, charsmax(g_szFile), "%s/breakables/%s.txt", g_szConfigDir, szMapName)
    38.     formatex(g_szDir, charsmax(g_szDir), "%s/breakables", g_szConfigDir)
    39. }
    40.  
    41. public Fw_TakeDamage_Post(iEnt, iInflictor, iAttacker, Float:flDamage, bitsDamage)
    42. {
    43.     if (!EntityExists(iEnt))
    44.         return
    45.    
    46.     // iEnt Damage Time
    47.     formatex(g_szDamageData[iAttacker], charsmax(g_szDamageData[]), "%i %f %f", iEnt, flDamage, get_gametime())
    48.    
    49.     // In case of breaking we check breakers
    50.     if(get_entvar(iEnt, var_health) <= 0)
    51.     {
    52.         new szEnt[32], szDamage[32], szTime[32]
    53.    
    54.         for(new id = 1; id <= g_iMaxPlayers; id++)
    55.         {
    56.             if (!is_user_alive(id))
    57.                 continue;
    58.            
    59.             // Check if these users has empty data continue, somehow parse don't work with empty strings so this is important
    60.             trim(g_szDamageData[id])
    61.            
    62.             if (strlen(g_szDamageData[id]) == 0)
    63.                 continue;
    64.            
    65.             parse(g_szDamageData[id], szEnt, charsmax(szEnt), szDamage, charsmax(szDamage), szTime, charsmax(szTime))
    66.            
    67.             // This is a friend that did no damage and touching our entity
    68.             if (IsUserToucing(iEnt, id) && str_to_num(szDamage) == 0)
    69.                 continue;
    70.            
    71.             // Make sure the stored entity same as broken one
    72.             if (str_to_num(szEnt) == iEnt)
    73.             {              
    74.                 // Make sure that time for this is just from 2 seconds (or value from cvar)
    75.                 if (str_to_num(szTime) + get_pcvar_num(g_pCvarDamageTime) >= floatround(get_gametime()))
    76.                 {
    77.                     // There is someone touching it
    78.                     if (AnyoneTouching(iEnt, iAttacker))
    79.                     {
    80.                         // Make sure first player not zombie
    81.                         if (!ze_is_user_zombie(id))
    82.                         {
    83.                             client_print_color(id, print_team_default, "^1[^4Team-Mate^1] ^3You have ^4exploded ^3because you ^4blocked ^3your team-mate(s)^1.")
    84.                             ExecuteHamB(Ham_TakeDamage, id, iEnt, iEnt, 99999.0, DMG_GENERIC)
    85.                             client_cmd(id, "spk vox/bizwarn")
    86.                         }
    87.                     }
    88.                 }
    89.             }
    90.         }
    91.     }
    92. }
    93.  
    94. public Fw_TouchBreakable_Pre(iEnt, id)
    95. {
    96.     if (!is_user_connected(id) || ze_is_user_zombie(id))
    97.         return HAM_IGNORED;
    98.    
    99.     g_flLastTouched[id] = get_gametime()
    100.     g_iEnt[id] = iEnt
    101.    
    102.     return HAM_IGNORED;
    103. }
    104.  
    105. public BreakableMenu(id)
    106. {
    107.     // Player have no access?
    108.     if (!(get_user_flags(id) & ACCESS))
    109.     {
    110.         client_print(id, print_console, "You have no access to that command")
    111.         return PLUGIN_HANDLED
    112.     }
    113.    
    114.     // Create our menu
    115.     new iBreakMenu = menu_create("\yBreakable Menu\w:", "BreakMenuHandler")
    116.    
    117.     // Add elements
    118.     menu_additem(iBreakMenu, "Add this entity", "", 0)
    119.    
    120.     // Remove elements
    121.     menu_additem(iBreakMenu, "Remove this entity", "", 0)
    122.    
    123.     // Set some properties and display the menu
    124.     menu_setprop(iBreakMenu, MPROP_EXIT, MEXIT_ALL);
    125.     menu_display(id, iBreakMenu, 0)
    126.    
    127.     // Block annoying message in console after writing breakmenu
    128.     return PLUGIN_HANDLED
    129. }
    130.  
    131. public BreakMenuHandler(id, iMenu, iItem)
    132. {
    133.     // If it's exit, destroy the menu
    134.     if (iItem == MENU_EXIT)
    135.     {
    136.         menu_destroy(iMenu)
    137.         return PLUGIN_HANDLED
    138.     }
    139.    
    140.     // Variables
    141.     new iEnt, szClassName[32], szModel[32], iFileHandler, iBody, szLine[32]
    142.    
    143.     // Get the entity index player aiming at
    144.     get_user_aiming(id, iEnt, iBody)
    145.    
    146.     // Get classname for this entity player aiming at
    147.     get_entvar(iEnt, var_classname, szClassName, charsmax(szClassName))
    148.    
    149.     // If the classname not ours then show wrong message and reshow menu
    150.     if (!equal(szClassName, "func_breakable"))
    151.     {
    152.         client_print_color(id, print_team_default, "^3Failed^1, ^3you are aiming at wrong entity ^4not func_breakable^1.")
    153.         BreakableMenu(id)
    154.        
    155.         return PLUGIN_HANDLED
    156.     }
    157.    
    158.     // It's breakable then get it's model
    159.     get_entvar(iEnt, var_model, szModel, charsmax(szModel))
    160.    
    161.     switch(iItem)
    162.     {
    163.         case 0:
    164.         {
    165.             // Now we check if breakables folder exist or not, if not create one
    166.             if (!dir_exists(g_szDir))
    167.             {
    168.                 mkdir(g_szDir)
    169.             }
    170.            
    171.             // Now we open file for reading text
    172.             iFileHandler = fopen(g_szFile, "rt")
    173.            
    174.             // Loop through the whole file to check if this model exist or not
    175.             // Note that feof should be used only if file opened for reading
    176.             // If you opened file for writting and try using feof you will fall in infinite loop
    177.             while(!feof(iFileHandler))
    178.             {
    179.                 // Read the line
    180.                 fgets(iFileHandler, szLine, charsmax(szLine))
    181.                
    182.                 // Remove any spaces from it's start
    183.                 trim(szLine)
    184.                
    185.                 // This line is empty? skip
    186.                 if (strlen(szLine) == 0)
    187.                     continue;
    188.                
    189.                 // If model already exist then show fail message, and reshow menu
    190.                 if (equal(szLine, szModel))
    191.                 {
    192.                     client_print_color(id, print_team_default, "^3Failed^1, ^3this already exist in the file ^1(^4%s^1) !", szModel)
    193.                    
    194.                     BreakableMenu(id)
    195.                    
    196.                     // Close the file
    197.                     fclose(iFileHandler)
    198.                    
    199.                     return PLUGIN_HANDLED
    200.                 }
    201.             }
    202.            
    203.             // Close the file
    204.             fclose(iFileHandler)
    205.  
    206.             // Open file for appending text, and create if not exist
    207.             iFileHandler = fopen(g_szFile, "at")
    208.            
    209.             // Append the text to the file
    210.             fputs(iFileHandler, szModel)
    211.             fputs(iFileHandler, "^n")
    212.            
    213.             // Close file again
    214.             fclose(iFileHandler)
    215.            
    216.             // Success
    217.             client_print_color(id, print_team_default, "^3Successfully added entity^1: ^4%s ^3to the file^1.", szModel)
    218.            
    219.             client_cmd(id, "spk buttons/bell1")
    220.             // Reshow menu
    221.             BreakableMenu(id)
    222.         }
    223.         case 1:
    224.         {
    225.             // Folder not exist? so file will exist? lol
    226.             if (!dir_exists(g_szDir))
    227.             {
    228.                 client_print_color(id, print_team_default, "^3Failed^1, ^3no text file exist for this map^1!")
    229.                
    230.                 return PLUGIN_HANDLED
    231.             }
    232.            
    233.             if (!EntityExists(iEnt))
    234.             {
    235.                 client_print_color(id, print_team_default, "^3Failed^1, ^3this entity ^1(^4%s^1) ^3not exist in the file to be removed^1!", szModel)
    236.  
    237.                 BreakableMenu(id)
    238.                 return PLUGIN_HANDLED
    239.             }
    240.            
    241.             // Here it's exist so we need to delete it
    242.             DeleteLine(g_szFile, szModel)
    243.            
    244.             client_print_color(id, print_team_default, "^3Successfully deleted entity^1: ^4%s ^3from the file^1.", szModel)
    245.            
    246.             client_cmd(id, "spk buttons/bell1")
    247.             BreakableMenu(id)
    248.         }
    249.     }
    250.  
    251.     return PLUGIN_HANDLED
    252. }
    253.  
    254. /*
    255. *   Stock to check if any player touching specific entity (iEnt) or not
    256. */
    257. stock AnyoneTouching(const iEnt, const iAttacker)
    258. {
    259.     // Check if anyone touch our ent or not
    260.     for(new id = 1; id <= g_iMaxPlayers; id++)
    261.     {
    262.         if (!is_user_alive(id) || !(g_iEnt[id] == iEnt) || id == iAttacker)
    263.             continue;
    264.        
    265.         if (g_flLastTouched[id] + 0.1 >= get_gametime()) /* For more accurecy lower 0.1 to for example 0.01*/
    266.         {
    267.             return true;
    268.         }
    269.     }
    270.    
    271.     return false;
    272. }
    273.  
    274. /*
    275. *   Stock to check if specific player (id) is touching specific entity (iEnt)
    276. */
    277. stock IsUserToucing(const iEnt, const id)
    278. {
    279.     // Check if this user touching this ent or not
    280.     if ((g_flLastTouched[id] + 0.1 >= get_gametime()) && (g_iEnt[id] == iEnt)) /* For more accurecy lower 0.1 to for example 0.01*/
    281.         return true
    282.    
    283.     return false
    284. }
    285.  
    286. /*
    287. *   Check if entity in our file or not
    288. */
    289. stock EntityExists(const iEnt)
    290. {
    291.     new iFileHandler, szModel[32], szLine[32]
    292.    
    293.     // Now we open file for reading text
    294.     iFileHandler = fopen(g_szFile, "rt")
    295.    
    296.     // Get model
    297.     get_entvar(iEnt, var_model, szModel, charsmax(szModel))
    298.  
    299.     while(!feof(iFileHandler))
    300.     {
    301.         // Read the line
    302.         fgets(iFileHandler, szLine, charsmax(szLine))
    303.        
    304.         // Remove any spaces from it's start
    305.         trim(szLine)
    306.        
    307.         // This line is empty? skip
    308.         if (strlen(szLine) == 0)
    309.             continue;
    310.        
    311.         // Exist in the file
    312.         if (equal(szLine, szModel))
    313.         {
    314.             // Close file
    315.             fclose(iFileHandler)
    316.            
    317.             return true;
    318.         }
    319.     }
    320.    
    321.     // Close file
    322.     fclose(iFileHandler)
    323.    
    324.     return false;
    325. }
    326.  
    327. /*
    328. *   My stock to delete line:
    329. *  
    330. *   szFile is the file path.
    331. *   szLine is the line to be deleted.
    332. */
    333. stock DeleteLine(const szFile[], const szLine[])
    334. {
    335.     // Check if file there or not
    336.     if (file_exists(szFile))
    337.     {
    338.         // Some variables
    339.         new Array:szFileLines, szLineToRead[32], iFileHandler
    340.        
    341.         // Create dynamic array to handle all lines in our file (every line will be in element)
    342.         szFileLines = ArrayCreate(32)
    343.        
    344.         // Open file for reading text so we can use feof
    345.         iFileHandler = fopen(szFile, "rt")
    346.        
    347.         while(!feof(iFileHandler))
    348.         {
    349.             // Read line by line
    350.             fgets(iFileHandler, szLineToRead, charsmax(szLineToRead))
    351.            
    352.             // Remove any spaces at start
    353.             trim(szLineToRead)
    354.            
    355.             // If this is our line we need to delete, skip it
    356.             if (equal(szLineToRead, szLine))
    357.                 continue
    358.            
    359.             // Push all lines to our array except one we need to delete
    360.             ArrayPushString(szFileLines, szLineToRead)
    361.         }
    362.        
    363.         // Close the file
    364.         fclose(iFileHandler)
    365.        
    366.         // Delete the file - using delete_file native will cause problems, so i use this way
    367.         iFileHandler = fopen(szFile, "wt")
    368.         fclose(iFileHandler)
    369.        
    370.         /* We may use here the new system */
    371.        
    372.         // Now we open file for appending text
    373.         iFileHandler = fopen(g_szFile, "at")
    374.        
    375.         // Recreate the file and print all data to it
    376.         for (new iLine = 0; iLine < ArraySize(szFileLines) - 1; iLine++)
    377.         {
    378.             // Get strings in our array
    379.             ArrayGetString(szFileLines, iLine, szLineToRead, charsmax(szLineToRead))
    380.            
    381.             // Write them to our file
    382.             fputs(iFileHandler, szLineToRead)
    383.             fputs(iFileHandler, "^n")
    384.         }
    385.        
    386.         // Close file
    387.         fclose(iFileHandler)
    388.        
    389.         // Destroy this array and free it's memory
    390.         ArrayDestroy(szFileLines)
    391.     }
    392. }
I added this:
Raheem wrote: 5 years ago I have idea for this:

If there is no players else this player standing on the breakable entity then we will not slay him.
If there is more than player and he break it and was standing on the entity he will be slayed.

Will find time to implement this.
He who fails to plan is planning to fail

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 598
Joined: 7 years ago
Contact:

#23

Post by czirimbolo » 5 years ago

Still nothing Raheem. It slays myself when I am standing on it
Image

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#24

Post by Raheem » 5 years ago

czirimbolo wrote: 5 years ago Still nothing Raheem. It slays myself when I am standing on it
Working for me, try again and make sure you updated the plugin.
He who fails to plan is planning to fail

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 598
Joined: 7 years ago
Contact:

#25

Post by czirimbolo » 5 years ago

Working!
Image

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#26

Post by Raheem » 5 years ago

Why things work for you in second test :?: :lol:
He who fails to plan is planning to fail

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 598
Joined: 7 years ago
Contact:

#27

Post by czirimbolo » 5 years ago

Dont know, maybe I uploaded wrong version haha.
Image

Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Who is online

Users browsing this forum: No registered users and 0 guests