Skip to content

Commit 2dfc66a

Browse files
committed
feat(scripting/weapon): SetDefaultAttributes
1 parent 3d6941c commit 2dfc66a

File tree

4 files changed

+75
-3
lines changed

4 files changed

+75
-3
lines changed

src/plugins/core/scripting.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,11 @@ class PluginDatabase
343343
class PluginCHandle
344344
{
345345
private:
346-
CHandle<CEntityInstance> *m_Handle;
346+
CHandle<CEntityInstance> *m_Handle;
347+
347348
public:
348349
PluginCHandle(std::string ptr);
349-
PluginCHandle(void* ptr);
350+
PluginCHandle(void *ptr);
350351

351352
std::string GetPtr();
352353
void SetPtr(std::string ptr);
@@ -497,6 +498,7 @@ class PluginWeapon
497498

498499
void Drop();
499500
void Remove();
501+
void SetDefaultAttributes();
500502
};
501503

502504
//////////////////////////////////////////////////////////////

src/plugins/core/scripting/weapons.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,73 @@ void PluginWeapon::Remove()
213213
itemServices->DropPlayerWeapon(this->m_ptr);
214214
weaponServices->RemoveWeapon(this->m_ptr);
215215
this->m_ptr->Despawn();
216+
}
217+
218+
std::vector<uint16_t> paintkitsFallbackCheck = {1171, 1170, 1169, 1164, 1162, 1161, 1159, 1175, 1174, 1167, 1165, 1168, 1163, 1160, 1166, 1173};
219+
220+
void PluginWeapon::SetDefaultAttributes()
221+
{
222+
if (!this->m_ptr)
223+
return;
224+
225+
Player *player = g_playerManager->GetPlayer(m_playerId);
226+
if (!player)
227+
return;
228+
229+
CCSPlayerPawn *pawn = player->GetPlayerPawn();
230+
if (!pawn)
231+
return;
232+
233+
this->m_ptr->m_AttributeManager().m_Item().m_iItemIDHigh = -1;
234+
235+
if (this->m_ptr->GetWeaponVData()->m_GearSlot == cgear_slot_t::GEAR_SLOT_KNIFE)
236+
{
237+
this->m_ptr->m_AttributeManager().m_Item().m_iEntityQuality = 3;
238+
}
239+
240+
int paintkit = this->m_ptr->m_nFallbackPaintKit();
241+
bool legacy = (std::find(paintkitsFallbackCheck.begin(), paintkitsFallbackCheck.end(), paintkit) == paintkitsFallbackCheck.end());
242+
243+
if (this->m_ptr->m_CBodyComponent() && this->m_ptr->m_CBodyComponent()->m_pSceneNode())
244+
{
245+
CSkeletonInstance *skeleton = this->m_ptr->m_CBodyComponent()->m_pSceneNode()->GetSkeletonInstance();
246+
if (skeleton)
247+
{
248+
if (skeleton->m_modelState().m_MeshGroupMask() != (legacy == true ? 2 : 1))
249+
{
250+
skeleton->m_modelState().m_MeshGroupMask = (legacy == true ? 2 : 1);
251+
}
252+
}
253+
}
254+
255+
CCSPlayer_ViewModelServices *viewmodelServices = pawn->m_pViewModelServices();
256+
if (!viewmodelServices)
257+
return;
258+
259+
CHandle<CBaseViewModel> *viewmodelHandles = viewmodelServices->m_hViewModel();
260+
if (!viewmodelHandles)
261+
return;
262+
if (!viewmodelHandles[0])
263+
return;
264+
if (!viewmodelHandles[0].IsValid())
265+
return;
266+
267+
CBaseViewModel *viewmodel = viewmodelHandles[0].Get();
268+
269+
if (!viewmodel)
270+
return;
271+
272+
if (viewmodel->m_CBodyComponent() && viewmodel->m_CBodyComponent()->m_pSceneNode())
273+
{
274+
CSkeletonInstance *viewmodelskeleton = viewmodel->m_CBodyComponent()->m_pSceneNode()->GetSkeletonInstance();
275+
if (viewmodelskeleton)
276+
{
277+
if (viewmodelskeleton->m_modelState().m_MeshGroupMask() != (legacy == true ? 2 : 1))
278+
{
279+
viewmodelskeleton->m_modelState().m_MeshGroupMask = (legacy == true ? 2 : 1);
280+
}
281+
}
282+
}
283+
284+
viewmodel->m_CBodyComponent.StateUpdate();
216285
}

src/plugins/lua/scripting/weapons.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void SetupLuaWeapons(LuaPlugin *plugin, lua_State *state)
1616
.addFunction("CCSWeaponBase", &PluginWeapon::GetCCSWeaponBase)
1717
.addFunction("CBasePlayerWeaponVData", &PluginWeapon::GetCBasePlayerWeaponVData)
1818
.addFunction("CCSWeaponBaseVData", &PluginWeapon::GetCCSWeaponBaseVData)
19+
.addFunction("SetDefaultAttributes", &PluginWeapon::SetDefaultAttributes)
1920
.addFunction("Drop", &PluginWeapon::Drop)
2021
.addFunction("Remove", &PluginWeapon::Remove)
2122
.endClass();

src/sdk/entity/CBaseEntity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CEntitySubclassVDataBase
3636
class CModelState
3737
{
3838
public:
39-
DECLARE_SCHEMA_CLASS_BASE(CModelState, false)
39+
DECLARE_SCHEMA_CLASS_BASE(CModelState, true)
4040

4141
SCHEMA_FIELD_OFFSET(uint64_t, m_MeshGroupMask, 0)
4242
};

0 commit comments

Comments
 (0)