AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Code optimization and crash debugging help needed. (https://forums.alliedmods.net/showthread.php?t=232654)

WildCard65 01-02-2014 19:36

Code optimization and crash debugging help needed.
 
I need the following code optimized and fixed for it crashing my server, I written it and new to sourcepawn.

Code:

#include <sourcemod>
#include <tf2_player>
#include <tf2items>
#include <tf2itemsinfo>
#define PLUGIN_VERSION "1.0"

public Plugin:myinfo =
{
        name = "FlexCraft Admin Weapons Handler",
        author = "WildCard65",
        description = "Autocreates the admin weapons in flexcraft.",
        version = PLUGIN_VERSION,
        url = "http://wildcard65gaming.bounceme.net/"
};

public OnPluginStart()
{
        HookEvent("player_spawn", OnPlayerSpawnNotice)
        PrintToServer("Flexcraft Admin Weapons Loaded!");
        AddCommandOverride("admins_weapons_override",Override_Command,ADMFLAG_GENERIC);
}

public OnPlayerSpawnNotice(Handle:event, const String:name[], bool:dontBroadcast)
{
        new clientID = GetEventInt(event, "userid");
        new client = GetClientOfUserId(clientID);
        PrintToChat(client,"If you see any valve quality cosmetic items with particle effects on this server, they aren't real.");
        PrintToChat(client,"They were modified by a plugin on this server.");
}

Handle:AddSapperAttributes(&Handle:hItem)
{
        TF2Items_SetNumAttributes(hItem,3);
        TF2Items_SetAttribute(hItem,1,425,99999.0);
        TF2Items_SetAttribute(hItem,2,428,5.0);
        return hItem;
}

Handle:AddBuffDuration(&Handle:hItem)
{
        TF2Items_SetNumAttributes(hItem,3);
        TF2Items_SetAttribute(hItem,2,319,15.0);
        return hItem;
}

Handle:AddMiniGunAttributes(&Handle:hItem)
{
        TF2Items_SetNumAttributes(hItem,13);
        TF2Items_SetAttribute(hItem,8,87,0.01);
        TF2Items_SetAttribute(hItem,9,238,1.0);
        TF2Items_SetAttribute(hItem,10,430,1.0);
        TF2Items_SetAttribute(hItem,11,397,100.0);
        TF2Items_SetAttribute(hItem,11,75,1.5);
        return hItem;
}

Handle:AddMediGunAttributes(&Handle:hItem)
{
        TF2Items_SetNumAttributes(hItem,8);
        TF2Items_SetAttribute(hItem,1,8,999999999.0);
        TF2Items_SetAttribute(hItem,2,10,999999999.0);
        TF2Items_SetAttribute(hItem,3,11,4.0);
        TF2Items_SetAttribute(hItem,4,14,100.0);
        TF2Items_SetAttribute(hItem,5,188,100.0);
        TF2Items_SetAttribute(hItem,6,314,900.0);
        TF2Items_SetAttribute(hItem,7,499,900.0);
        return hItem;
}

Handle:AddPipeBombAttributes(&Handle:hItem)
{
        TF2Items_SetNumAttributes(hItem,14);
        TF2Items_SetAttribute(hItem,10,121,1.0);
        TF2Items_SetAttribute(hItem,11,126,-0.8);
        TF2Items_SetAttribute(hItem,12,88,(25.0-8.0));
        TF2Items_SetAttribute(hItem,13,99,2.0);
        return hItem;
}

Handle:AddBuilderAttributes(&Handle:hItem)
{
        TF2Items_SetNumAttributes(hItem,9);
        TF2Items_SetAttribute(hItem,0,134,6.0);
        TF2Items_SetAttribute(hItem,1,286,999999.0);
        TF2Items_SetAttribute(hItem,2,287,999999.0);
        TF2Items_SetAttribute(hItem,3,343,0.01);
        TF2Items_SetAttribute(hItem,4,344,999.0);
        TF2Items_SetAttribute(hItem,5,345,999.0);
        TF2Items_SetAttribute(hItem,6,80,18.0);
        TF2Items_SetAttribute(hItem,7,321,0.01);
        TF2Items_SetAttribute(hItem,8,113,3600.0);
        return hItem;
}

Handle:EngiSpecial(hItem)
{
        TF2Items_SetNumAttributes(hItem,13);
        TF2Items_SetAttribute(hItem,10,469,0.0);
        TF2Items_SetAttribute(hItem,11,474,999999.0);
        TF2Items_SetAttribute(hItem,12,280,18.0);
        return hItem;
}

Handle:AddRechargeAttribute(&Handle:hItem,limit)
{
        TF2Items_SetNumAttributes(hItem,limit);
        TF2Items_SetAttribute(hItem,(limit-1),278,0.01);
        return hItem;
}

Handle:AddDemoShieldAttribute(&Handle:hItem)
{
        TF2Items_SetNumAttributes(hItem,4);
        TF2Items_SetAttribute(hItem,1,208,1.0);
        TF2Items_SetAttribute(hItem,2,248,2.0);
        TF2Items_SetAttribute(hItem,3,249,20.0);
        return hItem;
}

Handle:AddOtherAttributes(&Handle:hItem, String:classname[], iItemDefinitionIndex)
{
        new slotindex=TF2II_GetItemSlot(iItemDefinitionIndex)
        TF2Items_SetAttribute(hItem,1,2,99999.0);
        TF2Items_SetAttribute(hItem,2,31,99999.0);
        if(slotindex==2){
                TF2Items_SetNumAttributes(hItem,5);
                TF2Items_SetAttribute(hItem,3,396,0.4);
                TF2Items_SetAttribute(hItem,4,402,1.0);
        }else{
                if(StrEqual(classname,"tf_weapon_rocketlauncher")){
                        TF2Items_SetNumAttributes(hItem,9);
                        TF2Items_SetAttribute(hItem,3,6,0.4);
                        TF2Items_SetAttribute(hItem,4,112,1000.0);
                        TF2Items_SetAttribute(hItem,5,76,100.0);
                        TF2Items_SetAttribute(hItem,6,99,2.0);
                        TF2Items_SetAttribute(hItem,7,4,(99.0/4.0));
                        TF2Items_SetAttribute(hItem,8,97,0.01);
                       
                }else{
                        TF2Items_SetNumAttributes(hItem,8);
                        TF2Items_SetAttribute(hItem,3,6,0.3);
                        TF2Items_SetAttribute(hItem,4,112,1000.0);
                        TF2Items_SetAttribute(hItem,6,208,1.0);
                        TF2Items_SetAttribute(hItem,7,266,100.0);
                        if(slotindex==1 || StrEqual(classname,"tf_weapon_revolver")){
                                TF2Items_SetAttribute(hItem,5,78,100.0);
                        }else if(slotindex==0){
                                TF2Items_SetAttribute(hItem,5,76,100.0);
                        }
                }
        }
        return hItem;
}

Handle:AddHatAtts(&Handle:hItem)
{
        TF2Items_SetNumAttributes(hItem,9);
        TF2Items_SetAttribute(hItem,0,134,13.0);
        TF2Items_SetAttribute(hItem,1,26,20000.0);
        TF2Items_SetAttribute(hItem,2,57,1000.0);
        TF2Items_SetAttribute(hItem,3,107,1.5);
        TF2Items_SetAttribute(hItem,4,269,1.0);
        TF2Items_SetAttribute(hItem,5,330,3.0);
        TF2Items_SetAttribute(hItem,6,326,10.0);
        TF2Items_SetAttribute(hItem,7,275,100.0);
        TF2Items_SetAttribute(hItem,8,53,100.0);
}

Handle:AddFirstSet(&Handle:hItem)
{
        TF2Items_SetNumAttributes(hItem,1);
        TF2Items_SetAttribute(hItem,0,134,6.0);
        return hItem;
}

public Action:TF2Items_OnGiveNamedItem(client, String:classname[], iItemDefinitionIndex, &Handle:hItem)
{
        static Handle:lastItem=INVALID_HANDLE;
        if(TF2II_IsItemSchemaPrecached()){
                if(CheckCommandAccess(client,"admins_weapons_override",ADMFLAG_GENERIC)){
                        if(lastItem != INVALID_HANDLE){
                                CloseHandle(lastItem);
                                lastItem=INVALID_HANDLE;
                        }
                        if(hItem != INVALID_HANDLE){
                                return Plugin_Continue;
                        }
                        hItem = TF2Items_CreateItem(OVERRIDE_ITEM_QUALITY|OVERRIDE_ITEM_LEVEL|OVERRIDE_ATTRIBUTES|PRESERVE_ATTRIBUTES);
                        TF2Items_SetQuality(hItem,8);
                        TF2Items_SetLevel(hItem,5000);
                        if(TF2II_GetItemSlot(iItemDefinitionIndex)!=7){
                                hItem=AddFirstSet(hItem);
                                if(StrEqual(classname,"tf_weapon_buff_item"))
                                {
                                        hItem=AddBuffDuration(hItem);
                                }else if(StrEqual(classname,"tf_wearable"))
                                {
                                        AddHatAtts(hItem);
                                }else if(StrEqual(classname,"tf_weapon_pda_engineer_build"))
                                {
                                        hItem=AddBuilderAttributes(hItem);
                                }else if(StrEqual(classname,"tf_weapon_pda_engineer_destroy"))
                                {
                                }else if(StrEqual(classname,"tf_weapon_lunchbox"))
                                {
                                        hItem=AddRechargeAttribute(hItem,2);
                                }else if(StrEqual(classname,"tf_weapon_medigun"))
                                {
                                        hItem=AddMediGunAttributes(hItem);
                                }else if(StrEqual(classname,"tf_weapon_builder"))
                                {
                                }else if(StrEqual(classname,"tf_weapon_builder_spy"))
                                {
                                }else if(StrEqual(classname,"tf_weapon_invis"))
                                {
                                        TF2Items_SetNumAttributes(hItem,3);
                                        TF2Items_SetAttribute(hItem,2,83,-20.0);
                                        TF2Items_SetAttribute(hItem,2,84,20.0);
                                }else if(StrEqual(classname,"tf_weapon_sapper"))
                                {
                                        hItem=AddSapperAttributes(hItem);
                                }else if(StrEqual(classname,"tf_wearable_demoshield"))
                                {
                                        hItem=AddDemoShieldAttribute(hItem);
                                }else
                                {
                                        hItem=AddOtherAttributes(hItem, classname, iItemDefinitionIndex);
                                        if(!StrEqual(classname,"tf_weapon_flaregun") && !StrEqual(classname,"tf_weapon_minigun") && !StrEqual(classname,"tf_weapon_flamethrower") && !StrEqual(classname,"tf_weapon_rocketlauncher") && TF2II_GetItemSlot(iItemDefinitionIndex)!=2){
                                                TF2Items_SetNumAttributes(hItem,10);
                                                if(StrEqual(classname,"tf_weapon_syringegun_medic")){
                                                        TF2Items_SetAttribute(hItem,7,4,2.0);
                                                }else{
                                                        TF2Items_SetAttribute(hItem,7,4,11.0);
                                                }
                                                TF2Items_SetAttribute(hItem,9,97,0.01);
                                        }
                                        if(StrEqual(classname,"tf_weapon_bat_wood") || StrEqual(classname,"tf_weapon_bat_giftwrap") || StrEqual(classname,"tf_weapon_cleaver"))
                                        {
                                                hItem=AddRechargeAttribute(hItem,6);
                                        }
                                        if(StrEqual(classname,"tf_weapon_wrench"))
                                        {
                                                TF2Items_SetNumAttributes(hItem,7);
                                                TF2Items_SetAttribute(hItem,5,92,200.0);
                                                TF2Items_SetAttribute(hItem,6,94,200.0);
                                        }
                                        if(StrEqual(classname,"tf_weapon_sword"))
                                        {
                                                TF2Items_SetNumAttributes(hItem,6);
                                                TF2Items_SetAttribute(hItem,5,1030,1.0);
                                        }
                                        if(StrEqual(classname,"tf_weapon_pipebomblauncher"))
                                        {
                                                AddPipeBombAttributes(hItem);
                                        }
                                        if(StrEqual(classname,"tf_weapon_minigun"))
                                        {
                                                hItem=AddMiniGunAttributes(hItem);
                                        }
                                        if(StrEqual(classname,"tf_weapon_shotgun_building_rescue"))
                                        {
                                                PrintToServer("Found ranger!");
                                                hItem=EngiSpecial(hItem);
                                        }
                                }
                        }
                        lastItem=hItem;
                        return Plugin_Changed;
                }
                return Plugin_Continue;
        }else{
                ServerCommand("sm_tf2ii_reload");
                return Plugin_Handled;
        }
}

public OnPluginEnd()
{
}



All times are GMT -4. The time now is 21:27.

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