1+ public void Message_GiveWeapon (const String :type [], const String :message [], const JSON_Object :jsondata , WebsocketHandle :websocket ) {
2+ if (! tf2itemsENABLED ) {
3+ SendSimpleMessage (websocket , " Error" , " TF2ItemsMissing" );
4+ return ;
5+ }
6+
7+ JSON_Object weapondata = jsondata .GetObject (" message" )
8+
9+ int player = weapondata .GetInt (" id" );
10+ int weaponid = weapondata .GetInt (" weaponid" );
11+ int weaponslot = weapondata .GetInt (" weaponslot" );
12+ char classname [32 ];
13+ weapondata .GetString (" weaponclassname" , classname , sizeof (classname ));
14+
15+ JSON_Array attributes = view_as <JSON_Array >(weapondata .GetObject (" attributes" ));
16+
17+ new Handle :item = TF2Items_CreateItem (PRESERVE_ATTRIBUTES );
18+ TF2Items_SetClassname (item , classname );
19+ TF2Items_SetItemIndex (item , weaponid );
20+ TF2Items_SetNumAttributes (item , attributes .Length );
21+
22+ for (int i = 0 ; i < attributes .Length ; i += 1 ) {
23+ JSON_Object data = attributes .GetObject (i );
24+
25+ char type [16 ];
26+ data .GetString (" type" , type , sizeof (type ));
27+
28+ if (StrEqual (type , " float" )) {
29+ TF2Items_SetAttribute (item , i , data .GetInt (" id" ), data .GetFloat (" value" ));
30+ } else if (StrEqual (type , " int" )) {
31+ TF2Items_SetAttribute (item , i , data .GetInt (" id" ), data .GetInt (" value" ));
32+ } else if (StrEqual (type , " bool" )) {
33+ if (data .GetBool (" value" ) == true ) {
34+ TF2Items_SetAttribute (item , i , data .GetInt (" id" ), 1.0 );
35+ } else {
36+ TF2Items_SetAttribute (item , i , data .GetInt (" id" ), 0.0 );
37+ }
38+ }
39+ }
40+
41+ TF2_RemoveWeaponSlot (player , weaponslot );
42+ new entity = TF2Items_GiveNamedItem (player , item );
43+ SetEntProp (entity , Prop_Send , " m_bValidatedAttachedEntity" , 1 );
44+ EquipPlayerWeapon (player , entity );
45+ }
0 commit comments