AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   TF2Items (https://forums.alliedmods.net/forumdisplay.php?f=146)
-   -   TF2Items issue with creating a weapon. (https://forums.alliedmods.net/showthread.php?t=284766)

SNCurti 07-03-2016 23:03

TF2Items issue with creating a weapon.
 
Code:

#include <tf2_stocks>
#include <sdktools_functions>
#include <tf2items>
#include <tf2items_giveweapon>

public OnGameFrame()
{
        for (int i = 1; i <= MaxClients; i++)
        {
                if (IsClientInGame(i))
                {
                        PrintToChatAll("ayylmao %N", i);
                        if (IsPlayerAlive(i))
                        {
                                int newButtons = GetClientButtons(i);
                                if (newButtons & IN_FORWARD)
                                {
                                        if (TF2_GetPlayerClass(i) == TFClass_Soldier)
                                        {       
                                                TF2_RemoveWeaponSlot(i, TFWeaponSlot_Primary);
                                                Handle weapon = TF2Items_CreateItem(OVERRIDE_ALL|FORCE_GENERATION);
                                                if (weapon != INVALID_HANDLE)
                                                {
                                                        PrintToChatAll("ayylmao2");
                                                        TF2Items_SetClassname(weapon, "tf_weapon_rocketlauncher");
                                                        TF2Items_SetItemIndex(weapon, 18);
                                                        TF2Items_SetLevel(weapon, 1);
                                                        TF2Items_SetQuality(weapon, 5);
                                                        char weaponAtt[256];
                                                        Format(weaponAtt, sizeof(weaponAtt), "2 ; 100.0 ; 258 ; 1.0");
                                                        char weaponAttArray[32][32];
                                                        int attCount = ExplodeString(weaponAtt, " ; ", weaponAttArray, 32, 32);
                                                        if (attCount > 0)
                                                        {
                                                                TF2Items_SetNumAttributes(weapon, attCount/2);
                                                                int i2 = 0;
                                                                for (int i1 = 0; i1 < attCount; i1 += 2)
                                                                {
                                                                        TF2Items_SetAttribute(weapon, i2, StringToInt(weaponAttArray[i1]), StringToFloat(weaponAttArray[i1+1]));
                                                                        i2++;
                                                                }
                                                        }
                                                        else
                                                        {
                                                                TF2Items_SetNumAttributes(weapon, 0);
                                                        }
                                                        int weaponCreated = TF2Items_GiveNamedItem(i, weapon);
                                                        EquipPlayerWeapon(i, weaponCreated);
                                                       
                                                        CloseHandle(weapon);
                                                       
                                                        if (IsValidEntity(weaponCreated))
                                                        {
                                                                int ammoPrimary = GetEntProp(i, Prop_Send, "m_iPrimaryAmmo", 1) * 4;
                                                                int ammoTable = FindSendPropInfo("CTFPlayer", "m_iAmmo");
                                                                SetEntData(i, ammoTable + ammoPrimary, 0, 4, true);
                                                        }
                                                }
                                        }
                                }
                        }
                }
        }
}

So this tidbit of code was a test to see if I could check many people at once and give them rocket launchers if they were soldiers for a plugin I'm making.
However, because of the chunk of TF2Items code, the plugin just won't activate. It compiles correctly, but I was wondering if it was even running through the code and it didn't even run through it, and when I take out all of the TF2Items code, it runs. Does anyone know what I'm doing wrong when creating a rocket launcher with one rocket in clip?


All times are GMT -4. The time now is 20:58.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.