I’m trying to create a combo hit script that I can reuse.
I’m sure you’ve seen this before. “God Of War” / “Jak and Daxter” etc. Where you fight an enemy and. . .
You have to press the correct key, in the correct time frame to get a hit. If you get all three, you get a super hit that greatly decreases the enemy health, and gives you more points. If you hit the wrong key, or not in time, you lose health, and the enemy gains back it’s full health, or whatever.
In this script I set up a combination of Ckey, Bkey, vkey. (see Blend file)
I’m wondering if the script is written correctly, or is there a better way to do this.
and, see where I used “def” to make functions (commented out). is there a way to call on these functions if the conditions are right. And reuse these functions in a different order.
So instead of using a property “obj[‘totals’]”. call the funtion directly?
Does this make any sense? Hope so.
Any help is appreciated, even if it’s “out of the box” so to speak.
In the Blend, when you press “P” be patient, I have the timer set really slow, so it takes a few sec before the “C” spawns.
import bge
def add(cont):
obj = cont.owner
sce = bge.logic.getCurrentScene()
E1 = sce.objects['Empty_1']
E2 = sce.objects['Empty_2']
E3 = sce.objects['Empty_3']
cee = bge.logic.keyboard.events[bge.events.CKEY]
vee = bge.logic.keyboard.events[bge.events.VKEY]
bee = bge.logic.keyboard.events[bge.events.BKEY]
ay = bge.logic.keyboard.events[bge.events.AKEY]
#def cee(cont):
if not 'init' in obj: # create properties
obj['init'] = 1
obj['timer'] = 0.0
obj['totals'] = 0
obj['timer'] += 1.0 / bge.logic.getLogicTicRate() # starts the timer
if obj['totals'] == 0:
if obj['timer'] > 5.0 and obj['timer'] < 10.0:
sce.addObject("C", E2, 2) # spawns first key
if cee and obj['timer'] > 5.0 and obj['timer'] < 10.0:
print ("on time")
obj['totals'] = 1
sce.addObject("hit", obj, 10)
obj['timer'] = 0.0
#go to the next function (bee)
elif cee and obj['timer'] > 0.0 and obj['timer'] < 4.0:
print ("too early")
# bring up "failed" overlay scene
# remove this scene
elif obj['timer'] > 10.1 and cee:
print ("too late")
# bring up "failed" overlay scene
# remove this scene
elif bee or vee:
print ("wrong key")
# bring up "failed" overlay scene
# remove this scene
#def bee(cont):
if obj['totals'] == 1:
if not 'init' in obj: # create properties
obj['init'] = 1
obj['timer'] = 0.0
obj['timer'] += 1.0 / bge.logic.getLogicTicRate() # starts the timer
if obj['timer'] > 5.0 and obj['timer'] < 10.0:
sce.addObject("B", E3, 2) # spawns 2nd key
if bee and obj['timer'] > 5.0 and obj['timer'] < 10.0:
print ("on time")
obj['totals'] = 2
obj['timer'] = 0.0
sce.addObject("hit",obj,10)
#go to the next function (vee)
elif bee and obj['timer'] > 0.0 and obj['timer'] < 4.0:
print ("too early")
# bring up "failed" overlay scene
# remove this scene
elif obj['timer'] > 10.1 and bee:
print ("too late")
# bring up "failed" overlay scene
# remove this scene
elif cee or vee:
print ("wrong key")
# bring up "failed" overlay scene
# remove this scene
##def vee(cont):
if obj['totals'] == 2:
if not 'init' in obj: # create properties
obj['init'] = 1
obj['timer'] = 0.0
obj['timer'] += 1.0 / bge.logic.getLogicTicRate() # starts the timer
if obj['timer'] > 5.0 and obj['timer'] < 10.0:
sce.addObject("V", E1, 2) # spawns 3rd key
if vee and obj['timer'] > 5.0 and obj['timer'] < 10.0:
print ("on time")
obj['totals'] = 3
sce.addObject("hit",obj,10)
#combo completed
elif vee and obj['timer'] > 0.0 and obj['timer'] < 4.0:
print ("too early")
# bring up "failed" overlay scene
# remove this scene
elif obj['timer'] > 10.1 and vee:
print ("too late")
# bring up "failed" overlay scene
# remove this scene
elif cee or bee:
print ("wrong key")
# bring up "failed" overlay scene
# remove this scene
if obj['totals'] == 3:
obj.sendMessage("superduperpowerhit")#changes player to a state that plays the superduperpowerhit animation
# remove this scene
http://pasteall.org/blend/index.php?id=50126
BF 2.78
This script and stuff will be on an overlay scene that will be called when the enemys health decreases a few hp’s.