Akuba

Weapon Replace FF2 thing

Nov 10th, 2015
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.11 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <freak_fortress_2>
  3. #include <tf2_stocks>
  4. #include <tf2items>
  5.  
  6. public OnPluginStart()
  7. {
  8.     HookEvent("player_spawn", event_player_spawn, EventHookMode_Pre);
  9. }
  10.  
  11. public Action:event_player_spawn(Handle:event, const String:name[], bool:dontBroadcast)
  12. {
  13.     new client=GetClientOfUserId(GetEventInt(event, "userid"));
  14.     CreateTimer(0.15, CheckItems, client);
  15.     return Plugin_Continue;
  16. }
  17.  
  18. public Action:CheckItems(Handle:timer, any:client)
  19. {
  20.     if(!IsValidClient(client) || !IsPlayerAlive(client) || FF2_GetBossIndex(client)!=-1)
  21.     {
  22.         return Plugin_Continue;
  23.     }
  24.  
  25.     new weapon=GetPlayerWeaponSlot(client, TFWeaponSlot_Primary);
  26.     new index=-1;
  27.  
  28.     if(weapon && IsValidEdict(weapon))
  29.     {
  30.         index=GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex");
  31.         switch(index)
  32.         {
  33.             case 230:  //The Sydney Sleeper
  34.             {
  35.                 TF2_RemoveWeaponSlot(client, TFWeaponSlot_Primary);
  36.                 SpawnWeapon(client, "tf_weapon_sniperrifle", 14, 1, 0, ""); //Sniper Rifle
  37.             }
  38.         }
  39.     }
  40.  
  41.     weapon=GetPlayerWeaponSlot(client, TFWeaponSlot_Melee);
  42.     if(weapon && IsValidEdict(weapon))
  43.     {
  44.         index=GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex");
  45.         switch(index)
  46.         {
  47.             case 649:  //Spy-cicle
  48.             {
  49.                 TF2_RemoveWeaponSlot(client, TFWeaponSlot_Melee);
  50.                 weapon=SpawnWeapon(client, "tf_weapon_knife", 4, 1, 0, "");  //Knife
  51.             }
  52.         }
  53.     }
  54.  
  55.     weapon=GetPlayerWeaponSlot(client, 4);
  56.     if(weapon && IsValidEdict(weapon))
  57.     {
  58.         index=GetEntProp(weapon, Prop_Send, "m_iItemDefinitionIndex");
  59.         switch(index)
  60.         {
  61.             case 60:  //Cloak and Dagger
  62.             {
  63.                 TF2_RemoveWeaponSlot(client, 4);
  64.                 SpawnWeapon(client, "tf_weapon_invis", 30, 1, 0, ""); //Watch
  65.             }
  66.         }
  67.     }
  68.     return Plugin_Continue;
  69. }
  70.  
  71. stock bool:IsValidClient(client, bool:replaycheck=true)
  72. {
  73.     if(client<=0 || client>MaxClients)
  74.     {
  75.         return false;
  76.     }
  77.  
  78.     if(!IsClientInGame(client))
  79.     {
  80.         return false;
  81.     }
  82.  
  83.     if(GetEntProp(client, Prop_Send, "m_bIsCoaching"))
  84.     {
  85.         return false;
  86.     }
  87.  
  88.     if(replaycheck)
  89.     {
  90.         if(IsClientSourceTV(client) || IsClientReplay(client))
  91.         {
  92.             return false;
  93.         }
  94.     }
  95.     return true;
  96. }
  97.  
  98. stock SpawnWeapon(client, String:name[], index, level, qual, String:att[])
  99. {
  100.     new Handle:hWeapon=TF2Items_CreateItem(OVERRIDE_ALL|FORCE_GENERATION);
  101.     if(hWeapon==INVALID_HANDLE)
  102.     {
  103.         return -1;
  104.     }
  105.  
  106.     TF2Items_SetClassname(hWeapon, name);
  107.     TF2Items_SetItemIndex(hWeapon, index);
  108.     TF2Items_SetLevel(hWeapon, level);
  109.     TF2Items_SetQuality(hWeapon, qual);
  110.     new String:atts[32][32];
  111.     new count=ExplodeString(att, ";", atts, 32, 32);
  112.  
  113.     if(count % 2)
  114.     {
  115.         --count;
  116.     }
  117.  
  118.     if(count>0)
  119.     {
  120.         TF2Items_SetNumAttributes(hWeapon, count/2);
  121.         new i2;
  122.         for(new i; i<count; i+=2)
  123.         {
  124.             new attrib=StringToInt(atts[i]);
  125.             if(!attrib)
  126.             {
  127.                 LogError("Bad weapon attribute passed: %s ; %s", atts[i], atts[i+1]);
  128.                 CloseHandle(hWeapon);
  129.                 return -1;
  130.             }
  131.  
  132.             TF2Items_SetAttribute(hWeapon, i2, attrib, StringToFloat(atts[i+1]));
  133.             i2++;
  134.         }
  135.     }
  136.     else
  137.     {
  138.         TF2Items_SetNumAttributes(hWeapon, 0);
  139.     }
  140.  
  141.     new entity=TF2Items_GiveNamedItem(client, hWeapon);
  142.     CloseHandle(hWeapon);
  143.     EquipPlayerWeapon(client, entity);
  144.     return entity;
  145. }
Advertisement