Ejemplo n.º 1
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())
                },
                           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, int, dynamic, dynamic, bool>(
                            (identifier, type, pos, scale, color, maxDistance, bobUpAndDown, faceCamera, rotate, accessibility, onEnter, onExit) =>
            {
                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())
                },
                           Color.FromArgb(int.Parse(color.R.ToString()), int.Parse(color.G.ToString()), int.Parse(color.B.ToString())),
                           maxDistance,
                           (bool)bobUpAndDown,
                           (bool)faceCamera,
                           (bool)rotate,
                           (int)accessibility,
                           onEnter,
                           onExit
                           ));
            }));

            Exports.Add("DeleteMarkerEvent", new Action <string>(
                            (identifier) =>
            {
                if (identifier != null && 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 = 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,
                           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("CreateText3DOnEntity", new Func <string, string, int, dynamic, dynamic, dynamic, float, int, bool>(
                            (identifier, text, font, textColor, textScale, textPos, maxDistance, entity) =>
            {
                return(CreateText3D(
                           identifier,
                           text,
                           (CitizenFX.Core.UI.Font)font,
                           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,
                           entity
                           ));
            }));

            Exports.Add("DeleteText3D", new Action <string>(
                            (identifier) =>
            {
                if (identifier != null && 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("IsEntityInArea", new Func <string, int, bool>(
                            (identifier, handle) =>
            {
                if (identifier != null && areas.ContainsKey(identifier))
                {
                    Entity entity = Entity.FromHandle(handle);
                    AreaBase area = areas[identifier];
                    return(area.CoordsInside(entity.Position));
                }
                return(false);
            }));

            Exports.Add("IsCoordsInArea", new Func <string, float, float, float, bool>(
                            (identifier, x, y, z) =>
            {
                if (identifier != null && areas.ContainsKey(identifier))
                {
                    AreaBase area = areas[identifier];
                    return(area.CoordsInside(new Vector3 {
                        X = x, Y = y, Z = z
                    }));
                }
                return(false);
            }));

            Exports.Add("GetFirstAreaEntityIsIn", new Func <int, string>(
                            (handle) =>
            {
                Entity entity = Entity.FromHandle(handle);

                foreach (KeyValuePair <string, AreaBase> pair in areas)
                {
                    if (pair.Value.CoordsInside(entity.Position))
                    {
                        return(pair.Key);
                    }
                }

                return(null);
            }));

            Exports.Add("GetFirstAreaCoordsIsIn", new Func <float, float, float, string>(
                            (x, y, z) =>
            {
                Vector3 coords = new Vector3 {
                    X = x, Y = y, Z = z
                };

                foreach (KeyValuePair <string, AreaBase> pair in areas)
                {
                    if (pair.Value.CoordsInside(coords))
                    {
                        return(pair.Key);
                    }
                }

                return(null);
            }));

            Exports.Add("GetAreasEntityIsIn", new Func <int, object[]>(
                            (handle) =>
            {
                Entity entity        = Entity.FromHandle(handle);
                List <string> result = new List <string>();

                foreach (KeyValuePair <string, AreaBase> pair in areas)
                {
                    if (pair.Value.CoordsInside(entity.Position))
                    {
                        result.Add(pair.Key);
                    }
                }

                return(result.ToArray());
            }));

            Exports.Add("GetAreasCoordsIsIn", new Func <float, float, float, object[]>(
                            (x, y, z) =>
            {
                Vector3 coords = new Vector3 {
                    X = x, Y = y, Z = z
                };
                List <string> result = new List <string>();

                foreach (KeyValuePair <string, AreaBase> pair in areas)
                {
                    if (pair.Value.CoordsInside(coords))
                    {
                        result.Add(pair.Key);
                    }
                }

                return(result.ToArray());
            }));

            Exports.Add("DeleteArea", new Action <string>(
                            (identifier) =>
            {
                if (identifier != null && 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);
        }
Ejemplo n.º 2
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);
        }