MrGTAmodsgerman Posted June 12, 2016 Share Posted June 12, 2016 Hey, I am trying to run a function that have different ways when i holding the vehicleexit key or just press the vehicleexit key. For me it makes no difference when i even change IsControlPressed to IsControlJustPressed . I got this way from: http://gtaforums.com/topic/848554-c-how-to-add-controller-support-to-your-mod/ But it doesnt help. So what i have to do then? Do i need to add some special stuff? I want to run it like the IVVehicleExit mod, but i dont know how he do it. Can someone explain me that? Thanks Link to comment Share on other sites More sharing options...
JohnMcDoogle Posted June 12, 2016 Share Posted June 12, 2016 (edited) 'is_control_just_pressed' returns true if the given control was pressed, and was now just released. So basically if you're looping this as a check, it will return true once you let go of the control. 'is_control_pressed' returns true if the given control is being held down during the time of is_control_pressed being called. Not sure if this helps but I wanted just to make sure you understand what they both do. np Edit: I looked at the thread you linked and I think you understand what the two natives do. I'm not sure what your problem is as I'm not familiar with C#. Edited June 12, 2016 by JohnMcDoogle MrGTAmodsgerman 1 Link to comment Share on other sites More sharing options...
AHK1221 Posted June 12, 2016 Share Posted June 12, 2016 Hey, I am trying to run a function that have different ways when i holding the vehicleexit key or just press the vehicleexit key. For me it makes no difference when i even change IsControlPressed to IsControlJustPressed . I got this way from: http://gtaforums.com/topic/848554-c-how-to-add-controller-support-to-your-mod/ But it doesnt help. So what i have to do then? Do i need to add some special stuff? I want to run it like the IVVehicleExit mod, but i dont know how he do it. Can someone explain me that? Thanks Is_Control_Just_pressed returns true the moment it was pressed and turns to false the next frame. Is_Control_pressed returns true when it is pressed, and doesn't turn false the next frame The problem is Is_Control_Pressed returns true the first frame too, and therefore you are not seeing any difference. You can use a timer to skip the first few frames and you can also use this to determine how much time it has to be held. MrGTAmodsgerman 1 Link to comment Share on other sites More sharing options...
MrGTAmodsgerman Posted June 12, 2016 Author Share Posted June 12, 2016 Hey, I am trying to run a function that have different ways when i holding the vehicleexit key or just press the vehicleexit key. For me it makes no difference when i even change IsControlPressed to IsControlJustPressed . I got this way from: http://gtaforums.com/topic/848554-c-how-to-add-controller-support-to-your-mod/ But it doesnt help. So what i have to do then? Do i need to add some special stuff? I want to run it like the IVVehicleExit mod, but i dont know how he do it. Can someone explain me that? Thanks Is_Control_Just_pressed returns true the moment it was pressed and turns to false the next frame. Is_Control_pressed returns true when it is pressed, and doesn't turn false the next frame The problem is Is_Control_Pressed returns true the first frame too, and therefore you are not seeing any difference. You can use a timer to skip the first few frames and you can also use this to determine how much time it has to be held. I dont get it, its confusing! I try it with a timer, but it only works when i holding the key instantly and the player directly leave the car. But what i want is that when i holding the key inside my current vehicle that something happends. But when i just take a short press on the key, something different is going on. Can you give me a example that shows how it works perfectly? Link to comment Share on other sites More sharing options...
AHK1221 Posted June 12, 2016 Share Posted June 12, 2016 (edited) public int timer = 0;public yourClassName(){ Interval = 1000; Tick += onTick;}public void onTick(object sender, EventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if(timer >= 3000) { \\Do whatever you want }} Now, theoretically this should work. Try it out. Right now, hold the button for three seconds and it will do whatever you want to do in the if statement. This is a bad way of doing this, since your Tick is only run once per second, you can look into the Timer class to create your own timers for this kind of thing. Also, this is only a one time thing. Since there is no method to return it back to 0, you wont be able to use this another time. Ofc it will work, but it will work the moment you press it, not after three seconds. You can add a reset timer to reset it back to 0 once X amount of time has passed. Edited June 12, 2016 by AHK1221 MrGTAmodsgerman 1 Link to comment Share on other sites More sharing options...
MrGTAmodsgerman Posted June 12, 2016 Author Share Posted June 12, 2016 public int timer = 0;public yourClassName(){ Interval = 1000; Tick += onTick;}public void onTick(object sender, EventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if(timer >= 3000) { \\Do whatever you want }} Now, theoretically this should work. Try it out. Right now, hold the button for three seconds and it will do whatever you want to do in the if statement. This is a bad way of doing this, since your Tick is only run once per second, you can look into the Timer class to create your own timers for this kind of thing. Also, this is only a one time thing. Since there is no method to return it back to 0, you wont be able to use this another time. Ofc it will work, but it will work the moment you press it, not after three seconds. You can add a reset timer to reset it back to 0 once X amount of time has passed. Um, but what about the key that directly runs the function? Doesnt it need a if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; if(timer <= 3000) } ? Because the same happend in a different way and it have to stop the other way you know?! And what do you mean with you can look into the Timer class to create your own timers you can look into the Timer class to create your own timers Which Timer class? What are you talking about? NativeDB? Anyways thank you. But how to reset the timer? I cant find anything like that, reset isnt declared! Or do you mean to declare "reset" as "0"? Link to comment Share on other sites More sharing options...
AHK1221 Posted June 12, 2016 Share Posted June 12, 2016 (edited) public int timer = 0;public yourClassName(){ Interval = 1000; Tick += onTick;}public void onTick(object sender, EventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if(timer >= 3000) { \\Do whatever you want }} Now, theoretically this should work. Try it out. Right now, hold the button for three seconds and it will do whatever you want to do in the if statement. This is a bad way of doing this, since your Tick is only run once per second, you can look into the Timer class to create your own timers for this kind of thing. Also, this is only a one time thing. Since there is no method to return it back to 0, you wont be able to use this another time. Ofc it will work, but it will work the moment you press it, not after three seconds. You can add a reset timer to reset it back to 0 once X amount of time has passed. Um, but what about the key that directly runs the function? Doesnt it need a if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; if(timer <= 3000) } ? Because the same happend in a different way and it have to stop the other way you know?! And what do you mean with you can look into the Timer class to create your own timers you can look into the Timer class to create your own timers Which Timer class? What are you talking about? NativeDB? Anyways thank you. But how to reset the timer? I cant find anything like that, reset isnt declared! Or do you mean to declare "reset" as "0"? It doesn't matter, if the if statement is in it or out since it will activate when timer reaches a certain point and it only reaches that point in the Key if statement. Also it is if(timer >= 3000) not if(timer <= 3000) Timer class: https://msdn.microsoft.com/en-us/library/system.windows.forms.timer(v=vs.110).aspx for resetting: public int timer = 0;public int resetTime = 3000;public yourClassName(){ Interval = 1000; Tick += onTick;}public void onTick(object sender, EventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if(timer >= 3000) { \\Do whatever you want resetTime -= this.Interval; } if(resetTime <= 0) { timer = 0; resetTime = 3000; }} this code resets the timer 3 seconds after it has been held. As I said before, this isn't the most proper way, so use the above link to create another Tick event used specifically for this purpose. There are some bugs, like for example you only held it half way so timer fills up until 2000. It doesn't reset at that. But I hope you can fix these. Edited June 12, 2016 by AHK1221 MrGTAmodsgerman 1 Link to comment Share on other sites More sharing options...
MrGTAmodsgerman Posted June 26, 2016 Author Share Posted June 26, 2016 public int timer = 0;public yourClassName(){ Interval = 1000; Tick += onTick;}public void onTick(object sender, EventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if(timer >= 3000) { \\Do whatever you want }} Now, theoretically this should work. Try it out. Right now, hold the button for three seconds and it will do whatever you want to do in the if statement. This is a bad way of doing this, since your Tick is only run once per second, you can look into the Timer class to create your own timers for this kind of thing. Also, this is only a one time thing. Since there is no method to return it back to 0, you wont be able to use this another time. Ofc it will work, but it will work the moment you press it, not after three seconds. You can add a reset timer to reset it back to 0 once X amount of time has passed. Um, but what about the key that directly runs the function? Doesnt it need a if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; if(timer <= 3000) } ? Because the same happend in a different way and it have to stop the other way you know?! And what do you mean with you can look into the Timer class to create your own timers you can look into the Timer class to create your own timers Which Timer class? What are you talking about? NativeDB? Anyways thank you. But how to reset the timer? I cant find anything like that, reset isnt declared! Or do you mean to declare "reset" as "0"? It doesn't matter, if the if statement is in it or out since it will activate when timer reaches a certain point and it only reaches that point in the Key if statement. Also it is if(timer >= 3000) not if(timer <= 3000) Timer class: https://msdn.microsoft.com/en-us/library/system.windows.forms.timer(v=vs.110).aspx for resetting: public int timer = 0;public int resetTime = 3000;public yourClassName(){ Interval = 1000; Tick += onTick;}public void onTick(object sender, EventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if(timer >= 3000) { \\Do whatever you want resetTime -= this.Interval; } if(resetTime <= 0) { timer = 0; resetTime = 3000; }} this code resets the timer 3 seconds after it has been held. As I said before, this isn't the most proper way, so use the above link to create another Tick event used specifically for this purpose. There are some bugs, like for example you only held it half way so timer fills up until 2000. It doesn't reset at that. But I hope you can fix these. Thanks, but it doesnt really work, its working like holding 3 seconds, and the short press function run, and next time the long pressing function run!?? What about this example? https://libertylocked.wordpress.com/2015/06/19/readability-is-priority-for-example-scripts/ Its completly different but it doesnt work for me because && isnt declared. I dont know what it means, and your link doesnt help me because i dont see where it was made and what i need. Sorry, i am not the best scripter Link to comment Share on other sites More sharing options...
AHK1221 Posted June 26, 2016 Share Posted June 26, 2016 Well... you have to wait three seconds before you use it again. Also remember to hold it for three seconds. I have no idea about the link you posted to me. Um, in the link I provided, the namespace and assembly are provided. The link was meant to tell you how to have custom Tick events btw. You can edit my code so it is bug free, and you can reduce the time. But I dont really have the time to do it myself, I hope you figure it out. MrGTAmodsgerman 1 Link to comment Share on other sites More sharing options...
MrGTAmodsgerman Posted June 27, 2016 Author Share Posted June 27, 2016 (edited) Well... you have to wait three seconds before you use it again. Also remember to hold it for three seconds. I have no idea about the link you posted to me. Um, in the link I provided, the namespace and assembly are provided. The link was meant to tell you how to have custom Tick events btw. You can edit my code so it is bug free, and you can reduce the time. But I dont really have the time to do it myself, I hope you figure it out. What i mean was, it doesnt give me a short press option, the function i want to run at short press is running after i hold the 3 seconds. But the function that i was trying to run on holding the key also runs after 3 seconds. Its changeing everytime! So the code of you link was made from you? Because i used you code from this here above (not the link) and yea, its still doesnt really work. I really want to get this code you post here start working, because i can understand it then how it works. Currently i really dont get it how it works, or much better to say, i dont know whats wrong with your code and how its work. is something else here that can give me more options? Someone that understand that exit script example of my link that i post here? Thanks Edited June 27, 2016 by MrGTAmodsgerman Link to comment Share on other sites More sharing options...
ins1de Posted June 27, 2016 Share Posted June 27, 2016 (edited) public int timer = 0;public yourClassName(){ Interval = 1000; Tick += onTick;}public void onTick(object sender, EventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if(timer >= 3000) { \\Do whatever you want }} Now, theoretically this should work. Try it out. Right now, hold the button for three seconds and it will do whatever you want to do in the if statement. This is a bad way of doing this, since your Tick is only run once per second, you can look into the Timer class to create your own timers for this kind of thing. Also, this is only a one time thing. Since there is no method to return it back to 0, you wont be able to use this another time. Ofc it will work, but it will work the moment you press it, not after three seconds. You can add a reset timer to reset it back to 0 once X amount of time has passed. Um, but what about the key that directly runs the function? Doesnt it need a if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; if(timer <= 3000) } ? Because the same happend in a different way and it have to stop the other way you know?! And what do you mean with you can look into the Timer class to create your own timers you can look into the Timer class to create your own timers Which Timer class? What are you talking about? NativeDB? Anyways thank you. But how to reset the timer? I cant find anything like that, reset isnt declared! Or do you mean to declare "reset" as "0"? It doesn't matter, if the if statement is in it or out since it will activate when timer reaches a certain point and it only reaches that point in the Key if statement. Also it is if(timer >= 3000) not if(timer <= 3000) Timer class: https://msdn.microsoft.com/en-us/library/system.windows.forms.timer(v=vs.110).aspx for resetting: public int timer = 0;public int resetTime = 3000;public yourClassName(){ Interval = 1000; Tick += onTick;}public void onTick(object sender, EventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if(timer >= 3000) { \\Do whatever you want resetTime -= this.Interval; } if(resetTime <= 0) { timer = 0; resetTime = 3000; }} this code resets the timer 3 seconds after it has been held. As I said before, this isn't the most proper way, so use the above link to create another Tick event used specifically for this purpose. There are some bugs, like for example you only held it half way so timer fills up until 2000. It doesn't reset at that. But I hope you can fix these. Thanks, but it doesnt really work, its working like holding 3 seconds, and the short press function run, and next time the long pressing function run!?? What about this example? https://libertylocked.wordpress.com/2015/06/19/readability-is-priority-for-example-scripts/ Its completly different but it doesnt work for me because && isnt declared. I dont know what it means, and your link doesnt help me because i dont see where it was made and what i need. Sorry, i am not the best scripter It's actually a syntax fail. It's probably his code highlighter that failed to write the & symbol correctly. The original author wanted to write this symbol && which is an operator that means "AND" in C#. So here's the line you must correct if you are using his script : if (player.IsAlive && player.IsInVehicle()) // Replaced && with && Edited June 27, 2016 by ins1de MrGTAmodsgerman 1 Link to comment Share on other sites More sharing options...
AHK1221 Posted June 28, 2016 Share Posted June 28, 2016 Well... you have to wait three seconds before you use it again. Also remember to hold it for three seconds. I have no idea about the link you posted to me. Um, in the link I provided, the namespace and assembly are provided. The link was meant to tell you how to have custom Tick events btw. You can edit my code so it is bug free, and you can reduce the time. But I dont really have the time to do it myself, I hope you figure it out. What i mean was, it doesnt give me a short press option, the function i want to run at short press is running after i hold the 3 seconds. But the function that i was trying to run on holding the key also runs after 3 seconds. Its changeing everytime! So the code of you link was made from you? Because i used you code from this here above (not the link) and yea, its still doesnt really work. I really want to get this code you post here start working, because i can understand it then how it works. Currently i really dont get it how it works, or much better to say, i dont know whats wrong with your code and how its work. is something else here that can give me more options? Someone that understand that exit script example of my link that i post here? Thanks Revised code: public int timer = 0;public int resetTime = 3000;public yourClassName(){ Interval = 1000; Tick += onTick; KeyDown += onKeyDown;}public void onTick(object sender, EventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if(timer >= 3000) { \\Do whatever you want \\Long press. resetTime -= this.Interval; } if(resetTime <= 0) { timer = 0; resetTime = 3000; }}public void onKeyDown(object sender, KeyEventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { //Short Press }} MrGTAmodsgerman 1 Link to comment Share on other sites More sharing options...
MrGTAmodsgerman Posted June 28, 2016 Author Share Posted June 28, 2016 (edited) Well... you have to wait three seconds before you use it again. Also remember to hold it for three seconds. I have no idea about the link you posted to me. Um, in the link I provided, the namespace and assembly are provided. The link was meant to tell you how to have custom Tick events btw. You can edit my code so it is bug free, and you can reduce the time. But I dont really have the time to do it myself, I hope you figure it out. What i mean was, it doesnt give me a short press option, the function i want to run at short press is running after i hold the 3 seconds. But the function that i was trying to run on holding the key also runs after 3 seconds. Its changeing everytime! So the code of you link was made from you? Because i used you code from this here above (not the link) and yea, its still doesnt really work. I really want to get this code you post here start working, because i can understand it then how it works. Currently i really dont get it how it works, or much better to say, i dont know whats wrong with your code and how its work. is something else here that can give me more options? Someone that understand that exit script example of my link that i post here? Thanks Revised code: public int timer = 0;public int resetTime = 3000;public yourClassName(){ Interval = 1000; Tick += onTick; KeyDown += onKeyDown;}public void onTick(object sender, EventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if(timer >= 3000) { \\Do whatever you want \\Long press. resetTime -= this.Interval; } if(resetTime <= 0) { timer = 0; resetTime = 3000; }}public void onKeyDown(object sender, KeyEventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { //Short Press }} Thanks, it make much more sense now but for some stupid reason, onKeyDown doesnt work anymore! I already used it at my script but its acting like it isnt there now! I dont know what it is My code: public class MyScriptName : Script{ public int timer = 0; public int resetTime = 3000; public MyScriptName() { Interval = 1000; Tick += OnTick; KeyDown += OnKeyDown; //KeyUp += OnKeyUp; Interval = 10; } void OnTick(object sender, EventArgs e) { if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if (timer >= 3000) { Game.Player.Character.SetDefaultClothes(); resetTime -= this.Interval; } if (resetTime <= 0) { timer = 0; resetTime = 3000; } } void OnKeyDown(object sender, KeyEventArgs e) { if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { Game.Player.Character.RandomizeOutfit(); } }} And a another problem is that the long press key function doesnt run always when i hold the 3 seconds! Only sometimes! public int timer = 0;public yourClassName(){ Interval = 1000; Tick += onTick;}public void onTick(object sender, EventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if(timer >= 3000) { \\Do whatever you want }} Now, theoretically this should work. Try it out. Right now, hold the button for three seconds and it will do whatever you want to do in the if statement. This is a bad way of doing this, since your Tick is only run once per second, you can look into the Timer class to create your own timers for this kind of thing. Also, this is only a one time thing. Since there is no method to return it back to 0, you wont be able to use this another time. Ofc it will work, but it will work the moment you press it, not after three seconds. You can add a reset timer to reset it back to 0 once X amount of time has passed. Um, but what about the key that directly runs the function? Doesnt it need a if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; if(timer <= 3000) } ? Because the same happend in a different way and it have to stop the other way you know?! And what do you mean with you can look into the Timer class to create your own timers you can look into the Timer class to create your own timers Which Timer class? What are you talking about? NativeDB? Anyways thank you. But how to reset the timer? I cant find anything like that, reset isnt declared! Or do you mean to declare "reset" as "0"? It doesn't matter, if the if statement is in it or out since it will activate when timer reaches a certain point and it only reaches that point in the Key if statement. Also it is if(timer >= 3000) not if(timer <= 3000) Timer class: https://msdn.microsoft.com/en-us/library/system.windows.forms.timer(v=vs.110).aspx for resetting: public int timer = 0;public int resetTime = 3000;public yourClassName(){ Interval = 1000; Tick += onTick;}public void onTick(object sender, EventArgs e){ if (Game.IsControlPressed(2, GTA.Control.ScriptPadLeft)) { timer += this.Interval; } if(timer >= 3000) { \\Do whatever you want resetTime -= this.Interval; } if(resetTime <= 0) { timer = 0; resetTime = 3000; }} this code resets the timer 3 seconds after it has been held. As I said before, this isn't the most proper way, so use the above link to create another Tick event used specifically for this purpose. There are some bugs, like for example you only held it half way so timer fills up until 2000. It doesn't reset at that. But I hope you can fix these. Thanks, but it doesnt really work, its working like holding 3 seconds, and the short press function run, and next time the long pressing function run!?? What about this example? https://libertylocked.wordpress.com/2015/06/19/readability-is-priority-for-example-scripts/ Its completly different but it doesnt work for me because && isnt declared. I dont know what it means, and your link doesnt help me because i dont see where it was made and what i need. Sorry, i am not the best scripter It's actually a syntax fail. It's probably his code highlighter that failed to write the & symbol correctly. The original author wanted to write this symbol && which is an operator that means "AND" in C#. So here's the line you must correct if you are using his script : if (player.IsAlive && player.IsInVehicle()) // Replaced && with && Thank you but where is amp declared and what does gt means? if (holdTime >= _HOLD_THRESHOLD) Edited June 28, 2016 by MrGTAmodsgerman Link to comment Share on other sites More sharing options...
ins1de Posted June 28, 2016 Share Posted June 28, 2016 Thank you but where is amp declared and what does gt means? if (holdTime >= _HOLD_THRESHOLD) & is not a variable, it has nothing to do with scripting. It is a problem with his website that shows it instead of an HTML symbol. gt; is the same problem again. Here, take a look at the HTML entities if you don't see what I mean : https://dev.w3.org/html5/html-author/charref Anyways, this is the code you need : http://pastebin.com/eMHDFHXy and he also made a second version, available here http://pastebin.com/a2HZeB8p MrGTAmodsgerman 1 Link to comment Share on other sites More sharing options...
AHK1221 Posted June 28, 2016 Share Posted June 28, 2016 Of course it doesnt work, why did you set the Interval to ten in the instructor? MrGTAmodsgerman 1 Link to comment Share on other sites More sharing options...
MrGTAmodsgerman Posted June 29, 2016 Author Share Posted June 29, 2016 (edited) Thank you but where is amp declared and what does gt means? if (holdTime >= _HOLD_THRESHOLD) & is not a variable, it has nothing to do with scripting. It is a problem with his website that shows it instead of an HTML symbol. gt; is the same problem again. Here, take a look at the HTML entities if you don't see what I mean : https://dev.w3.org/html5/html-author/charref Anyways, this is the code you need : http://pastebin.com/eMHDFHXy and he also made a second version, available here http://pastebin.com/a2HZeB8p Thank you! Now i thing i will get it to work with this example, but which script way is better? @AHK1221 one? Or just like the script example? Of course it doesnt work, why did you set the Interval to ten in the instructor? WOooPs! My fault! I just forgot it to remove it from my old script Edited June 29, 2016 by MrGTAmodsgerman 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