R1Z Posted January 23, 2019 Share Posted January 23, 2019 (edited) Hi guys, so im trying to get back into scripting, trying to figure out everything by my own wont work. I used to script but somehow im really rust. I have this script where i just want the player to be able to do the /armyduty command when he is in a colshape&Marker and not when he is outside. I found some usefull information on the wiki but i keep on getting "Nope" as an answer. const Armymarker = mp.markers.new(1, new mp.Vector3(-2126.56128, 3285.96265, 37.7325134), 3, { color: [255, 165, 0, 50], visible: true, }); let ArmyColShape = mp.colshapes.newSphere(-2126.56128, 3285.96265, 37.7325134, 5); mp.events.addCommand('armyduty', (player, shape) => { if(shape == ArmyColShape) { player.outputChatBox(`${player.name} duty Army`); } else { player.outputChatBox(`${player.name} Nope`); } }); Thats the script, but i cant figure out what im doing wrong that i cant execute the command in the colshape. Im grateful for every tips and tricks. Cheers, R1Z Edited January 23, 2019 by R1Z 1 Link to comment Share on other sites More sharing options...
MrPancakers Posted January 23, 2019 Share Posted January 23, 2019 (edited) If I'm guessing correctly, you're just typing /armyduty and that's it? That won't do anything as you haven't written anything for 'shape', it can't just grab 'shape' out of nowhere, you need to tell it what 'shape' is. Thinking off the top of my head, what if you used the playerEnterColShape and playerExitColShape events, and assign the player a variable called something like currentCol with the value of the shape that you get from the event. Then when they exit, just assign that variable the value of 'null'? I've never actually played with colshapes where it checks if you're inside one, I've always just executed functions as soon as they enter it so this is just me thinking up one way. Edited January 23, 2019 by MrPancakers 1 Link to comment Share on other sites More sharing options...
R1Z Posted January 24, 2019 Author Share Posted January 24, 2019 14 hours ago, MrPancakers said: If I'm guessing correctly, you're just typing /armyduty and that's it? That won't do anything as you haven't written anything for 'shape', it can't just grab 'shape' out of nowhere, you need to tell it what 'shape' is. Thinking off the top of my head, what if you used the playerEnterColShape and playerExitColShape events, and assign the player a variable called something like currentCol with the value of the shape that you get from the event. Then when they exit, just assign that variable the value of 'null'? I've never actually played with colshapes where it checks if you're inside one, I've always just executed functions as soon as they enter it so this is just me thinking up one way. Thanks for your reply. Thats the first helpful step though. Going to try that thankyou 2 Link to comment Share on other sites More sharing options...
Elliot Posted January 24, 2019 Share Posted January 24, 2019 let ArmyColShape = mp.colshapes.newSphere(-2126.56128, 3285.96265, 37.7325134, 5); mp.events.addCommand('armyduty', (player) => { if(ArmyColShape.isPointWithin(player.position)) { //The player is within the colshape } else { //Handle if the player isn't } }) How I understand it, it's something like this you're looking for 1 1 Link to comment Share on other sites More sharing options...
R1Z Posted January 24, 2019 Author Share Posted January 24, 2019 28 minutes ago, Elliot said: let ArmyColShape = mp.colshapes.newSphere(-2126.56128, 3285.96265, 37.7325134, 5); mp.events.addCommand('armyduty', (player) => { if(ArmyColShape.isPointWithin(player.position)) { //The player is within the colshape } else { //Handle if the player isn't } }) How I understand it, it's something like this you're looking for I think youre an angel haha! I dont know what i did wrong before but i troed the isPointWithin and did something wrong! Im so grateful! Thank you man! Link to comment Share on other sites More sharing options...
Geramy92 Posted January 31, 2019 Share Posted January 31, 2019 I know you have already you answer but Why are you creating a colshape for that function when you use a command. It is more simple to use directly const armyPosition = new mp.Vector3(-2126.56128, 3285.96265, 37.7325134); if (player.position.substract(armyPosition).length <= 5) I mean maybe I am wrong but this should be more efficient, isn't it? 2 1 Link to comment Share on other sites More sharing options...
Flow Posted February 1, 2019 Share Posted February 1, 2019 Set a inColshape var on the player on enter and remove it on leave. Then just check if inColshape is your prefered value. Should be (in theory) the most efficietn way because no position has to be calculated Link to comment Share on other sites More sharing options...
Geramy92 Posted February 1, 2019 Share Posted February 1, 2019 (edited) Sorry to say that: but you are completely wrong. First of all to explain differences: player.position ist only a PROPERTY a property is a value in storage. You DO NOT CALCULATE IT. So only calculation on my solution you have is vector calculation. Colshape solution: You create an entire ENTITY so an Object in world and compare it to the position and delete it. - so as it sounds it IS more calculations (don't want to go in details as I do not know hjow rage.mp / gta V implemented it) Before you do not believe me, I did some performance tests and have let run both solutions 1 mio times. Just to show difference: I think the times, explains why you should use in this case only Vector calculation based on properties. In Fact you want to have events and so on, yes then colshapes should be your solution, but I think more because of it has more confort in such things // edit: I improved a bit the performance and created the colshape upfront and destroy it after all loops - in case for example in the script you want to check multiple times same position. Same for Vector solution. -> In this solution you should consider that you have all the time an entity spawned which takes also storage and performance as it is used for all colshape events. But here the numbers says still the same: //edit2: ofcause you could also write a var on entering and existing a colshape - result will be still the same, but I can not write a performance test out of that, simply because you get only the end of the process as time in your script - but still see the first edit - the time will be like that because most of the time is creating colshape and checking position - which happens also before triggering the event //edit3: What I also do not understand: why are we talking about that, also regarding of complexity for just a position check, my solution is the simplest (I know that is now a subjective opinion - but I can not see that it should be easier to handle a whole colshape instead of simply check two positions against each other) Edited February 1, 2019 by Geramy92 2 Link to comment Share on other sites More sharing options...
Flow Posted February 9, 2019 Share Posted February 9, 2019 Never tought that. Interesting. Thanks 1 Link to comment Share on other sites More sharing options...
Gragon Posted February 10, 2019 Share Posted February 10, 2019 Can you tell me where to put this code to make it work ? Link to comment Share on other sites More sharing options...
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