View Single Post
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-16-2013 , 11:18   Re: [HELP] With the function TF2Items_SetAttribute
Reply With Quote #4

Quote:
Originally Posted by Arkarr View Post
What's wrong with handle here ?
It give me a error message in console saying something like TF2_Items Invalid Handle... (need screenshot?)

PHP Code:
#include <sourcemod>
#include <tf2items>

public OnPluginStart()  
{
    
//Nothing ?
}


public 
Action:TF2Items_OnGiveNamedItem(clientString:classname[], iItemDefinitionIndex, &Handle:hItem)
{                
    
TF2Items_CreateItem(PRESERVE_ATTRIBUTES);
    
    
//Adding 300 dammage bonus
    
TF2Items_SetAttribute(hItem12300);
                
    
TF2Items_GiveNamedItem(clienthItem);
                
    
CloseHandle(hItem);

    return 
Plugin_Continue;

A few things:
  • You're not saving the item handle to hItem
  • You also need OVERRIDE_ATTRIBUTES to change attributes.
  • You're not returning Plugin_Changed
  • You're closing the handle before the callback completes
  • Also, unfortunately, TF2Items_OnGiveNamedItem tends to leak handles.
  • Attributes start at 0.
  • Attribute count has to be set.

So...
PHP Code:
public Action:TF2Items_OnGiveNamedItem(clientString:classname[], iItemDefinitionIndex, &Handle:hItem)
{
    
//Deal with Handle leaks
    
static Handle:item INVALID_HANDLE;
    if (
item != INVALID_HANDLE)
    {
        
CloseHandle(item);
        
item INVALID_HANDLE;
    }
    
    
item TF2Items_CreateItem(OVERRIDE_ATTRIBUTES|PRESERVE_ATTRIBUTES);
    
    
//Adding 300 dammage bonus
    
TF2Items_SetAttribute(hItem02300);
    
TF2Items_SetNumAttributes(hItem1);
                
    
TF2Items_GiveNamedItem(clienthItem);
                
    
hItem item;

    return 
Plugin_Changed;

__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 09-16-2013 at 11:28.
Powerlord is offline