예제 #1
0
 private int CreatePickup(Vector3 pos, Model model, bool isDynamic, bool onGround, bool deleteOnAction, EventAction action)
 {
     try
     {
         CustomPickup pickup = new CustomPickup
         {
             Pos            = pos,
             Model          = model,
             Dynamic        = isDynamic,
             OnGround       = onGround,
             DeleteOnAction = deleteOnAction,
             EventAction    = action
         };
         pickup.Create();
         pickups.Add(pickup);
         return(pickup.NetHandle);
     }
     catch (Exception Ex)
     {
         Debug.WriteLine("Error: " + Ex);
         return(-1);
     }
 }
예제 #2
0
        public void GetMapDirective(dynamic addCb)
        {
            addCb("createMarkerEvent", new Func <dynamic, dynamic, Action <dynamic> >((state, arg) =>
            {
                return(new Action <dynamic>(arg2 =>
                {
                    bool created = CreateMarkerEvent(
                        arg,
                        (MarkerType)arg2.Type,
                        new Vector3 {
                        X = (float)arg2.Pos.X, Y = (float)arg2.Pos.Y, Z = (float)arg2.Pos.Z
                    },
                        new Vector3 {
                        X = (float)arg2.Scale.X, Y = (float)arg2.Scale.Y, Z = (float)arg2.Scale.Z
                    },
                        System.Drawing.Color.FromArgb(arg2.Color.R, arg2.Color.G, arg2.Color.B),
                        (float)arg2.MaxDistance,
                        IsPropertyExist(arg2, "BobUpAndDown") ? (bool)arg2.BobUpAndDown : false,
                        IsPropertyExist(arg2, "FaceCamera") ? (bool)arg2.FaceCamera : false,
                        IsPropertyExist(arg2, "Rotate") ? (bool)arg2.Rotate : false
                        );

                    if (created)
                    {
                        state.add("markerId", arg);
                    }
                }));
            }), new Action <dynamic>(state =>
            {
                string markerId = state.markerId;

                if (markerId != null && markerEvents.ContainsKey(markerId))
                {
                    markerEvents.Remove(markerId);
                }
            }));

            addCb("addTextToMarkerEvent", new Func <dynamic, dynamic, Action <dynamic> >((state, arg) =>
            {
                return(new Action <dynamic>(arg2 =>
                {
                    Text3D text = new Text3D {
                        TextString = arg2.Text,
                        Font = (CitizenFX.Core.UI.Font)arg2.Font,
                        Color = System.Drawing.Color.FromArgb(arg2.Color.R, arg2.Color.G, arg2.Color.B),
                        Scale = new Vector2 {
                            X = (float)arg2.Scale.X, Y = (float)arg2.Scale.Y
                        },
                        Pos = new Vector3 {
                            X = (float)arg2.Pos.X, Y = (float)arg2.Pos.Y, Z = (float)arg2.Pos.Z
                        },
                        MaxDistance = (float)arg2.MaxDistance
                    };


                    bool done = AddTextToMarkerEvent(
                        arg,
                        text
                        );

                    if (done)
                    {
                        state.add("markerId", arg);
                    }
                }));
            }), new Action <dynamic>(state =>
            {
                string markerId = state.markerId;

                if (markerId != null && markerEvents.ContainsKey(markerId))
                {
                    markerEvents[markerId].Text3D = null;
                }
            }));

            addCb("addActionToMarkerEvent", new Func <dynamic, dynamic, Action <dynamic> >((state, arg) =>
            {
                return(new Action <dynamic>(arg2 =>
                {
                    EventAction action = new EventAction {
                        Type = (EventActionType)arg2.Action,
                        Callback = arg2.CallBack
                    };

                    if (IsPropertyExist(arg2, "HelpText"))
                    {
                        action.HelpText = arg2.HelpText;
                    }

                    if (IsPropertyExist(arg2, "Control"))
                    {
                        action.Control = (Control)arg2.Control;
                    }

                    if (IsPropertyExist(arg2, "Params"))
                    {
                        action.Params = arg2.Params;
                    }

                    bool done = AddActionToMarkerEvent(
                        arg,
                        action
                        );

                    if (done)
                    {
                        state.add("markerId", arg);
                    }
                }));
            }), new Action <dynamic>(state =>
            {
                string markerId = state.markerId;

                if (markerId != null && markerEvents.ContainsKey(markerId))
                {
                    markerEvents[markerId].EventAction = null;
                }
            }));

            addCb("create3DText", new Func <dynamic, dynamic, Action <dynamic> >((state, arg) =>
            {
                return(new Action <dynamic>(arg2 =>
                {
                    bool done = CreateText3D(
                        arg,
                        arg2.Text,
                        (CitizenFX.Core.UI.Font)arg2.Font,
                        System.Drawing.Color.FromArgb(arg2.Color.R, arg2.Color.G, arg2.Color.B),
                        new Vector2 {
                        X = (float)arg2.Scale.X, Y = (float)arg2.Scale.Y
                    },
                        new Vector3 {
                        X = (float)arg2.Pos.X, Y = (float)arg2.Pos.Y, Z = (float)arg2.Pos.Z
                    },
                        (float)arg2.MaxDistance
                        );

                    if (done)
                    {
                        state.add("textId", arg);
                    }
                }));
            }), new Action <dynamic>(state =>
            {
                string textId = state.textId;

                if (textId != null && texts.ContainsKey(textId))
                {
                    texts.Remove(textId);
                }
            }));

            addCb("createArea", new Func <dynamic, dynamic, Action <dynamic> >((state, arg) =>
            {
                return(new Action <dynamic>(arg2 =>
                {
                    bool done = CreateArea(
                        arg,
                        (AreaType)arg2.Type,
                        arg2.Data,
                        IsPropertyExist(arg2, "OnEnter") ? arg2.OnEnter : null,
                        IsPropertyExist(arg2, "OnExit") ? arg2.OnExit : null,
                        IsPropertyExist(arg2, "Params") ? arg2.Params : null,
                        IsPropertyExist(arg2, "Debug") ? (bool)arg2.Debug : false
                        );

                    if (done)
                    {
                        state.add("areaId", arg);
                    }
                }));
            }), new Action <dynamic>(state =>
            {
                string areaId = state.areaId;

                if (areaId != null && areas.ContainsKey(areaId))
                {
                    areas.Remove(areaId);
                }
            }));
        }
예제 #3
0
        public FToolsClient()
        {
            Tick += OnTick;
            Tick += OnTick500;
            Tick += OnTick10000;

            markerEvents = new Dictionary <string, MarkerEvent>();
            texts        = new Dictionary <string, Text3D>();
            areas        = new Dictionary <string, AreaBase>();
            pickups      = new List <CustomPickup>();


            Exports.Add("CreateMarkerEvent", new Func <string, int, dynamic, dynamic, dynamic, float, bool>(
                            (identifier, type, pos, scale, color, maxDistance) =>
            {
                return(CreateMarkerEvent(
                           identifier,
                           (MarkerType)type,
                           new Vector3 {
                    X = float.Parse(pos.X.ToString()), Y = float.Parse(pos.Y.ToString()), Z = float.Parse(pos.Z.ToString())
                },
                           new Vector3 {
                    X = float.Parse(scale.X.ToString()), Y = float.Parse(scale.Y.ToString()), Z = float.Parse(scale.Z.ToString())
                },
                           System.Drawing.Color.FromArgb(int.Parse(color.R.ToString()), int.Parse(color.G.ToString()), int.Parse(color.B.ToString())),
                           maxDistance
                           ));
            }));

            Exports.Add("CreateMarkerEventExtended", new Func <string, int, dynamic, dynamic, dynamic, float, bool, bool, bool, bool>(
                            (identifier, type, pos, scale, color, maxDistance, bobUpAndDown, faceCamera, rotate) =>
            {
                return(CreateMarkerEvent(
                           identifier,
                           (MarkerType)type,
                           new Vector3 {
                    X = float.Parse(pos.X.ToString()), Y = float.Parse(pos.Y.ToString()), Z = float.Parse(pos.Z.ToString())
                },
                           new Vector3 {
                    X = float.Parse(scale.X.ToString()), Y = float.Parse(scale.Y.ToString()), Z = float.Parse(scale.Z.ToString())
                },
                           System.Drawing.Color.FromArgb(int.Parse(color.R.ToString()), int.Parse(color.G.ToString()), int.Parse(color.B.ToString())),
                           maxDistance,
                           (bool)bobUpAndDown,
                           (bool)faceCamera,
                           (bool)rotate
                           ));
            }));

            Exports.Add("DeleteMarkerEvent", new Action <string>(
                            (identifier) =>
            {
                if (markerEvents.ContainsKey(identifier))
                {
                    markerEvents.Remove(identifier);
                }
            }));

            Exports.Add("AddTextToMarkerEvent", new Func <string, string, int, dynamic, dynamic, dynamic, float, bool>(
                            (markerEventId, text, font, textColor, textScale, textPos, maxDistance) =>
            {
                return(AddTextToMarkerEvent(
                           markerEventId,
                           new Text3D {
                    TextString = text,
                    Font = (CitizenFX.Core.UI.Font)font,
                    Color = System.Drawing.Color.FromArgb(int.Parse(textColor.R.ToString()), int.Parse(textColor.G.ToString()), int.Parse(textColor.B.ToString())),
                    Scale = new Vector2 {
                        X = float.Parse(textScale.X.ToString()), Y = float.Parse(textScale.Y.ToString())
                    },
                    Pos = new Vector3 {
                        X = float.Parse(textPos.X.ToString()), Y = float.Parse(textPos.Y.ToString()), Z = float.Parse(textPos.Z.ToString())
                    },
                    MaxDistance = maxDistance
                }
                           ));
            }));

            Exports.Add("AddActionToMarkerEvent", new Func <string, int, int?, string, dynamic, dynamic, bool>(
                            (markerEventId, eventActionType, control, helpText, callBack, parameters) =>
            {
                EventAction action = new EventAction
                {
                    Type     = (EventActionType)eventActionType,
                    Callback = callBack
                };

                if (!String.IsNullOrEmpty(helpText))
                {
                    action.HelpText = helpText;
                }

                if (control != null)
                {
                    action.Control = (Control)control;
                }

                if (parameters != null)
                {
                    action.Params = parameters;
                }

                return(AddActionToMarkerEvent(
                           markerEventId,
                           action
                           ));
            }));


            Exports.Add("CreateText3D", new Func <string, string, int, dynamic, dynamic, dynamic, float, bool>(
                            (identifier, text, font, textColor, textScale, textPos, maxDistance) =>
            {
                return(CreateText3D(
                           identifier,
                           text,
                           (CitizenFX.Core.UI.Font)font,
                           System.Drawing.Color.FromArgb(int.Parse(textColor.R.ToString()), int.Parse(textColor.G.ToString()), int.Parse(textColor.B.ToString())),
                           new Vector2 {
                    X = float.Parse(textScale.X.ToString()), Y = float.Parse(textScale.Y.ToString())
                },
                           new Vector3 {
                    X = float.Parse(textPos.X.ToString()), Y = float.Parse(textPos.Y.ToString()), Z = float.Parse(textPos.Z.ToString())
                },
                           maxDistance
                           ));
            }));

            Exports.Add("DeleteText3d", new Action <string>(
                            (identifier) =>
            {
                if (texts.ContainsKey(identifier))
                {
                    texts.Remove(identifier);
                }
            }));

            Exports.Add("CreateArea", new Func <string, int, dynamic, dynamic, dynamic, dynamic, bool, bool>(
                            (identifier, type, data, onEnter, onExit, parameters, debug) =>
            {
                return(CreateArea(
                           identifier,
                           (AreaType)type,
                           data,
                           onEnter,
                           onExit,
                           parameters,
                           debug
                           ));
            }));

            Exports.Add("DeleteArea", new Action <string>(
                            (identifier) =>
            {
                if (areas.ContainsKey(identifier))
                {
                    areas.Remove(identifier);
                }
            }));

            Exports.Add("CreatePickup", new Func <dynamic, string, bool, bool, bool, int, int?, string, string, dynamic, int>(
                            (position, model, isDynamic, onGround, deleteOnAction, eventActionType, control, helpText, callBack, parameters) =>
            {
                EventAction action = new EventAction
                {
                    Type     = (EventActionType)eventActionType,
                    Callback = callBack
                };

                if (!String.IsNullOrEmpty(helpText))
                {
                    action.HelpText = helpText;
                }

                if (control != null)
                {
                    action.Control = (Control)control;
                }

                if (parameters != null)
                {
                    action.Params = parameters;
                }

                return(CreatePickup(
                           new Vector3 {
                    X = float.Parse(position.X.ToString()), Y = float.Parse(position.Y.ToString()), Z = float.Parse(position.Z.ToString())
                },
                           new Model(model),
                           isDynamic,
                           onGround,
                           deleteOnAction,
                           action
                           ));
            }));

            Exports.Add("DeletePickup", new Action <int>(
                            (NetHandle) =>
            {
                CustomPickup pickup = pickups.SingleOrDefault(p => p.NetHandle == NetHandle);

                if (pickup != null)
                {
                    pickup.Delete();
                }
            }));

            Exports.Add("ShowNotification", new Action <string>(
                            (text) =>
            {
                ShowNotification(text);
            }));


            EventHandlers["getMapDirectives"]       += new Action <dynamic>(this.GetMapDirective);
            EventHandlers["FTools:PickupCreated"]   += new Action <dynamic>(this.CreateNetPickup);
            EventHandlers["FTools:PickupDeleted"]   += new Action <int>(this.DeleteNetPickup);
            EventHandlers["FTools:PickupTriggered"] += new Action <int>(this.PickupTriggered);
            EventHandlers["playerSpawned"]          += new Action <dynamic>(this.PlayerSpawned);
        }