Raised This Month: $32 Target: $400
 8% 

Solved [Answered]Would this make everyone's weapon quality Valve?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 12-30-2013 , 15:35   [Answered]Would this make everyone's weapon quality Valve?
Reply With Quote #1

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.

Last edited by WildCard65; 12-31-2013 at 14:11.
WildCard65 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-30-2013 , 16:14   Re: Would this make everyone's weapon quality Valve?
Reply With Quote #2

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.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-30-2013 at 16:19.
Powerlord is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 12-30-2013 , 16:16   Re: Would this make everyone's weapon quality Valve?
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
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)
WildCard65 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-30-2013 , 16:19   Re: Would this make everyone's weapon quality Valve?
Reply With Quote #4

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)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-30-2013 at 16:20.
Powerlord is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 12-30-2013 , 16:48   Re: Would this make everyone's weapon quality Valve?
Reply With Quote #5

Quote:
Originally Posted by Powerlord View Post
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.

Last edited by WildCard65; 12-30-2013 at 16:49.
WildCard65 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-30-2013 , 16:53   Re: Would this make everyone's weapon quality Valve?
Reply With Quote #6

Quote:
Originally Posted by WildCard65 View Post
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.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-30-2013 at 16:55.
Powerlord is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 12-30-2013 , 17:03   Re: Would this make everyone's weapon quality Valve?
Reply With Quote #7

Did that, still crashes.
WildCard65 is offline
DarthNinja
SourceMod Plugin Approver
Join Date: Mar 2009
Location: PreThinkHook()
Old 12-30-2013 , 23:39   Re: Would this make everyone's weapon quality Valve?
Reply With Quote #8

You could just change the value of m_iEntityQuality and m_iEntityLevel and not have to deal with TF2Items.
__________________

Last edited by DarthNinja; 12-30-2013 at 23:39.
DarthNinja is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 12-31-2013 , 08:20   Re: Would this make everyone's weapon quality Valve?
Reply With Quote #9

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;

__________________
asherkin is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 12-31-2013 , 08:39   Re: Would this make everyone's weapon quality Valve?
Reply With Quote #10

Quote:
Originally Posted by asherkin View Post
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)
WildCard65 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 16:53.


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