dutchy 0 Report post Posted October 21, 2010 Hello all, Below is a code for a jumping script. It works great however I just want to be able to change one little thing... If a player can Jump the distance (In my example 6 tiles) but can do it 4 or 3 because that's where the closes landing point is, then I'd like my character to be able to do that, instead of jumping the full 6 squares. I've looked though a number of Jumping Scripts and did a pretty wide google search and found nothing... Any support would mean the world to me #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:= # Simple Jump System by Nathmatt # Version: 1.03 # Type: Custom Movement System #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:= # # This work is protected by the following license: # #---------------------------------------------------------------------------- # # # # Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported # # ( http://creativecommons.org/licenses/by-nc-sa/3.0/ ) # # # # You are free: # # # # to Share - to copy, distribute and transmit the work # # to Remix - to adapt the work # # # # Under the following conditions: # # # # Attribution. You must attribute the work in the manner specified by the # # author or licensor (but not in any way that suggests that they endorse you # # or your use of the work). # # # # Noncommercial. You may not use this work for commercial purposes. # # # # Share alike. If you alter, transform, or build upon this work, you may # # distribute the resulting work only under the same or similar license to # # this one. # # # # - For any reuse or distribution, you must make clear to others the license # # terms of this work. The best way to do this is with a link to this web # # page. # # # # - Any of the above conditions can be waived if you get permission from the # # copyright holder. # # # # - Nothing in this license impairs or restricts the author's moral rights. # # # #---------------------------------------------------------------------------- # #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:= # # This is the config: # # (Jump_Distance) is how far you want to jump. # # (Cant_Jump) is the terrain tag that you cant jump on. # # (Off_Switch_id) is the swith id used to turn off the jump. # # (Jump_key) is the key used to jump if using tons ads custom controls. # # (Jump_Animation) is if you want a speacial graphic for jumping # add _jmp so 001-Fighter01 would be 001-Fighter01_jmp. # #------------------------------------------------------------------------------- module Nathmatt_Config Jump_Distance = 2 Jump_Animation = false Off_Switch_id = 50 Jump_Key = 'Space' # Terrain_Tags Cant_Jump = 1 end #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:= # # This is the update method: # #------------------------------------------------------------------------------- class Game_Player < Game_Character alias nathmatt_update update def update nathmatt_update actor = $game_party.actors[0] unless actor == $game_party.actors[0] if $tons_version != nil && $tons_version >= 5.40 && TONS_OF_ADDONS::CUSTOM_CONTROLS if Input.trigger?(Input::Key[Nathmatt_Config::Jump_Key]) unless jumping? || $game_switches [Nathmatt_Config::Off_Switch_id] c = Nathmatt_Config::Cant_Jump d = Nathmatt_Config::Jump_Distance case direction when 2 then jump(0,d) unless check_terrain(0,d,c) when 4 then jump(-d,0) unless check_terrain(-d,0,c) when 6 then jump(d,0) unless check_terrain(d,0,c) when 8 then jump(0,-d) unless check_terrain(0,-d,c) end end end else if Input.trigger?(Input::A) unless jumping? || $game_switches [Nathmatt_Config::Off_Switch_id] c = Nathmatt_Config::Cant_Jump d = Nathmatt_Config::Jump_Distance case direction when 2 then jump(0,d) unless check_terrain(0,d,c) when 4 then jump(-d,0) unless check_terrain(-d,0,c) when 6 then jump(d,0) unless check_terrain(d,0,c) when 8 then jump(0,-d) unless check_terrain(0,-d,c) end end end end if jumping? && Nathmatt_Config::Jump_Animation @character_name_org = actor.character_name @character_name = @character_name_org+'_jmp' end if @character_name != actor.character_name @character_name = actor.character_name unless jumping? end end def check_terrain(x,y,condition) px = $game_player.x + x py = $game_player.y + y if $game_map.terrain_tag(px,py) == condition return true else return false end end end Share this post Link to post Share on other sites
Valdred 1 Report post Posted October 21, 2010 Put this script above main (and include the script you posted too) class Game_Map alias old_fucking_update update def update old_fucking_update $game_player.jump_count = 0 if Input.trigger?(Input::A) end end Now, the player will stop every time the A trigger is pressed. Don't know what triggers are? Press f1 while playtesting and you will see. Share this post Link to post Share on other sites
dutchy 0 Report post Posted October 21, 2010 Not sure why you posted that Share this post Link to post Share on other sites
Marked 197 Report post Posted October 22, 2010 Valdred, that isn't related to his request. And don't name your aliases silly things. Share this post Link to post Share on other sites
CrimsonInferno 35 Report post Posted October 22, 2010 Isn't this what you have to change? I haven't tested it, put it looks like it. :sweatdrop: module Nathmatt_Config Jump_Distance = 2 Jump_Animation = false Off_Switch_id = 50 Jump_Key = 'Space' # Terrain_Tags Cant_Jump = 1 Share this post Link to post Share on other sites
dutchy 0 Report post Posted October 22, 2010 No, sorry. I'll try and explain it like this... Say if a player needs to jump 4 Tiles and the Jump_Distance = 8 Instead of jumping all 8 Tiles He should only Jump 4 because that's where the closest land place is. Share this post Link to post Share on other sites
Marked 197 Report post Posted October 22, 2010 I don't think its as complicated as it sounds. In RGSS its pretty simple to get your players X and Y coordinates and his direction, so all you have to do is check the passiblity of each of the 8 squares in front of him on all 3 layers and if there is an event there. Pretty pointless to say because I can't exactly do it :sweatdrop: Share this post Link to post Share on other sites
dutchy 0 Report post Posted October 22, 2010 (edited) I don't think its as complicated as it sounds. In RGSS its pretty simple to get your players X and Y coordinates and his direction, so all you have to do is check the passiblity of each of the 8 squares in front of him on all 3 layers and if there is an event there. Pretty pointless to say because I can't exactly do it :sweatdrop: Correct... I just want the character to jump to the closest option. In example... ---Example 1---- (start) x x x o o x o o (max jump length*) *8 tiles *x = can't pass *o = passable ground. (*each represent a tile) If the Example 1 The player is jumping to the right, because the 4th tile is available to land on then it should land there instead of the 8th tile because that's the max jump length. The only time a player should jump 8 tiles is when a situation like this comes up as shown in Example 2. ---Example 2---- (start) x x x x x x x o (finish) If also possible can it be defined within that code that the minimum jump length is 2 tiles? So that the character isn't jumping one tile at a time? Edited October 22, 2010 by dutchy Share this post Link to post Share on other sites
Marked 197 Report post Posted October 22, 2010 If also possible can it be defined within that code that the minimum jump length is 2 tiles? So that the character isn't jumping one tile at a time? I'm pretty sure thats easy. You work it out based on your characters coordinates and direction. Say if he's facing left, we're talking X, and say he's at X=4, Y=6. You got that variable already in the script, its pretty easy to do. So then to get the coordinates of the tiles we want to check for passibilty, well, you could do $i=[variable for players X or Y c] + 2 for($i < [variable for players X or Y c] + 2 + 8 ){ code to check passibilty, using $i as the X/Y coordinate, and the other constant coordinate if($i is passable){ break and return $i } $i++ } Actually that is kinda php but that's all I know :sweatdrop: but all of that is more or less the same in RGSS, above would be same. In fact I could probably write it if I knew how to return whether a tile is passable based on its coordinates. Share this post Link to post Share on other sites
dutchy 0 Report post Posted October 22, 2010 Thanks for the support, I'm trying to get my hed around it all my self... sometimes i get lucky sometimes i can't get anything right... :( Share this post Link to post Share on other sites
Marked 197 Report post Posted October 22, 2010 Good news :) I have successfully edited this and it works :) But first, do you know what terrain tags are? They are defined in the tileset tab in the database and are what makes the whole system work. Basically, you set any tile you dont want to be jumped to a terrain tag of 1(or another number, its defined in the script). Here's the script. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:= # Simple Jump System by Nathmatt # Version: 1.03 # Type: Custom Movement System #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:= # # This work is protected by the following license: # #---------------------------------------------------------------------------- # # # # Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported # # ( http://creativecommons.org/licenses/by-nc-sa/3.0/ ) # # # # You are free: # # # # to Share - to copy, distribute and transmit the work # # to Remix - to adapt the work # # # # Under the following conditions: # # # # Attribution. You must attribute the work in the manner specified by the # # author or licensor (but not in any way that suggests that they endorse you # # or your use of the work). # # # # Noncommercial. You may not use this work for commercial purposes. # # # # Share alike. If you alter, transform, or build upon this work, you may # # distribute the resulting work only under the same or similar license to # # this one. # # # # - For any reuse or distribution, you must make clear to others the license # # terms of this work. The best way to do this is with a link to this web # # page. # # # # - Any of the above conditions can be waived if you get permission from the # # copyright holder. # # # # - Nothing in this license impairs or restricts the author's moral rights. # # # #---------------------------------------------------------------------------- # #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:= # # This is the config: # # (Jump_Distance) is how far you want to jump. # # (Cant_Jump) is the terrain tag that you cant jump on. # # (Off_Switch_id) is the swith id used to turn off the jump. # # (Jump_key) is the key used to jump if using tons ads custom controls. # # (Jump_Animation) is if you want a speacial graphic for jumping # add _jmp so 001-Fighter01 would be 001-Fighter01_jmp. # #------------------------------------------------------------------------------- module Nathmatt_Config Jump_Distance = 4 Jump_Distance_Min = 2 Jump_Animation = false Off_Switch_id = 1 Jump_Key = 'C' # Terrain_Tags Cant_Jump = 1 end #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:= # # This is the update method: # #------------------------------------------------------------------------------- class Game_Player < Game_Character alias nathmatt_update update def update nathmatt_update actor = $game_party.actors[0] unless actor == $game_party.actors[0] if Input.trigger?(Input::A) unless jumping? || $game_switches [Nathmatt_Config::Off_Switch_id] c = Nathmatt_Config::Cant_Jump d = Nathmatt_Config::Jump_Distance m = Nathmatt_Config::Jump_Distance_Min case direction when 2 try = d while try >= m pass=check_terrain(0,try,c) if pass==false jump(0,try) break else try=try-1 end end when 4 try = d while try >= m pass=check_terrain(-try,0,c) if pass==false jump(-try,0) break else try=try-1 end end when 6 try = d while try >= m pass=check_terrain(try,0,c) if pass==false jump(try,0) break else try=try-1 end end when 8 try = d while try >= m pass=check_terrain(0,-try,c) if pass==false jump(0,-try) break else try=try-1 end end end end end#end for def update if jumping? && Nathmatt_Config::Jump_Animation @character_name_org = actor.character_name @character_name = @character_name_org+'_jmp' end if @character_name != actor.character_name @character_name = actor.character_name unless jumping? end end#end of alias #Checks the terrain coorindates against the terrain tag def check_terrain(x,y,condition) px = $game_player.x + x py = $game_player.y + y if $game_map.terrain_tag(px,py) == condition return true else return false end end end#end of class When testing I set the jump distance to 4 and the minimum jump distance (a variable I added) to 2. So, say you're standing in front of a building (which has its tiles set to a terrain tag of 1) and you're standing 3 squares away from it, he will jump right to the wall. It would look way cooler if the min jump was set to 1. Hope this is what you wanted, just reply if you have any problems with it. Share this post Link to post Share on other sites
Valdred 1 Report post Posted October 22, 2010 I feel that I have to justify myself. My post was totally related to his request. I might have misunderstood what he was asking for, but a script that makes the player end the jump anytime by pressing a key is at least not so unrelated that it is worthy of a "not sure why you posted that." Did I explain in a bad way what it does? I'm so sorry, I'm not a native english speaker. Didn't the script work? It happens that the scriptlets I write aren't properly read trough, if that's the case it is my fault. Concerning the swearing in my code: I did not know that it was a rule against swearing, but if it is I should have read trough the rules more properly (I should have anyway). old_update is a very common alias name so to improve compatibility I added the F word (it was the first thing that came into my mind). Share this post Link to post Share on other sites
Marked 197 Report post Posted October 22, 2010 Ah ok, I apologize for saying it was unrelated, I understand what it does now. I originally couldn't find the connection. I didn't know you weren't a native English speaker, so your English is perfectly fine. As for swearing, its not expressly mentioned in the rules, but its more about posting etiquette. You could argue all day about whether it should be against the rules or not, I think it should be in allowed in the debate and mature discussion forum, but I don't think its necessary inside of code lol. If you want to discuss it further PM me. Share this post Link to post Share on other sites
Valdred 1 Report post Posted October 22, 2010 Happy ending then. No need to discuss that further :) Share this post Link to post Share on other sites