Raised This Month: $2 Target: $400
 0% 

[Team Fortress 2]How to get real weapon?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Master Cake
Junior Member
Join Date: May 2020
Location: Planet Earth
Old 06-09-2020 , 23:37   [Team Fortress 2]How to get real weapon?
Reply With Quote #1

Hello everyone! I have a problem with getting weapon in primary slot.

Here is code:
Code:
int weaponIndex = GetPlayerWeaponSlot(myClient, 0); //Save ENTITY index
Item[myClient] = GetEntProp(weaponIndex, Prop_Send,  "m_iItemDefinitionIndex"); //Save WEAPON index to the array for users. (need that to store initial weapon for each client)

SetEntProp(weaponIndex, Prop_Send,  "m_iItemDefinitionIndex", 513); //513 - weapon index Original Rocket Launcher (indexes)
When I execute it gives me <"Original">. Rockets, weapon model and sounds are like a Stock RL but model position and rotation angles are like an Original RL. And after regeneration my HP or ammo I get Stock again.

What am I doing wrong?

Last edited by Master Cake; 06-09-2020 at 23:38.
Master Cake is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-10-2020 , 04:06   Re: [Team Fortress 2]How to get real weapon?
Reply With Quote #2

You can’t sanely change the item definition index on an already spawned entity - use TF2Items and its forward instead.
__________________
asherkin is offline
Master Cake
Junior Member
Join Date: May 2020
Location: Planet Earth
Old 06-10-2020 , 10:17   Re: [Team Fortress 2]How to get real weapon?
Reply With Quote #3

Text from tf2_stocks.inc:

Code:
/**
 * Sets client data in the resource entity
 *
 * Note: The game overwrites these values every frame, so changing them will have very little effect.
 *
 * @param client        Player's index.
 * @param type          ResourceType constant
 * @param value         Value to set.
 * @return              Value or -1 on failure.
 * @error               Invalid client index, client not in game or failed to find resource entity.
 * @deprecated          Use GetPlayerResourceEntity and SetEntProp instead.
 */
#pragma deprecated Use GetPlayerResourceEntity and SetEntProp instead
stock bool TF2_SetPlayerResourceData(int client, TFResourceType type, any value)
Hmmm looks like I have a standoff Why does TF2 overwrite values every frame? So, I can't change my weapon again.

Last edited by Master Cake; 06-10-2020 at 15:48.
Master Cake is offline
PC Gamer
Senior Member
Join Date: Mar 2014
Old 06-10-2020 , 16:55   Re: [Team Fortress 2]How to get real weapon?
Reply With Quote #4

What exactly are you trying to accomplish in your script?

There are different ways to give a player a weapon. The most common ways are to use either tf2items_giveweapon plugin or tf2items plugin.

For example, in your script you can use:
PHP Code:
#include <tf2items_giveweapon> 
And later in your code you can use:
PHP Code:
TF2_RemoveWeaponSlot(client0);
TF2Items_GiveWeapon(client298); //Iron Curtain 
The weapons you give will be removed when the player dies or touches a locker. No other players will be able to see the weapons you gave. However, if you give weapons to a Bot the players will be able to see the weapons. You can use the TF2Attributes include to give additional attributes to weapons.

Brief video example of player getting several different weapons with attributes:
PC Gamer is offline
Master Cake
Junior Member
Join Date: May 2020
Location: Planet Earth
Old 06-10-2020 , 19:16   Re: [Team Fortress 2]How to get real weapon?
Reply With Quote #5

Ok I understand. If weapon will be removed when the player touches a locker, that's not what I need. Ehh sadly, Source doesn't allow force changing weapon to clients.
Master Cake is offline
PC Gamer
Senior Member
Join Date: Mar 2014
Old 06-10-2020 , 20:38   Re: [Team Fortress 2]How to get real weapon?
Reply With Quote #6

What exactly are you trying to accomplish in your plugin?

You can write code that hooks the event that fires when player touches a locker (post_inventory_application). You can then force give a particular weapon to a player at that time. tf2items_giveweapon plugin does this for you with the command giveweapon_ex. Everytime you spawn or touch locker it will force give you the same weapon. You can do this yourself with code.
PC Gamer is offline
Master Cake
Junior Member
Join Date: May 2020
Location: Planet Earth
Old 06-11-2020 , 14:31   Re: [Team Fortress 2]How to get real weapon?
Reply With Quote #7

I see TF2Itmes is useful. I will try to do it in my own way with hooks, many thanks
Master Cake is offline
Reply


Thread Tools
Display Modes

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 10:57.


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