This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

tf2 gun mettle update. spawn weapon on the ground?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Randommagic
Senior Member
Join Date: Jun 2014
Location: -
Old 07-06-2015 , 06:54   tf2 gun mettle update. spawn weapon on the ground?
Reply With Quote #1

Yay. New update which might break lots of mods and plugins.

Is it possible to spawn a specific weapon on the ground by command? Maybe something like giveweapon, but not actually giving a user weapon, just spawning it on the ground.

__________________
Randommagic is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-06-2015 , 10:07   Re: tf2 gun mettle update. spawn weapon on the ground?
Reply With Quote #2

To be honest, I'm not sure if it's currently possible.

I will say this: It's likely only possible to create regular items (without skins) this way. The reason being that SourceMod can't modify item attributes for dropped weapons because it uses a CUtlVector netprop, which SourceMod doesn't support.

Since I haven't tried creating them yet, I'm not sure if items will be visible if the item ID or account ID are empty.

The TF2Attributes plugin might be able to add attributes to it, though...
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 07-06-2015 , 10:11   Re: tf2 gun mettle update. spawn weapon on the ground?
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
To be honest, I'm not sure if it's currently possible.

I will say this: It's likely only possible to create regular items (without skins) this way. The reason being that SourceMod can't modify item attributes for dropped weapons because it uses a CUtlVector netprop, which SourceMod doesn't support.

Since I haven't tried creating them yet, I'm not sure if items will be visible if the item ID or account ID are empty.

The TF2Attributes plugin might be able to add attributes to it, though...
Spawning works, all you do is set the m_iItemDefinitionIndex to an index and on pickup the weapon will have that items default attributes, you can add attributes to dropped weapons with TF2Attributes and spawned dropped weapons are visible on pickup for everyone on the server
__________________
Pelipoika is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 07-06-2015 , 15:15   Re: tf2 gun mettle update. spawn weapon on the ground?
Reply With Quote #4

https://forums.alliedmods.net/showthread.php?t=265737

Trying to do that myself but I'm failing. Suggestions from experts would be helpful.
Potato Uno is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 07-06-2015 , 15:34   Re: tf2 gun mettle update. spawn weapon on the ground?
Reply With Quote #5

Quote:
Originally Posted by Potato Uno View Post
https://forums.alliedmods.net/showthread.php?t=265737

Trying to do that myself but I'm failing. Suggestions from experts would be helpful.
You need to give it a model
__________________
Pelipoika is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 07-06-2015 , 15:53   Re: tf2 gun mettle update. spawn weapon on the ground?
Reply With Quote #6

So I have to precache ALL the weapon models?

Oh good lord. I'll try that then. Thanks!
Potato Uno is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 07-06-2015 , 16:00   Re: tf2 gun mettle update. spawn weapon on the ground?
Reply With Quote #7

Quote:
Originally Posted by Potato Uno View Post
So I have to precache ALL the weapon models?

Oh good lord. I'll try that then. Thanks!
Use TF2IDB query weapon model from it with the weapon index and precache it before spawn?
__________________
Pelipoika is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 07-06-2015 , 16:07   Re: tf2 gun mettle update. spawn weapon on the ground?
Reply With Quote #8

Nah I got it to work, it does fall, except I can't pick it up. Is there some netprop I need to change so it is pickup-able?

If it works, then I can post the final plugin here.

(Thanks for your help so far by the way - appreciate it.)

INSTANT EDIT: I'm guessing that the reason why I can't pick it up is because the game probably thinks I'm not a soldier.

Last edited by Potato Uno; 07-06-2015 at 16:08.
Potato Uno is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 07-06-2015 , 16:14   Re: tf2 gun mettle update. spawn weapon on the ground?
Reply With Quote #9

Quote:
Originally Posted by Potato Uno View Post
Nah I got it to work, it does fall, except I can't pick it up. Is there some netprop I need to change so it is pickup-able?

If it works, then I can post the final plugin here.

(Thanks for your help so far by the way - appreciate it.)

INSTANT EDIT: I'm guessing that the reason why I can't pick it up is because the game probably thinks I'm not a soldier.
Try setting m_bInitialized to 1
__________________
Pelipoika is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 07-06-2015 , 16:22   Re: tf2 gun mettle update. spawn weapon on the ground?
Reply With Quote #10

That seemed to have done the trick. Thank you very much!

I haven't actually done it properly, and I just hard-coded in the direct hit model precache out of laziness, but here's the skeleton code for anyone who wants to incorporate it into a plugin. The DropWeapon() function is 90% correct, except that it will look like a direct hit all the time. I'll finish this fully when I have time later, but this should get you started.

PHP Code:
#include <sourcemod>
#include <sdktools>

public OnPluginStart()
{
    
RegConsoleCmd("sm_drop"DropWeapon"Spawns a dropped weapon at your feet. Usage: sm_drop [item index]");
}

public 
OnMapStart()
{
    
PrecacheModel("models/weapons/c_models/c_directhit/c_directhit.mdl"true);
    
// Need to add more precaches here
}

public 
Action DropWeapon(iClientnArgs)
{
    
char index[10];
    
GetCmdArg(1index10);
    
int Entity CreateEntityByName("tf_dropped_weapon");
    
SetEntProp(EntityProp_Send"m_iItemDefinitionIndex"StringToInt(index));
//    SetEntProp(Entity, Prop_Send, "m_nModelIndex", 662);         Don't think this is needed.
    
SetEntProp(EntityProp_Send"m_iEntityLevel"5);
    
SetEntProp(EntityProp_Send"m_iEntityQuality"6);
    
SetEntProp(EntityProp_Send"m_bInitialized"1);
    
float coordinates[3];
    
GetClientAbsOrigin(iClientcoordinates);
    
GetEntPropVector(iClientProp_Send"m_vecOrigin"coordinates);
    
TeleportEntity(EntitycoordinatesNULL_VECTORNULL_VECTOR);
    
SetEntityModel(Entity"models/weapons/c_models/c_directhit/c_directhit.mdl");
    
DispatchSpawn(Entity);
    
PrintToChatAll("Command ran %.2f %.2f %.2f"coordinates[0], coordinates[1], coordinates[2]);

Oh I should also note that you won't have any ammo in the weapon when you pick it up. Just find an ammo crate or something (I probably need to find some netprop to put ammo in it later).

Last edited by Potato Uno; 07-06-2015 at 16:24.
Potato Uno 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 15:47.


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