[HELP]I need help with loadfx

InfinityScript plugins for dedicated servers.
Dragonshot
TeknoCricket
TeknoCricket
Posts: 5
Joined: Sat Oct 17, 2015 5:00 am

[HELP]I need help with loadfx

Postby Dragonshot » Fri Jul 01, 2016 3:39 pm

Hello Everyone! :-> :-> :-> :-> :-> :-> I hope you all are fine.I want help please please.. i wanna have a gun like example iw5_mp9_mp_reflexsmg and when we shoot it the tactical insertion green one :P should come out when fired once fired the effect should close i mean the fx should close this should be with every bullet please don`t say i am noob at this i am just a begainner so please pardon me :-> :-> :->
btw i was just looking this it gave me hope but nope this doesnt work...

Code: Select all

using System;
using InfinityScript;

namespace designator
{
    public class designator : BaseScript
    {
        public override void OnSay(Entity player, string name, string message)
        {
            if (message == "!des")
            {
                player.GiveWeapon("iw5_mp9_mp_reflexsmg");
                player.SwitchToWeaponImmediate("iw5_mp9_mp_reflexsmg");
                player.OnNotify("missile_fire", (Entity owner, Parameter entity, Parameter weaponName) =>
                {
                    Entity missile = entity.As<Entity>();
                    string wep = weaponName.As<string>();
                    if (wep != "iw5_mp9_mp_reflexsmg")
                        return;
                    missile.OnNotify("death", (g) =>
                    {
                        Call("magicbullet", "", missile.Origin + new Vector3(0, 0, 6000), missile.Origin, player);
                        int loadfx = Call<int>("loadfx", "misc/laser_glow");
                        Vector3 target = missile.Origin;
                        Entity Effect = Call<Entity>("spawnFx", loadfx, target);
                        Call("triggerfx", Effect);
                        Effect.AfterDelay(500, h => Effect.Call("delete"));
                        //missile = null;
                    });
                });
            }
            if (message == "!uammo")
            {
                OnInterval(100, () =>
                {
                    if (!player.IsAlive)
                        return false;
                    player.Call("setweaponammoclip", player.CurrentWeapon, 2);
                    player.Call("setweaponammostock", player.CurrentWeapon, 2);
                    return true;
                });
            }
        }
    }
}
 


Please help me i will be very thankfull to you <3 :good:
User avatar
S3VDIT0
TeknoCow
TeknoCow
Posts: 68
Joined: Tue Jun 16, 2015 7:50 am
Location: Russian Federation
Contact:

Re: [HELP]I need help with loadfx

Postby S3VDIT0 » Fri Jul 01, 2016 4:26 pm

I think you can not read...

Code: Select all

 player.OnNotify("missile_fire", (Entity owner, Parameter entity, Parameter weaponName) =>

Use it https://teknogods.com/phpbb/viewtopic.php?f=76&t=37556 (thanks cubrr)
Dragonshot
TeknoCricket
TeknoCricket
Posts: 5
Joined: Sat Oct 17, 2015 5:00 am

Re: [HELP]I need help with loadfx

Postby Dragonshot » Fri Jul 01, 2016 6:44 pm

I am sorry but i didnt understood that player.notify one!!
I saw one thing on cubrr post.

this https://gfycat.com/FondRequiredIraniangroundjay
Yes i want like this just those tactical flames on iw5_mp9_mp_reflexsmg
User avatar
Boboo
TeknoDev
Posts: 145
Joined: Thu Jul 23, 2015 3:41 pm

Re: [HELP]I need help with loadfx

Postby Boboo » Fri Jul 01, 2016 8:31 pm

The custom notifys:

Code: Select all

player.Call("notifyonplayercommand", "spawnfx", "+attack");
player.OnNotify("spawnfx", ent =>
                     {
                         Vector3 targ = this.PhysicsTraceFromEye(player);
                         int fxhandle = Call<int>("loadFx", FxSkins[i]);
                         Entity effect = Call<Entity>("spawnfx", fxhandle, targ);
                         Call("triggerfx", effect);
                     });


The Extension methods :))

Code: Select all

public static class Trace //Thx to Cubrr <3
        {
            public static Vector3 PhysicsTrace(this BaseScript basecript, Vector3 start, Vector3 end)
            {
                return basecript.Call<Vector3>("physicstracenormal", start, end);
            }

            public static Vector3 PlayerPhysicsTrace(this BaseScript basecript, Vector3 start, Vector3 end)
            {
                return basecript.Call<Vector3>("playerphysicstrace", start, end);
            }

            public static Vector3 PhysicsTraceFromEye(this BaseScript basecript, Entity e)
            {
                Vector3 headpos = e.Call<Vector3>("gettagorigin", "j_eye");
                Vector3 forwangles = basecript.Call<Vector3>("anglestoforward", e.Call<Vector3>("getplayerangles"));
                Vector3 traceendpos = headpos + forwangles * 50 * 1000;
                return basecript.PhysicsTrace(headpos, traceendpos);
            }

    }
Image
Dragonshot
TeknoCricket
TeknoCricket
Posts: 5
Joined: Sat Oct 17, 2015 5:00 am

Re: [HELP]I need help with loadfx

Postby Dragonshot » Sat Jul 02, 2016 4:37 am

Boboo thank you but that didnt work at all :sadpanda: Can you please do it all for me please please please i will be very thankfull to you!!! :->
User avatar
S3VDIT0
TeknoCow
TeknoCow
Posts: 68
Joined: Tue Jun 16, 2015 7:50 am
Location: Russian Federation
Contact:

Re: [HELP]I need help with loadfx

Postby S3VDIT0 » Sat Jul 02, 2016 10:21 am

Code: Select all

        public Class1()
        {
            PlayerConnected += new Action<Entity>(player =>
                {
                    player.Call("notifyonplayercommand", "spawnfx", "+attack");
                    player.OnNotify("spawnfx", ent =>
                    {
                    if(player.CurrentWeapon == "your weapon")
                    {
                        Vector3 targ = Trace.PhysicsTraceFromEye(player);
                        int fxhandle = Call<int>("loadFx", "misc/flare_ambient_green");
                        Entity effect = Call<Entity>("spawnfx", fxhandle, targ);
                        Call("triggerfx", effect);
                        }
                    });
                });
        }


        public static class Trace //Thx to Cubrr <3
        {
            public static Vector3 PhysicsTrace(Vector3 start, Vector3 end)
            {
                return Function.Call<Vector3>("physicstracenormal", start, end);
            }

            public static Vector3 PlayerPhysicsTrace(Vector3 start, Vector3 end)
            {
                return Function.Call<Vector3>("playerphysicstrace", start, end);
            }

            public static Vector3 PhysicsTraceFromEye(Entity e)
            {
                Vector3 headpos = e.Call<Vector3>("gettagorigin", "j_eye");
                Vector3 forwangles = Function.Call<Vector3>("anglestoforward", e.Call<Vector3>("getplayerangles"));
                Vector3 traceendpos = headpos + forwangles * 50 * 1000;
                return PhysicsTrace(headpos, traceendpos);
            }
        }

Boboo took from your snippet
User avatar
Boboo
TeknoDev
Posts: 145
Joined: Thu Jul 23, 2015 3:41 pm

Re: [HELP]I need help with loadfx

Postby Boboo » Sat Jul 02, 2016 11:06 am

We already solved it :) :bravo:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using InfinityScript;

namespace InfinityScript_TeknoHelp
{
    public class SpawnFX : BaseScript
    {
        public SpawnFX() : base()
        {
            PlayerConnected += SpawnFX_PlayerConnected;
        }

        private void SpawnFX_PlayerConnected(Entity obj) //Eventhandler for the PlayerConnected Event
        {
            obj.Call("notifyonplayercommand", "fx_spawn", "+attack"); //Custom notifys
            obj.OnNotify("fx_spawn", ent =>
             {
                 if (obj.CurrentWeapon != "iw5_mp9_mp_reflexsmg") //Checkining the weapon
                     return;
                 Vector3 target = Tracer.PhysicsTraceFromEye(obj); //getting the target
                 int fxhandle = Call<int>("loadfx", "misc/flare_ambient"); //loading the fxhandle
                 Entity effect = Call<Entity>("spawnfx", fxhandle, target); //spawning the certain handle at the target
                 Call("triggerfx", effect); //triggering it
                 effect.AfterDelay(200, h => effect.Call("delete")); //Play around with the delay as u like it
             });
        }

        public override EventEat OnSay2(Entity player, string name, string message) //this part can be removed
        {
            if (message.ToLower() == "!fx")
            {
                player.GiveWeapon("iw5_mp9_mp_reflexsmg");
                player.SwitchToWeaponImmediate("iw5_mp9_mp_reflexsmg");
            }
            return EventEat.EatNone;
        }
    }
}


and I used the 1337 Physicstracer :) # thx cubrr :-P

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using InfinityScript;
using System.Runtime.InteropServices;

namespace InfinityScript_TeknoHelp
{
    public static class Tracer
    {
        private static readonly IntPtr LocationalTracePointer = new IntPtr(0x48A2C0);
        private static G_LocationalTrace _locationalTraceFunction = null;

        [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
        private delegate void G_LocationalTrace(ref Trace trace, ref Vector3 start, ref Vector3 end, int ignoreEntNum, int clipMask, int unk);

        public static Trace LocationalTrace(Vector3 start, Vector3 end, int ignoreEntNum = 2047, int clipMask = 0x806831)
        {
            Trace trace = new Trace();
            GetLocationalTraceFunction()(
                ref trace,
                ref start,
                ref end,
                ignoreEntNum,
                clipMask,
                0);
            return trace;
        }

        public static Vector3 LocationalTraceFromEye(Entity e, float maxDistance)
        {
            var headPosition = e.Call<Vector3>("gettagorigin", "tag_eye");
            var forwardAngles = Call<Vector3>("anglestoforward", e.Call<Vector3>("getplayerangles"));
            var traceEndPosition = headPosition + forwardAngles * maxDistance; // far to the forward towards crosshair
            Trace trace = LocationalTrace(headPosition, traceEndPosition);
            return trace.GetHitPosition(headPosition, traceEndPosition);
        }

        /// <summary>
        /// Physics trace, ignoring characters. Returns the endpos vector.
        /// </summary>
        /// <param name="start">The start point.</param>
        /// <param name="end">The end point.</param>
        /// <returns></returns>
        public static Vector3 PhysicsTrace(Vector3 start, Vector3 end)
        {
            return Call<Vector3>("physicstracenormal", start, end);
        }

        /// <summary>
        /// Physics trace from the vision of the player.
        /// </summary>
        /// <param name="e">The entity.</param>
        /// <param name="maxDistance">Specifies the maximum distance to the forwards to test for.</param>
        /// <returns></returns>
        public static Vector3 PhysicsTraceFromEye(Entity e, float maxDistance = 10000)
        {
            var headPosition = e.Call<Vector3>("gettagorigin", "tag_eye"); // props to kenny
            var forwardAngles = Call<Vector3>("anglestoforward", e.Call<Vector3>("getplayerangles"));
            var traceEndPosition = headPosition + forwardAngles * maxDistance; // far to the forward towards crosshair
            return PhysicsTrace(headPosition, traceEndPosition);
        }

        /// <summary>
        /// Physics trace using the player capsule size, ignoring characters. Returns the endpos vector.
        /// The player capsule's diameter on the xy-axis is approximately 15 units.
        /// </summary>
        /// <param name="start">The start point.</param>
        /// <param name="end">The end point.</param>
        /// <returns></returns>
        public static Vector3 PlayerPhysicsTrace(Vector3 start, Vector3 end)
        {
            return Call<Vector3>("playerphysicstrace", start, end);
        }

        private static G_LocationalTrace GetLocationalTraceFunction()
        {
            if (_locationalTraceFunction == null)
            {
                _locationalTraceFunction = (G_LocationalTrace)Marshal.GetDelegateForFunctionPointer(
                    LocationalTracePointer,
                    typeof(G_LocationalTrace));
            }
            return _locationalTraceFunction;
        }

        private static T Call<T>(string name, params Parameter[] args)
        {
            Function.SetEntRef(-1);
            return Function.Call<T>(name, args);
        }
    }

    [StructLayout(LayoutKind.Sequential, Size = 44)]
    public struct Trace
    {
        public float Fraction;
        public Vector3 Normal;
        public int SurfaceFlags;
        public int Contents;
        [MarshalAs(UnmanagedType.LPStr)]
        public string Material;
        public TraceHitType HitType;
        public short HitId;
        public short ModelIndex;
        public short PartName;
        public short PartGroup;
        public bool AllSolid;
        public bool StartSolid;
        public bool Walkable;
        public bool HitPartition;

        public Vector3 GetHitPosition(Vector3 start, Vector3 end)
        {
            return start + (end - start) * Fraction;
        }
    }

    public enum TraceHitType : int
    {
        None,
        Entity,
        DynamicEntityModel,
        DynamicEntityBrush,
        DynamicEntityUnknown
    }
}

Image
User avatar
Slvr99
TeknoPrincess
TeknoPrincess
Posts: 270
Joined: Wed Apr 18, 2012 7:53 pm
Location: Florida
Contact:

Re: [HELP]I need help with loadfx

Postby Slvr99 » Sat Jul 02, 2016 11:51 am

Why is everybody using custom notifies on +attack? Why not just run code on "weapon_fired"?
User avatar
Boboo
TeknoDev
Posts: 145
Joined: Thu Jul 23, 2015 3:41 pm

Re: [HELP]I need help with loadfx

Postby Boboo » Sat Jul 02, 2016 12:32 pm

Slvr99 wrote:Why is everybody using custom notifies on +attack? Why not just run code on "weapon_fired"?


Uhmm it would be too easy xD
Image

Return to “InfinityScript”

Who is online

Users browsing this forum: No registered users and 6 guests