Jul 11 2009, 10:31 PM Post #1 | |
Coding like a Rockstar! Posts: 1,468 From: ??? Joined: 28-May 09 | [center]Adding Keypresses Made for Sanny Builder and CLEO! In this tutorial, I'll show you how to simply add keypresses in San Andreas. This will mean you can press a key in-game to make something happen. There are 2 methods for doing this. One, uses the original San Andreas opcode which reads from the players settings to determine the key to press. The other, requires CLEO to work and allows more keypresses. The Original Way The original way uses this opcode... CODE 00E1: player 0 pressed_key 19 The first parameter (player 0) should not be changed if you are modding the PC version of the game. It simply tells the game which player has to press the key for it to take effect. This is only used in 2 Player mode. The second parameter (pressed_key 19) is the keypress number. There is a list of them in Sanny Builders help file. For the paremeter, we use the number from the # column. So, if we wanted to check if the player has crouched... We'd use this line... CODE 00E1: player 0 pressed_key 18 We will use this in a conditional loop like so... CODE :LOOP 0001: wait 0 00D6: if 00E1: player 0 pressed_key 18 004D: jump_if_false @LOOP So if the player has pressed the crouch button, the code will continue, if not the code will jump back up to :LOOP and check again. BUT, the code would also apply if the player pressed the key while in a car (the horn)... To get around this, simply add a check to make sure the player is on foot, not in a car... CODE :LOOP 0001: wait 0 00D6: if and 044B: actor $PLAYER_ACTOR on_foot 00E1: player 0 pressed_key 18 004D: jump_if_false @LOOP Now the code will only apply if the player is ON FOOT and presses the crouch key, not in a car and pressing the horn key The good thing about using this opcode is that it constantly adapts to what the player configuration is... Meaning that if the player changes the crouch key, the key in your code will use the same key as the new one the user sets... This is also good if you want to add functions that are already in the game... Because the user will usually already know which key to press. It's also good because you can be sure the user has that key, in case the persons keyboard doesn't have the key you add... The bad thing about this, is there aren't as many keys that are addable. And if the player has lot's of mods using the same keys, there may be bad results... So if you don't want to use that method we can instead use... The CLEO Way CLEO features a new opcode that enables you to check for ANY key pressed... CODE 0AB0: key_pressed 69 There is only one parameter (key_pressed 69) and it chooses which key should be prssed. The list of values are in Sanny Builders Help File > CLEO 3 Code Library > Virtual Keycodes (for 0AB0) You may need to download the latest version of Sanny Builder to get this list. You'll notice 3 columns. Character, Decimal and HEX. The character column simply shows us the key. The decimal column shows the decimal values of the key... So if the decimal value was 45 (Insert) we'd add this this to our code: CODE 0AB0: key_pressed 45 The HEX column shows us the hexidecimal value of the key... This is like the decimal value, except it uses different numbers and has 0x at the start... So if the HEX value was 2D (Insert) we'd add this to our code: CODE 0AB0: key_pressed 0x2D Both HEX and decimal values work the same. It doesn't matter which one we use. That's it really (simples!), just use this opcode in place of the other opcode... In a conditional loop. We can now press the key and something will happen! What? Well, that's for you to decide... And code. Good luck! -------------------- | CLEO 4.3.22 | A?i?a?o?3D | UI SDK | Black Market Mod 1.0.1 | GInput 0.3 | Cheat Keyboard | Tactile Cheat Activation | Stream Ini Extender 0.7 | SuperVars | ScrDebug | Vigilante Justice: San Andreas | |
Aug 17 2009, 09:37 PM Post #2 | |
Devil's Advocate Posts: 413 From: CA US Joined: 26-July 09 | What about using memory addresses? With this you can create ASCII strings to activate a script. 0A8D: 0@ = read_memory 0x00969110 size 4 virtual_protect 0 Parameters: 1 – Handle 1 – Memory Address 2 – Number of bytes to read/write (1, 2 or 4) 4 – Virtual Protect: 1 = read-only, 0 = rewritable 4 Byte String 'CODE' CODE :LABEL wait 0 0A8D: 0@ = read_memory 0x00969110 size 4 virtual_protect 0 if 04A4: 0@ == 0x434F4445 // Hex String 'CODE' jf @LABEL 0A8C: write_memory 0x00969110 size 4 value 0 virtual_protect 0 // Clear buffer For strings larger than 4 bytes we have to add another address. 8 Byte String 'JUMPRAMP' CODE :LABEL wait 0 0A8D: 1@ = read_memory 0x00969110 size 4 virtual_protect 0 0A8D: 2@ = read_memory 0x00969114 size 4 virtual_protect 0 if and 04A4: 1@ == 0x52414D50 // RAMP 04A4: 2@ == 0x4A554D50 // JUMP jf @LABEL 0A8C: write_memory 0x00969110 size 4 value 0 virtual_protect 0 // Clear buffer 0A8C: write_memory 0x00969114 size 4 value 0 virtual_protect 0 // Clear buffer ASCII Characters (HEX) CODE 41 = A 42 = B 43 = C 44 = D 45 = E 46 = F 47 = G 48 = H 49 = I 4A = J 4B = K 4C = L 4D = M 4E = N 4F = O 50 = P 51 = Q 52 = R 53 = S 54 = T 55 = U 56 = V 57 = W 58 = X 59 = Y 5A = Z This post has been edited by Adler: Aug 18 2009, 05:25 PM -------------------- |
Aug 22 2009, 05:52 PM Post #3 | |
Coding like a Rockstar! Posts: 1,468 From: ??? Joined: 28-May 09 | Heh, that's a heap more advanced. Was gonna make it in another thread There are a few other ways of doing that too -------------------- | CLEO 4.3.22 | A?i?a?o?3D | UI SDK | Black Market Mod 1.0.1 | GInput 0.3 | Cheat Keyboard | Tactile Cheat Activation | Stream Ini Extender 0.7 | SuperVars | ScrDebug | Vigilante Justice: San Andreas | |
Aug 1 2010, 07:02 PM Post #4 | |
The New Guy! Posts: 1 Joined: 1-August 10 | this is my first post on the forum so hope you can help me. I've seen this video: http://www.youtube.com/watch?v=nmB_0FwySQI and I've tried it and it works. Can easily find out how to change a hotkey as long as it is only one button at a time. I have started to putting a lot of mods together to create the coolest GTA game ever. But there are so many mods that I'll need to change some of the Hotkeys so there should be two buttons to activate the mod. Then i have many more buttons to work with. I have also read your post and I still don´t how I should do. Can you explain me or upload a video where you show how to change a normal hotkey to "2 buttons at same time hotkey" ? Example: Hotkey 97 (NUM1) + Hotkey 98 (NUM2) = CJ smokes (Mod activated) In sanny builder I have tried to write: 0AB0: key_pressed 97+98 (it did not work) 0AB0: key_pressed 97,98 (it did not work) 0AB0: key_pressed 97 0AB0: key_pressed 98 (it did not work) What should I write before it works? for your information: I use CLEO 4 and Sanny Builder 3 thanks a lot |
Aug 1 2010, 11:53 PM Post #5 | |
Coding like a Rockstar! Posts: 1,468 From: ??? Joined: 28-May 09 | You should find a coding tutorial SANNY :LOOP wait 250 if and 0AB0: key_pressed xx // replace xx with keycode 0AB0: key_pressed xx else_jump @LOOP // else_jump... jf and 004D: jump_if_false are also accepted by Sanny Builder. // Do something 0AB0 is a conditional opcode, like many other opcodes. They are used to ask the game if something has happened or is happening or to check the state of something. We could also use if or to say that EITHER of those two things should be happening (key1 pressed or key2 pressed) before the code continues. Have fun. -------------------- | CLEO 4.3.22 | A?i?a?o?3D | UI SDK | Black Market Mod 1.0.1 | GInput 0.3 | Cheat Keyboard | Tactile Cheat Activation | Stream Ini Extender 0.7 | SuperVars | ScrDebug | Vigilante Justice: San Andreas | |