AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   TF2Items (https://forums.alliedmods.net/forumdisplay.php?f=146)
-   -   Solved [Answered]Would this make everyone's weapon quality Valve? (https://forums.alliedmods.net/showthread.php?t=232453)

WildCard65 12-30-2013 15:35

[Answered]Would this make everyone's weapon quality Valve?
 
PHP Code:

public Action:TF2Items_OnGiveNamedItem(clientString:classname[], iItemDefinitionIndex, &Handle:hItem)
{
    
hItem=TF2Items_CreateItem(OVERRIDE_ATTRIBUTES);
    
TF2Items_SetClassname(hItem,classname);
    
TF2Items_SetItemIndex(hItem,iItemDefinitionIndex);
    
TF2Items_SetQuality(hItem,8);
    
TF2Items_SetLevel(hItem,5000);
    
TF2Items_SetNumAttributes(hItem,1);
    
TF2Items_SetAttribute(hItem,1,134,1);
    
TF2Items_GiveNamedItem(client,hItem);
    
CloseHandle(hItem);
    return 
Plugin_Changed;


Edit:I'm also new to making sourcemod plugins.

Powerlord 12-30-2013 16:14

Re: Would this make everyone's weapon quality Valve?
 
You're forgetting a few flags to TF2Items_CreateItem... did you mean OVERRIDE_ALL instead of OVERRIDE_ATTRIBUTES? Also, you'll still need PRESERVE_ATTRIBUTES too.

WildCard65 12-30-2013 16:16

Re: Would this make everyone's weapon quality Valve?
 
Quote:

Originally Posted by Powerlord (Post 2078693)
You're forgetting a few flags to TF2Items_CreateItem... did you mean OVERRIDE_ALL instead of OVERRIDE_ATTRIBUTES? Also, you'll still need PRESERVE_ATTRIBUTES too.

how would I add Preserve_attributes?
Also note: This will eventually be a private plugin for me for admin weapons(where strange shotty would work with, with configs it won't work right(in terms of maxprimary/2nd ammo when otherweapons also handle that)

Powerlord 12-30-2013 16:19

Re: Would this make everyone's weapon quality Valve?
 
One other thing: You close hItem before the callback returns, so it's not going to work anyway... but to avoid leaking handles, you need to close said handle...

The best workaround for this issue is either a global or static variable. I personally prefer static.

So, something like...
PHP Code:

public Action:TF2Items_OnGiveNamedItem(clientString:classname[], iItemDefinitionIndex, &Handle:hItem)
{
    static 
Handle:item INVALID_HANDLE;
    if (
item != INVALID_HANDLE)
        
CloseHandle(item);
    new 
Handle:hItem TF2Items_CreateItem(OVERRIDE_QUALITY|OVERRIDE_LEVEL|OVERRIDE_ATTRIBUTES|PRESERVE_ATTRIBUTES);
    
TF2Items_SetItemIndex(hItem,iItemDefinitionIndex);
    
TF2Items_SetQuality(hItem,8);
    
TF2Items_SetLevel(hItem,5000);
    
TF2Items_SetNumAttributes(hItem,1);
    
TF2Items_SetAttribute(hItem,1,134,1);
    
TF2Items_GiveNamedItem(client,hItem);
    
hItem item;
    return 
Plugin_Changed;


(Note: I didn't actually test that code)

WildCard65 12-30-2013 16:48

Re: Would this make everyone's weapon quality Valve?
 
Quote:

Originally Posted by Powerlord (Post 2078697)
One other thing: You close hItem before the callback returns, so it's not going to work anyway... but to avoid leaking handles, you need to close said handle...

The best workaround for this issue is either a global or static variable. I personally prefer static.

So, something like...
PHP Code:

public Action:TF2Items_OnGiveNamedItem(clientString:classname[], iItemDefinitionIndex, &Handle:hItem)
{
    static 
Handle:item INVALID_HANDLE;
    if (
item != INVALID_HANDLE)
        
CloseHandle(item);
    new 
Handle:hItem TF2Items_CreateItem(OVERRIDE_QUALITY|OVERRIDE_LEVEL|OVERRIDE_ATTRIBUTES|PRESERVE_ATTRIBUTES);
    
TF2Items_SetItemIndex(hItem,iItemDefinitionIndex);
    
TF2Items_SetQuality(hItem,8);
    
TF2Items_SetLevel(hItem,5000);
    
TF2Items_SetNumAttributes(hItem,1);
    
TF2Items_SetAttribute(hItem,1,134,1);
    
TF2Items_GiveNamedItem(client,hItem);
    
hItem item;
    return 
Plugin_Changed;


(Note: I didn't actually test that code)

code did fail to compile, I removed the errors, tested and it crashed my server(plus also removed a warning of you using new on hItem when it's a parameter.
PHP Code:

public Action:TF2Items_OnGiveNamedItem(clientString:classname[], iItemDefinitionIndex, &Handle:hItem)
{
    static 
Handle:item INVALID_HANDLE;
    if (
item != INVALID_HANDLE)
        
CloseHandle(item);
    
hItem TF2Items_CreateItem(OVERRIDE_ITEM_QUALITY|OVERRIDE_ITEM_LEVEL|OVERRIDE_ATTRIBUTES|PRESERVE_ATTRIBUTES);
    
TF2Items_SetClassname(hItem,classname);
    
TF2Items_SetItemIndex(hItem,iItemDefinitionIndex);
    
TF2Items_SetQuality(hItem,8);
    
TF2Items_SetLevel(hItem,5000);
    
TF2Items_SetNumAttributes(hItem,1);
    
TF2Items_SetAttribute(hItem,1,134,1);
    
TF2Items_GiveNamedItem(client,hItem);
    
item=hItem;
    return 
Plugin_Changed;


Edit: Had to add the setclassname because console was being spammed with attemtping to create an entity.

Powerlord 12-30-2013 16:53

Re: Would this make everyone's weapon quality Valve?
 
Quote:

Originally Posted by WildCard65 (Post 2078715)
code did fail to compile, I removed the errors, tested and it crashed my server(plus also removed a warning of you using new on hItem when it's a parameter.
PHP Code:

public Action:TF2Items_OnGiveNamedItem(clientString:classname[], iItemDefinitionIndex, &Handle:hItem)
{
    static 
Handle:item INVALID_HANDLE;
    if (
item != INVALID_HANDLE)
        
CloseHandle(item);
    
hItem TF2Items_CreateItem(OVERRIDE_ITEM_QUALITY|OVERRIDE_ITEM_LEVEL|OVERRIDE_ATTRIBUTES|PRESERVE_ATTRIBUTES);
    
TF2Items_SetClassname(hItem,classname);
    
TF2Items_SetItemIndex(hItem,iItemDefinitionIndex);
    
TF2Items_SetQuality(hItem,8);
    
TF2Items_SetLevel(hItem,5000);
    
TF2Items_SetNumAttributes(hItem,1);
    
TF2Items_SetAttribute(hItem,1,134,1);
    
TF2Items_GiveNamedItem(client,hItem);
    
item=hItem;
    return 
Plugin_Changed;


Edit: Had to add the setclassname because console was being spammed with attemtping to create an entity.

Get rid of the TF2Items_GiveNamedItem(client, hItem) call... it's not necessary in this callback.... TF2Items will do it itself as soon as you return Plugin_Changed.

WildCard65 12-30-2013 17:03

Re: Would this make everyone's weapon quality Valve?
 
Did that, still crashes.

DarthNinja 12-30-2013 23:39

Re: Would this make everyone's weapon quality Valve?
 
You could just change the value of m_iEntityQuality and m_iEntityLevel and not have to deal with TF2Items.

asherkin 12-31-2013 08:20

Re: Would this make everyone's weapon quality Valve?
 
PHP Code:

public Action:TF2Items_OnGiveNamedItem(clientString:classname[], iItemDefinitionIndex, &Handle:hItem)
{
    static 
Handle:previousItem INVALID_HANDLE;

    if (
previousItem != INVALID_HANDLE) {
        
CloseHandle(previousItem);
    }

    if (
hItem != INVALID_HANDLE) {
        return 
Plugin_Continue;
    }

    
hItem TF2Items_CreateItem(OVERRIDE_QUALITY);
    
TF2Items_SetQuality(hItem8);
    
previousItem hItem;

    return 
Plugin_Changed;



WildCard65 12-31-2013 08:39

Re: Would this make everyone's weapon quality Valve?
 
Quote:

Originally Posted by asherkin (Post 2078965)
PHP Code:

public Action:TF2Items_OnGiveNamedItem(clientString:classname[], iItemDefinitionIndex, &Handle:hItem)
{
    static 
Handle:previousItem INVALID_HANDLE;

    if (
previousItem != INVALID_HANDLE) {
        
CloseHandle(previousItem);
    }

    if (
hItem != INVALID_HANDLE) {
        return 
Plugin_Continue;
    }

    
hItem TF2Items_CreateItem(OVERRIDE_QUALITY);
    
TF2Items_SetQuality(hItem8);
    
previousItem hItem;

    return 
Plugin_Changed;



Thx asherkin! It worked(just had to comment out the CloseHandle for it to work right)


All times are GMT -4. The time now is 19:24.

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