Jprey Posted March 8, 2020 Posted March 8, 2020 (edited) So im making a small script that should check if player is in a position and if is then add random amount of money, and i did it like this. It is working and all but whole server blocks cuz "while" is looping like crazy. Any ideas how to make it optimized ? Im also looking for a way to STOP task if player is dead or out of vector3 (mabye avoid while) while (player.Position.DistanceTo2D(new Vector3(2835.48, 1527.3, 24.56)) < 15) { Task.Run(() => { Task.Delay(1000).Wait(); Random rand = new Random(); int Money = rand.Next(17, 31); CashAPI.API.AddCash(c, Money); }); } Tried this but it check if player is in position just at the beggining, and not checking if the player left position Quote if (player.Position.DistanceTo2D(new Vector3(2835.48, 1527.3, 24.56)) > 15) { player.SendNotification("Niste u zoni"); return; } if (player.Position.DistanceTo2D(new Vector3(2835.48, 1527.3, 24.56)) < 15) { Task.Run(() => { Task.Delay(5000).Wait(); Random rand = new Random(); int Money = rand.Next(17, 31); CashAPI.API.AddCash(c, Money); }); } Edited March 8, 2020 by Jprey edit
Corlesi Posted March 11, 2020 Posted March 11, 2020 Maybe use a ColShape? So you can use the callbacks whenever a player is entering/leaving it
Jprey Posted March 12, 2020 Author Posted March 12, 2020 18 hours ago, Corlesi said: Maybe use a ColShape? So you can use the callbacks whenever a player is entering/leaving it Im abit unfamiliar with colshapes, i did try but failed to do so.
Jprey Posted March 12, 2020 Author Posted March 12, 2020 (edited) using GTANetworkAPI; using System; using System.Collections.Generic; using System.Timers; namespace Roleplay.Zone { public class Zone : Script { public void MakeZone(Client c) { ColShape ZonaM = NAPI.ColShape.CreateCylinderColShape(new Vector3(2835.48, 1527.3, 24.56), 3, 4); Marker ZonaOne = NAPI.Marker.CreateMarker(21, new Vector3(2835.48, 1527.3, 24.56), new Vector3(), new Vector3(0.48, 0.3, 0.56), 5f, new Color(16, 78, 139, 100)); ZonaM.SetData("ZonaOne", ZonaOne); } [ServerEvent(Event.PlayerEnterColshape)] public void Event_EnterColshape(ColShape colshape, Client c) { Marker ZonaOne = colshape.GetData("ZonaOne"); if(ZonaOne != null) { c.SendNotification("You entered zone"); return; } } } } I mean im doing something wrong here, why its not working ? Edited March 12, 2020 by Jprey Editing
Corlesi Posted March 12, 2020 Posted March 12, 2020 This should work fine, maybe you forgot to call MakeZone() ! I edited it a little so its called on resourcestart public class Zone : Script { [ServerEvent(Event.ResourceStart)] public void MakeZone() { ColShape ZonaM = NAPI.ColShape.CreateCylinderColShape(new Vector3(2835.48, 1527.3, 24.56), 3, 4); Marker ZonaOne = NAPI.Marker.CreateMarker(21, new Vector3(2835.48, 1527.3, 24.56), new Vector3(), new Vector3(0.48, 0.3, 0.56), 5f, new Color(16, 78, 139, 100)); ZonaM.SetData("ZonaOne", ZonaOne); } [ServerEvent(Event.PlayerEnterColshape)] public void Event_EnterColshape(ColShape colshape, Client c) { Marker ZonaOne = colshape.GetData("ZonaOne"); if (ZonaOne != null) { c.SendNotification("You entered zone"); return; } } [ServerEvent(Event.PlayerExitColshape)] public void Event_ExitColshape(ColShape colshape, Client c) { Marker ZonaOne = colshape.GetData("ZonaOne"); if (ZonaOne != null) { c.SendNotification("You left zone"); return; } } }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now