|
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
|
09-16-2013
, 11:18
Re: [HELP] With the function TF2Items_SetAttribute
|
#4
|
Quote:
Originally Posted by Arkarr
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(client, String:classname[], iItemDefinitionIndex, &Handle:hItem) { TF2Items_CreateItem(PRESERVE_ATTRIBUTES); //Adding 300 dammage bonus TF2Items_SetAttribute(hItem, 1, 2, 300); TF2Items_GiveNamedItem(client, hItem); 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(client, String: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(hItem, 0, 2, 300); TF2Items_SetNumAttributes(hItem, 1); TF2Items_GiveNamedItem(client, hItem); hItem = item;
return Plugin_Changed; }
__________________
Not currently working on SourceMod plugin development.
Last edited by Powerlord; 09-16-2013 at 11:28.
|
|
|
|