Raised This Month: $51 Target: $400
 12% 

[HELP] With the function TF2Items_SetAttribute


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 09-16-2013 , 07:48   [HELP] With the function TF2Items_SetAttribute
Reply With Quote #1

Well, I don't understand how do you can set/edit attributs of a weapon using TF2Items_SetAttribute and keeping the old attributs.
A exemple who explain this would be amazing
__________________
Want to check my plugins ?
Arkarr is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 09-16-2013 , 09:41   Re: [HELP] With the function TF2Items_SetAttribute
Reply With Quote #2

Include the PRESERVE_ATTRIBUTES flag when calling TF2Items_CreateItem.
__________________
asherkin is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 09-16-2013 , 11:03   Re: [HELP] With the function TF2Items_SetAttribute
Reply With Quote #3

if you have read it, forget it.

my fault was this one :

[HANDLE HERE] = TF2Items_CreateItem(PRESERVE_ATTRIBUTES);
__________________
Want to check my plugins ?

Last edited by Arkarr; 09-16-2013 at 11:20. Reason: WOW, you have seen nothing, NOTHING !
Arkarr is offline
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
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 09-16-2013 , 11:21   Re: [HELP] With the function TF2Items_SetAttribute
Reply With Quote #5

Thanks, as you can see, I just edited my last post. Then thanks for OVERRIDE_ATTRIBUTES I didn't know that. Hope, it will work now...

EDIT :

what's wrong with this now ? Any error printed in consol

PHP Code:
public Action:TF2Items_OnGiveNamedItem(clientString:classname[], iItemDefinitionIndex, &Handle:hItem)
{                
    
hItem TF2Items_CreateItem(OVERRIDE_ATTRIBUTES|PRESERVE_ATTRIBUTES);  
    
    
TF2Items_SetItemIndex(hItemiItemDefinitionIndex);
    
    
TF2Items_SetClassname(hItemclassname);
    
    
TF2Items_SetQuality(hItem9);
    
    
TF2Items_SetLevel(hItem100);
    
    
//Give 50 health on kill ONLY IF KILLED WITH SECOND WEAPON
    
TF2Items_SetAttribute(hItem518050.0);
    
    
TF2Items_GiveNamedItem(clienthItem);
    
    
CloseHandle(hItem);

    return 
Plugin_Continue;

Note : Where can I found all the flags for TF2Items_CreateItem ?
__________________
Want to check my plugins ?

Last edited by Arkarr; 09-16-2013 at 11:47.
Arkarr is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 09-16-2013 , 15:22   Re: [HELP] With the function TF2Items_SetAttribute
Reply With Quote #6

Damm... Still have a lot to learn, thanks !

Edit : Did you tested your code ? Maybe it's only on my server but it seems that's handle still give errors .
__________________
Want to check my plugins ?

Last edited by Arkarr; 09-16-2013 at 15:28.
Arkarr is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:48.


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