ID:1448537
 
(See the best response by Ter13.)
Can someone show me how to code someone block/defend for attack.
How do you want the thing to go? They get into blocking stance and sit in it? They need to time the block? What?
Blocking stuff like in hand to hand combat need to know how i can code something,like if someone attack when you guard is up he reduce,if power of the other person is too strong it will break your guard.
You could try to apply the block icon, and reduce if not dodge unblocked damage. Read the DM guide. it'll show you examples on how to attack, you can use your brain and conjure up the code to make them block. i would try just a basic reduce in damage (damage -= M.attack - (usr.defense + usr.block) im not sure if thats how it would go, but that could be the formula you put in your back pocket.

someone tell me if im wrong so i know
Just make it so you modify a blocking variable if they start blocking. While this blocking variable is true, damage is reduced to that person when attacked.
Lugia, could my way work though? is the idea good enough to work? im new so i just wanna know for myself
I couldn't really decipher what you said. But you had a blocking var so sure. Why not. I'd do a check to make sure damage isn't negative though, so you don't heal the enemy.
Best response
Here's something not really simplistic that ought to help you figure out what you need to do:

mob
var
tmp
blocking = 0
blockstrength = 2.0
blockduration = 50 //For 5 seconds, the block is effective
proc
startBlocking()
if(!blocking)
blocking = 1
var
blockstart = world.time
blockval
if(blockstrength == 2.0)
//for half a second, the strength of the block will be 2.0
sleep(5)
blockstrength = 1.0
//every tick, decrease the strength of the block until it reaches 0.5
while(blocking && blockstrength > 0.5)
blockval = (world.time - blockstart) / (blockduration - 5)
blockstrength = max(0.5, (1.0 - blockval ** 2))
sleep(1)

stopBlocking()
if(blocking)
blocking = 0
var
blockstop = world.time
blockval
startval = blockstrength
//don't recover block strength for half a second.
sleep(5)

//every tick, increase the strength of the block until it reaches 1.0
while(!blocking && blockstrength < 1.0)
blockval = (world.time - blockstop) / (blockduration * ( 1 - startval))
blockstrength = min(1.0, startval + (1 - startval) * blockval)
sleep(1)

//wait a half a second to recover to 2.0
sleep(5)
if(!blocking && blockstrength == 1.0)
blockstrength = 2.0


This approach creates a blocking variable that you can check to see if the user is blocking. This version does something neat as well, in that the block gets weaker over time, so you have to let it cool down in order to use it properly. For the first half a second it is in use, it will increase the strength of the block by double, and from there, it will steadily degrade to half as strong using a quadratic formula.

Lastly, it will attempt to recover the strength of the block over a period of time determined by a linear relationship between the strength of the block used, and the time you set the block to endure using the blockduration variable.

You will need to set up some form of a keybind for this to work using your interface files, and you will need to create client verbs that will call blockStart() and blockStop().

Finally, you can actually use this block like this:

mob
combatant
proc
takeDamage(mob/combatant/attacker, damage)
if(blocking)
damage = max(1, round(damage - src.defense * blockstrength))
attacker << "hits for [damage] damage!"
src << "hits for [damage] damage!"

testAttack(mob/combatant/target)
src << "You attack [target] with blast cannon, which \..."
target << "[src] attacks you with blast cannon, which \..."
target.takeDamage(src,1000)


This might be a little advanced for you, so if you have any questions about how things work, please ask. I will not, however, be changing this for you to work in a certain way, because you should be writing a system that will work for your own game. I'm just here to show you one of many approaches.
MegaMan999 the unpractice programmer.make a little easier like for example put up block when press b and release when press back b and also is broken when it overpowered.
In response to MegaMan999
MegaMan999 wrote:
MegaMan999 the unpractice programmer.make a little easier like for example put up block when press b and release when press back b and also is broken when it overpowered.

Ter13 Wrote:
This might be a little advanced for you, so if you have any questions about how things work, please ask. I will not, however, be changing this for you to work in a certain way, because you should be writing a system that will work for your own game. I'm just here to show you one of many approaches.
In response to MegaMan999
MegaMan999 wrote:
MegaMan999 the unpractice programmer.make a little easier like for example put up block when press b and release when press back b and also is broken when it overpowered.

Gotta remember that Dev Help is for people that help themselves. Asking for handouts will earn you a bad rep and get you nothing.