ItsMods

Full Version: Changing weapons
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I want to change the weapons of the clients, and this is also working, but if they climb on something they loose the weapon. You have to press 1 again to swap back which is really annoying.

I Could fix this with calling the Method SwitchToWeapon. But this method is only implementend it the current unstable version of nukems server addon. So i tried to decompile it to find the function and implement it myself.

Code:
[StructLayout(LayoutKind.Sequential, Size = 0x278), UnsafeValueType, MiscellaneousBits(0x41), DebugInfoInPDB, NativeCppClass]
internal struct Entity_t
{
}
unsafe public static class Other_TExtensionMethods
{
      [SuppressUnmanagedCodeSecurity]
      [MethodImpl(MethodImplOptions.Unmanaged | MethodImplOptions.PreserveSig, MethodCodeType = MethodCodeType.Native)]
      public static extern void ServerSwitchToWeapon([In] int obj0, [In] int obj1);


    private static unsafe Entity_t* CG;

    public static void SwitchToWeapon(this Other_t other, int WeaponID)
    {
        Other_TExtensionMethods.ServerSwitchToWeapon(*((int*)Other_TExtensionMethods.CG), WeaponID);
    }
}

actually this is compiling, but the addon will not get loaded then.

My code to swap the weapon is:
Code:
this.ServerClient.Other.OffhandWeapon = this.PrimaryWeapon.GetID();
this.ServerClient.Other.CurrentWeapon = this.ServerClient.Other.OffhandWeapon;
//The extension method from above
this.ServerClient.Other.SwitchToWeapon(this.ServerClient.Other.OffhandWeapon);

I hope sombody knows how to implement this function or an other way to avoid that the weapon disapears on climbin.