Raised This Month: $ Target: $400
 0% 

Plugin_Changed not working for me


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CoolJosh3k
AlliedModders Donor
Join Date: Mar 2010
Old 05-14-2013 , 23:41   Plugin_Changed not working for me
Reply With Quote #1

PHP Code:
/* * *
 * tf2items code written with help from asherkin
 * * */

#include <sourcemod>
#include <sdktools>
#include <tf2items> 

new Handle:Heavy_Sandvich INVALID_HANDLE;

public 
Plugin:myinfo =
{
    
name "sandvichtest",
    
author "CoolJosh3k",
    
description "Swaps the stock shotgun for a sandvich",
    
version "1.0.0",
    
url ""
}

public 
OnPluginStart()
{
    
Heavy_Sandvich TF2Items_CreateItem(OVERRIDE_ALL FORCE_GENERATION);
    
TF2Items_SetClassname(Heavy_Sandvich"tf_weapon_lunchbox");
    
TF2Items_SetItemIndex(Heavy_Sandvich42);
    
TF2Items_SetQuality(Heavy_Sandvich6);
    
TF2Items_SetLevel(Heavy_Sandvich1);
    
TF2Items_SetNumAttributes(Heavy_Sandvich0);
}

public 
Action:TF2Items_OnGiveNamedItem(clientString:classname[], iItemDefinitionIndex, &Handle:hItem)
{
    if (
iItemDefinitionIndex == 11)
    {
        
hItem Heavy_Sandvich;
        return 
Plugin_Changed;
    }
    return 
Plugin_Continue;

That sample from my code, doesn't work quite as planned.

If the player has a heavy stock shotgun, I want to force a sandvich instead. It does take the shotgun away, but it does not replace it with the sandvich.

The versions are:

Code:
] meta version
Metamod:Source version 1.9.1
Build ID: 805:44644c375f80
Loaded As: Valve Server Plugin
Compiled on: Dec 23 2012
Plugin interface version: 15:14
SourceHook version: 5:5
http://www.metamodsource.net/
] sm version
 SourceMod Version Information:
    SourceMod Version: 1.5.0-dev+3838
    SourcePawn Engine: SourcePawn 1.1, jit-x86 (build 1.5.0-dev+3838)
    SourcePawn API: v1 = 4, v2 = 4
    Compiled on: May  3 2013 12:46:42
    Build ID: 3838:32bab19b2f64
    http://www.sourcemod.net/
] tf2items_version 
"tf2items_version" = "1.5.3"
 notify singleplayer replicated
 - TF2 Items Version
CoolJosh3k is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-14-2013 , 23:46   Re: Plugin_Changed not working for me
Reply With Quote #2

While you can changes an items attributes in TF2Items_OnGiveNamedItem, you can't change its classname or item definition index. Instead, you'll have to block it and give them a new item instead.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
CoolJosh3k
AlliedModders Donor
Join Date: Mar 2010
Old 05-15-2013 , 03:01   Re: Plugin_Changed not working for me
Reply With Quote #3

Ah, that explains it. Thanks!

What is the best way to go about TF2Items_GiveNamedItem? I am thinking using a 0.1 timer on respawn/resupply is not a good way.

I don't suppose it is possible to both block then give, on the same game frame?
CoolJosh3k is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-15-2013 , 10:19   Re: Plugin_Changed not working for me
Reply With Quote #4

Quote:
Originally Posted by CoolJosh3k View Post
Ah, that explains it. Thanks!

What is the best way to go about TF2Items_GiveNamedItem? I am thinking using a 0.1 timer on respawn/resupply is not a good way.

I don't suppose it is possible to both block then give, on the same game frame?
Whenever a player's loadout changes, the post_inventory_application event fires. If you've previously blocked an item from being given to that player, GetPlayerWeaponSlot will return -1 for that slot.

It couldn't hurt to take a peek at what I did in the Huntsman Hell plugin, since it uses exactly this method.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
CoolJosh3k
AlliedModders Donor
Join Date: Mar 2010
Old 05-16-2013 , 05:03   Re: Plugin_Changed not working for me
Reply With Quote #5

Great! Thankyou for your help on this.
CoolJosh3k is offline
CoolJosh3k
AlliedModders Donor
Join Date: Mar 2010
Old 05-18-2013 , 09:21   Re: Plugin_Changed not working for me
Reply With Quote #6

Bonus question:

PHP Code:
new class = TF2_GetPlayerClass(client); 
Code:
warning 213: tag mismatch
I must say, I am confused.
CoolJosh3k is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 05-18-2013 , 14:53   Re: Plugin_Changed not working for me
Reply With Quote #7

Getplayerclass does not return a native, it returns a tf2class type
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
CoolJosh3k
AlliedModders Donor
Join Date: Mar 2010
Old 05-19-2013 , 12:33   Re: Plugin_Changed not working for me
Reply With Quote #8

Quote:
Originally Posted by friagram View Post
Getplayerclass does not return a native, it returns a tf2class type
Ah, now I get it. If it is a 'stock' instead of 'native', I need to check the include file to see what tag/format it uses. Seems rather obvious now.
CoolJosh3k is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-19-2013 , 17:46   Re: Plugin_Changed not working for me
Reply With Quote #9

Quote:
Originally Posted by CoolJosh3k View Post
Ah, now I get it. If it is a 'stock' instead of 'native', I need to check the include file to see what tag/format it uses. Seems rather obvious now.
Any type of function can return a different tag.
__________________
asherkin is offline
CoolJosh3k
AlliedModders Donor
Join Date: Mar 2010
Old 05-19-2013 , 19:33   Re: Plugin_Changed not working for me
Reply With Quote #10

I gotta admit, I find C+ easier than SourcePawn.
CoolJosh3k 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 09:37.


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