Raised This Month: $ Target: $400
 0% 

Simulate Player +use on a entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 08-01-2009 , 15:34   Simulate Player +use on a entity
Reply With Quote #1

Hi. I was trying a way to spawn a gun and equip to player in the mod Zombie Panic Source. The problem is that GivePlayerItem spawns the gun under the player and since this mod doesn't pick the gun when you walk over it stays on the ground until player notices and grab. Also EquipPlayerWeapon adds the gun to the client's weapon inventory but it's not useable. If you select the slot that the gun is in it doesn't change to that gun. So I was thinking on make it like the player used +use on the gun so it'd equip properly.

For this mod the inputs of guns are:
Code:
SetTeam
Kill
KillHierarchy
Use
Alpha
AlternativeSorting
Color
SetParent
SetParentAttachment
SetParentAttachmentMaintainOffset
ClearParent
SetDamageFilter
EnableDamageForces
DisableDamageForces
DispatchEffect
DispatchResponse
AddContext
RemoveContext
ClearContext
DisableShadow
EnableShadow
AddOutput
FireUser1
FireUser2
FireUser3
FireUser4
I was thinking about using "Use" input but I'm not really sure how to make it work properly with AcceptEntityInput.

Code:
Syntax: native bool:AcceptEntityInput(dest, const String:input[], activator=-1, caller=-1, outputid=0); 

Usage:  dest        Destination entity index.
 input        Input action.
 activator    Entity index which initiated the sequence of actions (-1 for a NULL entity).
 caller    Entity index from which this event is sent (-1 for a NULL entity).
outputid    Unknown.
Sammy-ROCK! is offline
Theme97
Senior Member
Join Date: Mar 2009
Old 08-01-2009 , 20:14   Re: Simulate Player +use on a entity
Reply With Quote #2

Try this:

PHP Code:
AcceptEntityInput(weapon_index"Use"clientclient); 
__________________
I now have very little time to work on stuff and my main computer (which is the only one that can run TF2) is not cooperating with me, so don't expect many updates from me anytime soon.

[ALL] Karaoke
[TF2] Intel Timer | Crabmod | Randomizer | Stopwatch | Crits 4 All
Theme97 is offline
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 08-01-2009 , 21:49   Re: Simulate Player +use on a entity
Reply With Quote #3

Didn't work.

Code:
public OnPluginStart()
{
    RegAdminCmd("sm_weapon_equip", Command_Weapon, ADMFLAG_CHEATS)
}

public Action:Command_Weapon(client, args)
{
    if(args < 2)
    {
        ReplyToCommand(client, "Usage: sm_weapon_equip <target> <weapon or ammo>");
        return Plugin_Handled;
    }
    decl String:arg[MAX_NAME_LENGTH];
    GetCmdArg(1, arg, sizeof(arg));
    decl String:target_name[MAX_TARGET_LENGTH];
    decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
    if((target_count = ProcessTargetString(arg, 0, target_list, MAXPLAYERS, 0, target_name, sizeof(target_name), tn_is_ml)) <= 0)
        return Plugin_Handled;
    GetCmdArg(2, arg, sizeof(arg));
    for(new i = 0; i < target_count; i++)
    {
        new target = target_list[i];
        new WeaponEnt = GivePlayerItem(target, arg);
        AcceptEntityInput(WeaponEnt, "Use", target, target);
        ReplyToCommand(client, "Equiped %N with a %s", target, arg);
        PrintToChat(target, "%N gave you a %s", client, arg);
    }
    return Plugin_Handled;
}
Sammy-ROCK! is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 08-02-2009 , 14:30   Re: Simulate Player +use on a entity
Reply With Quote #4

Try setting an empty entry in m_hMyWeapons to the entity index of the weapon. For example..

PHP Code:
new offset FindSendPropInfo("CTFPlayer""m_hMyWeapons");
for (new 
0<= 47i++)
{
    if (
GetEntDataEnt2(targetoffset+(i*4)) == 0)
    {
        new 
weapon GivePlayerItem(targetarg);
        
SetEntDataEnt2(targetoffset+(i*4), weapon);
        break;
    }

You might want to do some testing to see what the blank value might be (it's probably not 0, like I put in the if statement).
bl4nk is offline
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 08-02-2009 , 19:21   Re: Simulate Player +use on a entity
Reply With Quote #5

GetEntData2 returns -1 if no entity is found or it's invalid.
Code:
Entity index at the given location.  If there is no entity, or the stored entity is invalid, then -1 is returned.
Trying this.
Since in zps m_hMyWeapons is 40 bytes I decreased "i" to 9 max. (9x4 = 36 + 4 bytes = 40(limit))
Sammy-ROCK! is offline
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 08-02-2009 , 19:36   Re: Simulate Player +use on a entity
Reply With Quote #6

It worked just like EquipPlayerWeapon. It shows in inventory. But the gun is still on the ground and the inventory slot shows the gun but if you press that key you holst. Also if you try to grab the gun you pick it's ammo (Game thing if you grab a gun you already have you get it's ammo).

Code:
public OnPluginStart()
{
    RegAdminCmd("sm_weapon_equip", Command_Weapon, ADMFLAG_CHEATS)
}

public Action:Command_Weapon(client, args)
{
    if(args < 2)
    {
        ReplyToCommand(client, "Usage: sm_weapon_equip <target> <weapon or ammo>");
        return Plugin_Handled;
    }
    decl String:arg[MAX_NAME_LENGTH];
    GetCmdArg(1, arg, sizeof(arg));
    decl String:target_name[MAX_TARGET_LENGTH];
    decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
    if((target_count = ProcessTargetString(arg, 0, target_list, MAXPLAYERS, 0, target_name, sizeof(target_name), tn_is_ml)) <= 0)
        return Plugin_Handled;
    GetCmdArg(2, arg, sizeof(arg));
    new offset = FindSendPropInfo("CHL2MP_Player", "m_hMyWeapons");
    for(new i = 0; i < target_count; i++)
    {
        new target = target_list[i];
        new WeaponEnt = GivePlayerItem(target, arg);
        for (new d = 0; d < 10; d++)
        {
            if(GetEntDataEnt2(target, offset+(d*4)) == -1)
            {
                SetEntDataEnt2(target, offset+(d*4), WeaponEnt);
                break;
            }
        }
        ReplyToCommand(client, "Equiped %N with a %s", target, arg);
        PrintToChat(target, "%N gave you a %s", client, arg);
    }
    return Plugin_Handled;
}
Sammy-ROCK! is offline
will2tango
Member
Join Date: Nov 2009
Location: England
Old 12-11-2009 , 21:36   Re: Simulate Player +use on a entity
Reply With Quote #7

Hi Sammy,
Did you manage to finish this plugin? im hoping you wouldnt mind sharing your knowledge. Thanks
will2tango 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 23:08.


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