How to implement "add effect" to a script from another script

I think I’ve made these changes.

I am not sure where to see these errors? Python console isn’t the section to them, and the console below at the very top, doesn’t show any information on them.

So why would all these errors affect the blood effect? Because it pretty much runs, so I couldn’t of caused all of these. :rofl:

import bge
from bge import logic

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

#self
self = scene.objects[own.name]

#properties
target = own['target']
incover = own['incover']
direction = own['direction']

#sensors
pnear = cont.sensors['Pnear']
collide = cont.sensors['Collision']
Ray = cont.sensors['Ray']
delay = cont.sensors['Delay1']
shootray = cont.sensors['shootray']

#actuators
refind = cont.actuators['State1']
attack = cont.actuators['State6']
flare = cont.actuators['flare']

#steering
findc = cont.actuators['walk']
runc = cont.actuators['runC']

#cover object
cover = scene.objects[own['target']]

#animations
runAnim = cont.actuators['run']
duck = cont.actuators['duck']

fwd = cont.actuators['fwdwalk']
back = cont.actuators['backwalk']
left = cont.actuators['walkleft']
right = cont.actuators['walkright']

fwdfire = cont.actuators['fwdwalkfire']
backfire = cont.actuators['backwalkfire']
leftfire = cont.actuators['walkleftfire']
rightfire = cont.actuators['walkrightfire']

#sound
sound = cont.actuators['sound']

#path finding
if cover['cover'] == 'safe' and pnear.positive == True and Ray.positive == False:
    findc.target = str(own['target'])
    cont.activate(findc)
    if direction == 'Run Forward':
        cont.activate(fwd)
    elif direction == 'Run Backward':
        cont.activate(back)
    elif direction == 'Run Left':
        cont.activate(left)
    elif direction == 'Run Right':
        cont.activate(right)

if cover['cover'] == 'safe' and pnear.positive == True and Ray.positive == True:
    findc.target = str(own['target'])
    cont.activate(findc)
    if direction == 'Run Forward':
        cont.activate(fwdfire)
    elif direction == 'Run Backward':
        cont.activate(backfire)
    elif direction == 'Run Left':
        cont.activate(leftfire)
    elif direction == 'Run Right':
        cont.activate(rightfire) 
        
elif cover['cover'] == 'safe' and pnear.positive == False:
    runc.target = str(own['target'])
    cont.activate(runc)
    cont.activate(runAnim)

#flare
if pnear.positive == True and Ray.positive == True and delay.positive and shootray.positive == True:
    cont.activate(flare)
    own.sendMessage("Phit", "", "player")
    cont.activate(sound)
elif pnear.positive == True and Ray.positive == True and delay.positive and shootray.positive == False:
    cont.activate(flare)
    cont.activate(sound)
    
#find new cover   
elif i['cover'] == 'safe':
    cont.activate(refind)

#cover found
if collide.positive == True and incover == '':
    if collide.hitObject.name == str(cover):
        cont.deactivate(findc)
        cont.activate(duck)
        cover['cover'] = 'used'
        own['incover'] = 'cover'
        cont.activate(attack)

bge is still an error.

Randomsmoke

import bge
from bge import logic
import random

cont = bge.logic.getCurrentController()
own = cont.owner

smoke1 = cont.actuators['7']
smoke2 = cont.actuators['8']

motion1 = cont.actuators['Motion']
motion2 = cont.actuators['Motion1']

delay = cont.sensors['Delay']

dir = own['back']
dist = own.getDistanceTo("player")

random = random.randint(1,2)

if random == 1 and dist < 250:
    cont.activate(smoke1)
if random == 2 and dist < 250:
    cont.activate(smoke2)

if delay.positive == True and dir == 0 and dist < 250:
    cont.activate(motion1)
    cont.deactivate(motion2)
    own['back'] += 1
if delay.positive == True and dir == 1 and dist < 250:
    cont.activate(motion2)
    cont.deactivate(motion1)
    own['back'] -= 1

If you ignore errors how will you ever get your problem solved?
Some errors only get listed after others are corrected.

You may be right that these are not directly related to the blood effect. (I corrected them in my copy of your file)
I managed to get blood on your first moving enemy.

For that you must correct ‘bloodhit’:

from bge import logic
import random
import bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

if own['blood'] > 0:
    own['blood'] -= 1
    own.applyRotation([0.0, 0.0, (random.randint(0, 90))])
    scene.addObject("blood splat", own, 10)

if own['blood'] == 1 or own['blood'] == 2:
    scene.addObject("bloodmist", own, 30)

Then when you shoot at the enemy it just disappears. This is because the blood objects get added but they have NOT been set to “Ghost” and so they push away the enemy into unknown space.
You must set these 2 objects to “Ghost” in the physics settings:
bloodmist
blood splat

This isn’t the bullet hole effect but at least a bit blood. :grinning:

To your above files.
I suppose your first code is from “movecover.py” (Please give more information in future)
You tried to fix it with my solution for another error.
Here is how “movecover.py” looks like here:

import bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

#self
self = scene.objects[own.name]

#properties
target = own['target']
incover = own['incover']
direction = own['direction']

#sensors
pnear = cont.sensors['Pnear']
collide = cont.sensors['Collision']
Ray = cont.sensors['Ray']
delay = cont.sensors['Delay1']
shootray = cont.sensors['shootray']

#actuators
refind = cont.actuators['State1']
attack = cont.actuators['State6']
flare = cont.actuators['flare']

#steering
findc = cont.actuators['walk']
runc = cont.actuators['runC']

#cover object
cover = scene.objects[own['target']]

#animations
runAnim = cont.actuators['run']
duck = cont.actuators['duck']

fwd = cont.actuators['fwdwalk']
back = cont.actuators['backwalk']
left = cont.actuators['walkleft']
right = cont.actuators['walkright']

fwdfire = cont.actuators['fwdwalkfire']
backfire = cont.actuators['backwalkfire']
leftfire = cont.actuators['walkleftfire']
rightfire = cont.actuators['walkrightfire']

#sound
sound = cont.actuators['sound']

#path finding
if cover['cover'] == 'safe' and pnear.positive == True and Ray.positive == False:
    findc.target = str(own['target'])
    cont.activate(findc)
    if direction == 'Run Forward':
        cont.activate(fwd)
    elif direction == 'Run Backward':
        cont.activate(back)
    elif direction == 'Run Left':
        cont.activate(left)
    elif direction == 'Run Right':
        cont.activate(right)

if cover['cover'] == 'safe' and pnear.positive == True and Ray.positive == True:
    findc.target = str(own['target'])
    cont.activate(findc)
    if direction == 'Run Forward':
        cont.activate(fwdfire)
    elif direction == 'Run Backward':
        cont.activate(backfire)
    elif direction == 'Run Left':
        cont.activate(leftfire)
    elif direction == 'Run Right':
        cont.activate(rightfire) 
        
elif cover['cover'] == 'safe' and pnear.positive == False:
    runc.target = str(own['target'])
    cont.activate(runc)
    cont.activate(runAnim)

#flare
if pnear.positive == True and Ray.positive == True and delay.positive and shootray.positive == True:
    cont.activate(flare)
    own.sendMessage("Phit", "", "player")
    cont.activate(sound)
elif pnear.positive == True and Ray.positive == True and delay.positive and shootray.positive == False:
    cont.activate(flare)
    cont.activate(sound)
    
#find new cover   
elif cover['cover'] != 'safe':
    cont.activate(refind)

#cover found
if collide.positive == True and incover == '':
    if collide.hitObject.name == str(cover):
        cont.deactivate(findc)
        cont.activate(duck)
        cover['cover'] = 'used'
        own['incover'] = 'cover'
        cont.activate(attack)

ok, got more body-hole and ground-hole working in your file.
My suggestion:
From the part 15 project file append the object “eyes” with the option “active layer” unchecked.
in logic bricks you see it has 4 sensors which go to “bullethit.py002”
Select “Camera” and “eyes” to reconnect the logic bricks.
Before:

You want to connect the “Camera”-Sensors to the “eyes”-Controller and Actuators:

After that you can delete The “eyes” -Sensors.
Now edit the Sensor-names in “bullethit.py.002” so it reads:

##############################################################
#Blender 2.5 bullethole script
 
#this script is free to use and is under no license agreement.
 
##############################################################
 
from bge import logic as GameLogic
from mathutils import Vector
c = GameLogic.getCurrentController()
scene = GameLogic.getCurrentScene()
own = c.owner
         
space = 0.3

gunspawn = scene.objects['gun spawn']

# sensors
Ray = c.sensors['Ray']
Ray2 = c.sensors['blood']
glockflare = c.sensors['glock']
m24flare = c.sensors['m24']

# actuator
ground_hole = c.actuators['bullet_hole']
body_hole = c.actuators['blood_hole']
ground = c.actuators['ground']
blood = c.actuators['blood']

if Ray.positive and glockflare.positive and gunspawn['equipped'] == 2 or Ray.positive and m24flare.positive and gunspawn['equipped'] == 1:
    # Get info
    
    pos_vec = Vector(Ray.hitPosition)
    normal_vec = Vector(Ray.hitNormal)
         
    # make object
    ground.instantAddObject()
    bullet_hole = ground.objectLastCreated
   
   # position hole
    bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
    normal_vec.magnitude = space
    bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
   
    ground_hole.instantAddObject()
    bullet_hole2 = ground_hole.objectLastCreated
         
    bullet_hole2.alignAxisToVect(normal_vec.xyz, 2, 1)
    normal_vec.magnitude = 0.003
    bullet_hole2.worldPosition = (pos_vec + normal_vec).xyz

if Ray2.positive and glockflare.positive and gunspawn['equipped'] == 2 or Ray2.positive and m24flare.positive and gunspawn['equipped'] == 1:
    
    # Get info
    pos_vec = Vector(Ray2.hitPosition)
    normal_vec = Vector(Ray2.hitNormal)
         
    # make object
    blood.instantAddObject()
    bullet_hole = blood.objectLastCreated
         
    # position hole
    bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
    normal_vec.magnitude = space
    bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
    
    # make object
    body_hole.instantAddObject()
    bullet_hole3 = body_hole.objectLastCreated
         
    # position hole
    bullet_hole3.alignAxisToVect(normal_vec.xyz, 2, 1)
    normal_vec.magnitude = 0.003
    bullet_hole3.worldPosition = (pos_vec + normal_vec).xyz

And finally - very important - set the physics of both objects “body-hole” and “ground-hole” to “ghost”.

Yes I changed line 91.

As for the blood effect, yes it now works, okayish.

As for ground hole and body hole.

I did append eyes and selected player camera, the eyes are in the same layer?

And I coped the bullethit.002 you have edited, no bullet hole on the cube or a ground hole effect The bullet hole I found in the layer and made sure the setting was active. Here is a clip, so gives you a view as to what is or isn’t working correctly.

I feel a bit disappointed, that I should of may be worked out bge import. :face_with_diagonal_mouth: But hey, what do I know about programming.

I may want to keep the glock’s light effect still active. I may want to use two weapons, knife and the glock. So I wouldn’t want to remove them from the game, just probably deactivate them.

But yes, I think the Ai is useful on the area there, just no on the stairs, so cover objects can be moved within the square area only.

But they were the primary AI, but I am editing my own one, I may keep one AI person. There is already one AI with a melee animation, at the end of the demo, that one more useful than the one with the gun.

Thanks.

Congrats!!

Yes, both in Layer 1. Did you reconnect the Sensors as shown in the screenshot?
The bulletholes work on your cube here.
They are not the most exciting effect I want to say.
For me it was quite fun to look into this level. And it’s a good work all together.

I wish you good luck and much fun in creating your modification!

Shooting at the ground needs 2 more objects appended from pthe Part 15 file:
“ground impact”
“dust spawn”

On import always deselect the option “active Layer” !!!

BTW: The Bulletholes on your cube are only visible when the cube doesn’t move towards you because they don’t stick to the skin of the cube. They get immediately covered if the cube moves in front of them.

Ok thanks for information keep it up

Here is a fix for the doors:
for every door disable the “end object” -brick of the Trigger:

Now the door opening animation plays and you can look inside :slight_smile:

My main interest is more in the AI and the task, in the area at the end there is one Ai with a melee effect.

Once in contact with the door trigger it then does an animation, I only used the part where it uses the weapon facing forward, so no turn.

Is the AI there usable similar to the AI with the gun, because I tried all of that but didn’t work out.

I will check the box on the door use, for the area, that is useful too, could lead to somewhere. The train station area isn’t of use, the trains may be of use for a future addon. Some sort of mini game with the player on the train. No idea on such a task.

The AI is really the task, a lot of it seems setup.

I mean I have it in the area. But it doesn’t animate when it contact with it.

I am not sure, The Ai will attack the player, once collision, but no sound or blood effect so the player is damaged.

As for the Ai moving around, the movecover code may not work out for it. I tried using it, and the player loaded behind the door, and the program shut down.

I’m guess a simple brick program is may be suited for that task, so once player collides, Ai moves to collide with player to stab and damage the player with the blood effect, similar with the gun AI that shoots at the player and causes damage to the player an eventually is removed from scene after too many stabs.

I did check out the door, they won’t open, none of the two. The door trigger were hidden. They are all now visible in the scene.

I think I can get by with the bricks for AI movement, but the existing python code is obviously useful for the attack player with a weapon. I was wrong on the gun, there is a light, so that is okay like that.

Here is your previous File with corrected scripts, blood, bulletholes and smoke.
All doors but the last are opening.
(You can see the door triggers can still be hidden but the “end Object”-brick has to be turned off)

What is the solution to the AI with the object to attack the player?

I don’t know what I can do with that.

The file I setup was just the changes of the AI, nothing else.

That file works out fine.

How can I get the AI the test cube to cause the damage?

So collision and then the damage effect starts to play through until the end scene of the game.

In the python code example, it is the shooting that is causing the damage and using a ray or something.

I don’t know.

import bge

cont = bge.logic.getCurrentController()
own = cont.owner

#properties
timer = own['timer']
crouch = own['crouch']
incover = own['incover']

#sensors
delay = cont.sensors['Delay1']
shootray = cont.sensors['shootray']

#actuators
flare = cont.actuators['flare']
crouchT = cont.actuators['crouchT']
crouchF = cont.actuators['=False']

#animations
aim = cont.actuators['Enemy_aim']
Cidle = cont.actuators['crouchidle']
duck = cont.actuators['duck']
reload = cont.actuators['reload']
shoot = cont.actuators['shoot']
up = cont.actuators['up']
mag = cont.actuators['magazine']

#sound
sound = cont.actuators['sound']

if timer < 511 and incover == 'cover':
    own['timer'] += 1

if timer > 0 and timer < 120:
    cont.activate(Cidle)
    cont.activate(crouchT)
elif timer > 120 and timer < 140:
    cont.deactivate(Cidle)
    cont.activate(up)
elif timer > 140 and timer < 160:
    cont.deactivate(up)
    cont.activate(crouchF)
    cont.activate(aim)
elif timer > 160 and timer < 250:
    cont.deactivate(aim)
    cont.activate(shoot)
elif timer > 250 and timer < 271:
    cont.deactivate(shoot)
    cont.activate(duck)
elif timer == 271:
    cont.deactivate(duck)
    cont.activate(crouchT)
    cont.activate(reload)
    cont.activate(mag)
elif timer > 391 and timer < 511:
    cont.deactivate(reload)
    cont.deactivate(mag)
    cont.activate(Cidle)
elif timer == 511:
    cont.deactivate(Cidle)
    cont.deactivate(aim)
    cont.deactivate(duck)
    cont.deactivate(reload)
    cont.deactivate(shoot)
    cont.deactivate(up)
    cont.deactivate(mag)
    own['timer']-= 511

#burst 1
if delay.positive and timer > 160 and timer < 176:
    cont.activate(flare)
    cont.activate(sound)
if delay.positive and timer > 160 and timer < 176 and shootray.positive:
    own.sendMessage("Phit", "", "player")

#burst 2
if delay.positive and timer > 190 and timer < 206:
    cont.activate(flare)
    cont.activate(sound)
if delay.positive and timer > 190 and timer < 206 and shootray.positive:
    own.sendMessage("Phit", "", "player")
    
#burst 3
if delay.positive and timer > 220 and timer < 236:
    cont.activate(flare)
    cont.activate(sound)
if delay.positive and timer > 220 and timer < 236 and shootray.positive:
    own.sendMessage("Phit", "", "player")

Brick try below.

I think for some Ai it is better using the bricks, even I don’t really know very well, but it is a little more clearer for myself.

The key addings are ASO or something enabledog in a message brick.

I am not sure, if duplicating the similar bricks as on player on the enemy helps to get the effect working for the collision May be collision brick works with Message brick ‘phit’ keyword.

Regen python code is to regenerate the player’s health meter or bar.

import bge

cont = bge.logic.getCurrentController()
own = cont.owner

msg = cont.sensors['hit']
Delay = cont.sensors['Delay']
health = own['health']
regen = own['player']

#regen
regenT = cont.actuators['true']
regenF = cont.actuators['false']

#health regen
if msg.positive == True:
    cont.activate(regenF)
    cont.deactivate(regenF)
    
if Delay.positive and health < 100 and health > 0 and regen == False:
    cont.activate(regenT)
    cont.deactivate(regenT)

if regen == True and health < 100 and health > 0:
    own['health'] += 1


If you want that a collision of the cube with the player shows the damage blood (like when he gets hit by shots) then you just have to send a message called “Phit” to the player.
This is easiliy done with the logic bricks like in your picture.

Each collision adds a bit. If you want to make it completely deadly then you can turn on “True level triggering” with the 3 dots and to reduce the speed the messages get sent you can edit the “skip” value:
grafik

Here is your file with a Knife Attacker.
Had to get rid of the builtin 90 °body-rotation in the knive animation. puh!
For the walk animation I simply used that from the other enemies. But you might want to put your hands on this because it doesn’t match to the knife attacker.
Although I added the blood sensors to the rig he’s immortal :slight_smile:
The logic bricks look like that:

Here’s the file:

The best is you don’t have to deal with any codes :rofl:

That is quite good. How did you get it to go up the stairs?

It isn’t the same as the primary game AI. So I guess that solved that. The was a sound file with it, but I think I can solve that myself. Bricks are confusing, but it was my motivation for blender game engine. I couldn’t use it without them.

Thank you for getting these tasks working.

Any obstacles I’ll call back.

I changed the physics type to dynamic and in the Steering brick unchecked “lock Z velocity”.
Meanwhile I added a sound when you get in contact.
Also you now can shoot at him or attack with the knfe and he will die (almost like the other enemies, but while they die after one knife stroke he will take more :slight_smile: ) For that I created a modified “AIHealth2”-Script for him.
Now the logic bricks look more complicated, but far less than on the other enemies.
For me it was also quite interesting how this all works.
The Sensors on the enemy receive messages when the player hits them. These messages are collected by the “AIHealth”-Scripts that subtracts the enemie-health and when it is down to 1 the logic bricks are switched to another state that drive the Death-animations.
Here’s the file:

Have fun!! :slight_smile: