ID:303370
 
Hey, I'm looking for help with a wall climbing code, e.g. If you've watched the anime Naruto, as soon as they focus chakra to their feet the characters can run up walls, so I need the mob to be able to run up dense turfs after activating the i.e. "Focus Chakra to Feet" Verb. But as soon as the mob starts running up the vertical surface Id also like their animation to change to the wall climbing state.

Sorry if its a little hard to understand, I'm new to programming xD.
Have a look at Enter() and icon_state in the reference.
i could help you with this if you want, if you haven't already figured it out.
Sorry that I didnt reply a while back, havent been on here for a while as a result of studies and university stuff =S
mob/var/can_climb_walls = 0
mob/verb/Focus_Chakra_to_Feet()
can_climb_walls = 1
mob/verb/Some_Other_Focus()
can_climb_walls = 0

turf/wall/Enter(mob/m)
if(ismob(m))
if(m.can_climb_walls)
m.icon_state = "climbing"
return 1
return ..()
turf/wall/Exited(mob/m)
if(ismob(m))
if(m.icon_state == "climbing")
m.icon_state = initial(m.icon_state)//reset the icon state back to default
return ..()


Take this all with a grain of salt, its not the best way to do any of this. It's a basic demonstration of how it could work. I gave you a simple solution instead of giving you a long answer because we're all not very sure how important the climbing mechanic is going to be in your game. Also, since you specified you wanted it to work "via a verb" and you're new to programming, you probably don't need or even want a climbing system that is too hard for you to understand at your current level.

Ideally, you'd want to define what can and can't be climbed either via type path (ie: /turf/climbable/wall_a) or via property value (ie: turf/var/climbable).

Next, you need a system that keeps track of player "focus", and how focus is "shifted". You could do this with a list (if player can have multiple focuses), a variable (player can only focus on one thing at a time), or with a proc that can be overridden (ie: mob.CanFocus(focus)).

Here's an example of the latter:

focus
name = ""
id = 0
focus/Chakra
name = "Chakra"
id = 1
mob
var/focus/focus = null

verb/TestFocusChakra()
focus = new/focus/Chakra
verb/StopFocus()
focus = null
verb/CheckFocus()
world << "You are focusing on [src.focus]"


From there, you can implement ways for atoms to get the status of a mob's focus...


#define FOCUS_CHAKRA 1
turf/climbable/wall
Enter(atom/movable/a)
if(ismob(a))
var/mob/m = a
if(m.focus.id == FOCUS_CHAKRA)
return 1
return ..()


Next, you need an animation / icon_state changing system that will keep track of when icon_states are allowed to occur. You could just "inline check" them, but that will make code really hard to manage in future. An inline check would be like:

turf/wall
Enter(atom/movable/a)
if(a.icon_state == "climbing")
//do something


You can avoid this by having an icon_state manager of some sort...

At any rate, this reply is getting long, and you're probably realizing the scope of your question is quite vague and the answer could be anywhere from a simple 5 - 10 lines of code all the way to 4 - 5 game mechanic cores that would be robust to handle the growth of your game's code.

I'm mostly just defending my post because a comment was made about how the code is "probably one of the worst ways you can make a climbing code". Unfortunately, the answer isn't short unless you want a really bad method.
You probably want to put a "climbing" area over every thing you deem climbable instead of making those checks and changing your icon state twice after every time you move, and have another variable set to check whether or not you're climbing. That code above is probably one of the worst ways you can make a climbing code.
In response to Galactic Soldier (#5)
Galactic Soldier wrote:
You probably want to put a "climbing" area over every thing you deem climbable instead of making those checks and changing your icon state twice after every time you move, and have another variable set to check whether or not you're climbing. That code above is probably one of the worst ways you can make a climbing code.

Yeah, because its usually pretty impossible to help these people do something proper because of how many places you'd need to inject code to make it work properly.

Then again, maybe that's why the byond community has a lot of bad programmers... they learn on the forum, and forum people give them quick 10 - 20 line solutions for everything rather than a proper implementation.