Advertisement
Guest User

Infinite ammo source mod v0.6.1

a guest
Apr 10th, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.88 KB | None | 0 0
  1. #include <sourcemod>
  2.  
  3. #define PLUGIN_VERSION "0.6.1"
  4. public Plugin:myinfo = {
  5.     name = "Infinite Ammo",
  6.     author = "twistedeuphoria, Darkthrone, Andrej",
  7.     description = "Gives players infinite ammo.",
  8.     version = PLUGIN_VERSION,
  9.     url = "http://forums.alliedmods.net/showthread.php?t=55381"
  10. };
  11.  
  12. new ammo[128];
  13.  
  14. new activeoffset = 1896
  15. new clipoffset = 1204
  16. new secondclipoffset = 1208;
  17. new maxclients = 0;
  18.  
  19. new Handle:enablecvar;
  20.  
  21. public OnPluginStart()
  22. {
  23.     LoadTranslations("common.phrases")
  24.     enablecvar = CreateConVar("sm_iammo_enable", "1", "<0|1|2> 0 = disable infinite ammo; 1 = enable infinite ammo command; 2 = automatically give infinite ammo to everyone");
  25.     CreateConVar("sm_iammo_version", PLUGIN_VERSION, "Infinite Ammo Version", FCVAR_REPLICATED|FCVAR_NOTIFY);
  26.     HookConVarChange(enablecvar, EnableChanged);
  27.     RegAdminCmd("sm_iammo",unlimit, ADMFLAG_KICK,"<user id | name> <0|1> - Gives or removes infinite ammo from a player.", "",0);
  28.  
  29.     new off = FindSendPropInfo("CAI_BaseNPC", "m_hActiveWeapon");
  30.     if(off != -1) activeoffset = off;
  31.  
  32.     off = -1;  
  33.     off = FindSendPropInfo("CBaseCombatWeapon", "m_iClip1");
  34.     if(off != -1) clipoffset = off;
  35.    
  36.     // the same thing as with m_iClip1 does not work with m_iClip2 for some reason
  37.     // so we use m_iSecondaryAmmoType workaround
  38.     off = -1;
  39.     off = FindSendPropInfo("CBaseCombatWeapon", "m_iSecondaryAmmoType");
  40.     if(off != -1) secondclipoffset = off;
  41. }
  42.  
  43. public OnMapStart() {
  44.     maxclients = MaxClients;
  45. }
  46.  
  47. public EnableChanged(Handle:convar, const String:oldValue[], const String:newValue[])
  48. {
  49.     if(convar == enablecvar)
  50.     {
  51.         new oldval = StringToInt(oldValue);
  52.         new newval = StringToInt(newValue);
  53.        
  54.         if(newval == oldval) return;
  55.        
  56.         if( (newval != 0) && (newval != 1) && (newval != 2) )
  57.         {
  58.             PrintToServer("%s is not a valid value for sm_iammo_enable, switching back to %s", newValue, oldValue);
  59.             SetConVarInt(enablecvar, oldval);
  60.         }
  61.         else
  62.         {
  63.        
  64.             if(oldval == 2)
  65.             {
  66.                 PrintToChatAll("Infinite ammo for everyone removed!");
  67.                 for(new i=1;i<maxclients;i++)
  68.                 {
  69.                     if(IsValidEntity(i) && IsClientConnected(i))
  70.                     {
  71.                         ammo[i] = 0;
  72.                     }
  73.                 }
  74.             }
  75.        
  76.             if(newval == 2)
  77.             {
  78.                 PrintToChatAll("Infinite ammo enabled for everyone!");
  79.                 for(new i=1;i<maxclients;i++)
  80.                 {
  81.                     if(IsValidEntity(i) && IsClientConnected(i))
  82.                     {
  83.                         ammo[i] = 1;
  84.                     }
  85.                 }
  86.             }
  87.         }
  88.     }
  89. }
  90.  
  91. public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
  92. {
  93.     if(GetConVarInt(enablecvar) == 2)
  94.     {
  95.         ammo[client] = 1;
  96.     }
  97.    
  98.     return true;
  99. }
  100.  
  101. public OnClientDisconnect(client)
  102. {
  103.     ammo[client] = 0;
  104. }
  105.  
  106. public Action:unlimit(client,args)
  107. {
  108.  
  109.     new curval = GetConVarInt(enablecvar);
  110.    
  111.     if(curval == 0)
  112.     {
  113.         PrintToConsole(client, "Infinite Ammo is currently disabled.");
  114.         return Plugin_Handled;
  115.     }
  116.  
  117.     new aid = client;
  118.     if(args != 2)
  119.     {
  120.         PrintToConsole(aid, "Proper Usage: <user id | name> <0|1>");
  121.         return Plugin_Handled;
  122.     }
  123.     new String:idstr[50];
  124.     GetCmdArg(1,idstr,50);
  125.     new String:switchstr[2];
  126.     GetCmdArg(2,switchstr,2);
  127.    
  128.     int targets[1];
  129.     char tgtname[50];
  130.     bool ml;
  131.    
  132.     if(ProcessTargetString(idstr, client, targets, 1, 0, tgtname, 50, ml) != 1)
  133.     {
  134.         PrintToConsole(client, "Target not found.");
  135.         return Plugin_Handled;
  136.     }
  137.    
  138.     new onoff = StringToInt(switchstr);
  139.     ammo[targets[0]] = onoff;
  140. //  new String:name[50]
  141. //  GetClientName(id, name, 50);
  142.     if(onoff)
  143.     {
  144.         PrintToConsole(aid,"%s was given infinite ammo.",tgtname);
  145.         PrintToConsole(targets[0], "You were given infinite ammo.");
  146.     }
  147.     else
  148.     {
  149.         PrintToConsole(aid,"%s had their infinite ammo removed.",tgtname);
  150.         PrintToConsole(targets[0],"You're infinite ammo was removed.");
  151.     }
  152.     return Plugin_Handled;
  153. }
  154.  
  155. public OnGameFrame()
  156. {
  157.     new iWeapon;
  158.     new iSecondAmmo;
  159.     for(new iClient=1;iClient<=maxclients;iClient++)
  160.     {
  161.         if( (ammo[iClient] == 1) && IsClientInGame(iClient))
  162.         {
  163.             iWeapon = GetEntDataEnt2(iClient, activeoffset);
  164.             if(IsValidEntity(iWeapon)) {
  165.                 SetEntData(iWeapon, clipoffset, 50, 4, true);
  166.                 iSecondAmmo = GetEntData(iWeapon, secondclipoffset, 1);
  167.                 if (iSecondAmmo != 255)
  168.                     SetEntProp(iClient, Prop_Send, "m_iAmmo", 5, _, iSecondAmmo);
  169.             }
  170.         }
  171.     }
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement