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

Getting a weapons ent index


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
wgooch
Member
Join Date: Dec 2008
Old 05-02-2009 , 18:53   Getting a weapons ent index
Reply With Quote #1

I'm trying to write a plugin for sourcemod that allows you to equip a weapon to a player and remove weapons from players using RemovePlayerItem and EquipPlayerWeapon, I need to know how to create the weapon entity then get it's index so that it may be equiped to the player, and I need some sort of way to get the index of the weapon that I want to remove from the player. I'm guessing I can do something like that by using GetPlayerWeaponSlot, but I don't know what slot each weapon shows up in.
wgooch is offline
wgooch
Member
Join Date: Dec 2008
Old 05-02-2009 , 20:47   Re: Getting a weapons ent index
Reply With Quote #2

I've got this code up for equipping a player with a weapon
Code:
public Action:EquipPlayer(client, args)
{
    if (args < 2)
    {
        ReplyToCommand(client, "[SM] Usage: sm_equip <#userid|name> <Item>");
        return Plugin_Handled;
    }
    decl String:target_name[MAX_TARGET_LENGTH];
    decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
    
    decl String:arg[65], String:itemclass[82];
    GetCmdArg(1, arg, sizeof(arg) );
    GetCmdArg(2, itemclass, sizeof(itemclass) );
    
    new item = CreateEntityByName(itemclass[82], -1);
    DispatchSpawn(item)
    if ((target_count = ProcessTargetString(
            arg,
            client,
            target_list,
            MAXPLAYERS,
            0,
            target_name,
            sizeof(target_name),
            tn_is_ml)) <= 0)
    {
        ReplyToTargetError(client, target_count);
        return Plugin_Handled;
    }
    
    for (new i = 0; i < target_count; i++)
    {
        PerformEquip(client, target_list[i], target_name, item);
    }
    
    return Plugin_Handled;
}
stock PerformEquip(client, target, const String:target_name[], item)
{
        EquipPlayerWeapon(target, item);
        ShowActivity2(client, TAG, "Equiped %s with weapon", target_name);
}
But when I run it I get this error
Code:
[SM] Native "DispatchSpawn" reported: NULL not allowed
[SM] Displaying call stack trace for plugin "itemgive.smx":
[SM]   [0]  Line 74, C:\Program Files\Steam\steamapps\common\left 4 dead\left4dead\_addons\sourcemod\scripting\itemgive.sp::EquipPlayer()
Line 74 reads DispatchSpawn(item)
wgooch is offline
Kigen
BANNED
Join Date: Feb 2008
Old 05-02-2009 , 22:46   Re: Getting a weapons ent index
Reply With Quote #3

new item = CreateEntityByName(itemclass[82], -1);
DispatchSpawn(item)

is bad, use:

native GivePlayerItem(client, const String:item[], iSubType=0);

i.e., new ent = GivePlayerItem(target, item);

ent has your entity index stored for you. The player already has the weapon and everything so you won't need to worry about associating it with a player or using DispatchSpawn().
Kigen is offline
wgooch
Member
Join Date: Dec 2008
Old 05-02-2009 , 23:43   Re: Getting a weapons ent index
Reply With Quote #4

Very helpful, thanks!

I'm still stumped on how to get the ent index of a weapon a player is holding

Last edited by wgooch; 05-03-2009 at 00:56.
wgooch is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 05-03-2009 , 04:58   Re: Getting a weapons ent index
Reply With Quote #5

GetEntPropEnt() for the m_hActiveWeapon property I believe it is.
__________________
CrimsonGT 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 21:35.


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