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

Hmm, how would I do this for the cube enemy? So player shoots the cube, and then it removes or I am not sure.

I don’t mean the cube damages the player, we already know this.

Use “AIHealth2.py” in the brick!!!

The important thing is that all Sensors and Actuators that are mentioned in the script are really existent with their correct names
Or you edit the script and remove what you don’t want. (No we don’t want to do this now)
The enemies have different objects as sensor for Head, body etc.
Your cube only is himself so he is head, body all together.
Bad thing is that 1 headshot leads to suddendeath so better remove this. But how?
You are not allowed to leave away the message sensor because then the whole script doesn’t work. A trick is to give the Message Sensor Subject an unused name. It expects “hit” but I named it “hit disabled” so it will never receive the message.
Then for the States be sure you make all states visible. So you can add “and”-Controller and set their state to “2” and “3”.
Both then will lead to “end Object”.
Inspect the picture in all details.

Hi,
although the above example is an ideal chance to start understanding how a script works the same can be managed with Logic Bricks only too. :slight_smile:
And be simplified. No need to use different states.

I wasn’t sure,

Why head on the cube, surely it is the body? So shoot the cube bodyhit is the word for that. I saw the example for the AI character, and I just thought that was the way to go about that.

That example is to use the knife, not a gun? I would need a gun for that, as that cube is the basis for a new AI. I wanted to keep it a bit more simple compared to the main one, just for ease of use.

What is “that example”? You must be more clear in your questions.
Both examples work with guns and knife.
Let’s concentrate on the “only bricks”-solution. That is the most simple solution.
There are 2 Message Sensors.
If the player shoots and hits the cube, he will send a message with subject “hit”.
If the player uses the knife and hits the cube, he will send a message with subject “knife”

When the Message Sensors get one of these messages they will trigger the controller that will add “-1” to the health property.

Yes, the headhit could be removed from the script and the Sensors brick deleted. You can try to do it.

I think it works, but the cube seemed to vanish, after I had shot it many times, but I am not sure if it removed instant, I went to see the Ai I had removed, so I went back up the stairs, and it wasn’t there.

My video shows what is or isn’t working.

Does the go property also required on the Ai cube, I don’t think so.

Perhaps the code isn’t needed?

Aihealth2.py

You are incredible! :grinning:
I see what is wrong on your try but I won’t tell you.

If you manage to build your bricks like in my picture it will work.
Hint:

  1. check And-Controller states
  2. why do you add 1 health?
  3. Are the Actuator names really correct? state3 is not the same as State3
  4. which Always Sensor has the 3 dots enabled?
  5. You are your teacher

Please look above. I posted a solution without Code with a nice image.
If you manage to build your bricks like in my picture it will work.

And don’t forget: Never look at the Console for errors because this is only for nothing.
I’m sure you will master it. Because you want. Please post a picture of your working bricks.

I did try and do what you’ve put together, but nothing changes?

I also forgot, using key 7 I wanted to load the item to use, so it would work similar to a knife, just animated a little for effect. The chain item. I never got it to work. I don’t know. That was my first goal, when I tried this edit in April.

I never do look at the console…

I’m not that well versed in all of blender.

The collision works of the AI with the player, to cause damage, but not too well, but the player doesn’t end as a result of too much collision, knife guy finishes the player off. Ha!

in Change.py, that was where I tried to add 7 load chain onto player’s hands. It never loaded. I had to edit it a lot to make it stable for the game. But yes, I am guessing the knife code will work perfectly for that, using the bricks or code. Bit of both.

import bge

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

equipped = own['equipped']
target = own['target']
timer = own['timer']
change = own['change']
reload = own['reload']
Grenades = own['Grenades']
Smoke = own['Smoke']
shoot = own['shoot']

collide = cont.sensors['cutscene']

#animations
down_m24 = cont.actuators['downm24']
downGlock = cont.actuators['downGlock']
upm24 = cont.actuators['pickupm24']
upGlock = cont.actuators['pickupGlock']
downGren = cont.actuators['down_Gren']
upGren = cont.actuators['pickup_Gren']
Sdown = cont.actuators['Sdown']
Sup = cont.actuators['Sup']
Kdown = cont.actuators['knifedown']
Kup = cont.actuators['knifeup']
opendoor = cont.actuators['opendoor']

self = scene.objects[own.name]
movement = scene.objects['player']

#sets change == True
if own['target'] != own['equipped'] and reload == False and shoot == True or own['equipped'] == 0 or own['target'] == 6:
    self['change'] = True
elif own['target'] == own['equipped']:
    self['change'] = False

#timer  
if change == True and timer < 30 and movement['door'] == False:
    own['timer'] += 1

if change == True and movement['door'] == True and timer < 45:
    own['timer'] += 1
    
#putting down weapon
if equipped == 0 and change == True and timer == 0:
    cont.activate(downGlock)
if equipped == 1 and change == True and timer == 0:
    cont.activate(down_m24)
if equipped == 2 and change == True and timer == 0:
    cont.activate(downGlock)
if equipped == 3 and change == True and timer == 0:
    cont.activate(downGren)
if equipped == 4 and change == True and timer == 0:
    cont.activate(Sdown)
if equipped == 5 and change == True and timer == 0:
    cont.activate(Kdown)
if equipped == 7 and change == True and timer == 0:
    cont.activate(Kdown)
    
#ends old weapon + animation
if timer == 15 and change == True and equipped == 0:
    cont.deactivate(downGlock)
if timer == 15 and change == True and equipped == 1:
    own.sendMessage("endm24")
    cont.deactivate(down_m24)
if timer == 15 and change == True and equipped == 2:
    own.sendMessage("endglock")
    cont.deactivate(downGlock)
if timer == 15 and change == True and equipped == 3:
    own.sendMessage("endGren")
    cont.deactivate(downGren)
if timer == 15 and change == True and equipped == 4:
    own.sendMessage("endSmoke")
    cont.deactivate(Sdown)
if timer == 15 and change == True and equipped == 5:
    own.sendMessage("endKnife")
    cont.deactivate(Kdown)
if timer == 15 and change == True and equipped == 7:
    own.sendMessage("endchain")
    cont.deactivate(Kdown)
    
#spawn new weapon
if timer == 15 and change == True and target == 1:
    scene.addObject('m24', own, 0)
if timer == 15 and change == True and target == 2:
    scene.addObject('Glock', own, 0)
if timer == 15 and change == True and target == 3:
    scene.addObject('Grenade', own, 0)
if timer == 15 and change == True and target == 4:
    scene.addObject('smoke', own, 0)
if timer == 15 and change == True and target == 5:
    scene.addObject('knife', own, 0)
if timer == 15 and change == True and target == 7:
    scene.addObject('chain', own, 0)

#picking up weapon
if timer > 15 and timer < 30 and change == True and target == 1:
    cont.activate(upm24)
if timer > 15 and timer < 30 and change == True and target == 2:
    cont.activate(upGlock)  
if timer > 15 and timer < 30 and change == True and target == 3:
    cont.activate(upGren)
if timer > 15 and timer < 30 and change == True and target == 4:
    cont.activate(Sup)
if timer > 15 and timer < 30 and change == True and target == 5:
    cont.activate(Kup)
if timer > 15 and timer < 30 and change == True and target == 7:
    cont.activate(Kup)
if timer > 15 and timer < 45 and change == True and movement['door'] == True and target == 6:
    cont.activate(opendoor)

#open sesame
doorsound = cont.actuators['doorsound']
if timer == 30 and change == True and movement['door'] == True and target == 6:
    select = collide.hitObjectList[0]
    own.sendMessage("opendoor", "", str(select))
    cont.activate(doorsound)
#resetting properties
if timer == 30 and change == True and own['equipped'] != own['target'] and movement['door'] == False:
    own['equipped'] = own['target']
    own['timer'] -= 31
    cont.deactivate(upm24)
    cont.deactivate(upGren)
    cont.deactivate(upGlock)
    cont.deactivate(Sup)
    cont.deactivate(Kup)

#resetting after cutscene
if timer == 45 and change == True and movement['door'] == True and own['equipped'] != 6:
    own['equipped'] = own['target']
    movement['door'] = False
    movement['control'] = True
    movement['cutscene'] = 0
    self['timer'] = 0
    own.sendMessage("restorecontrol")
    cont.deactivate(opendoor)
    own['target'] = 2
    
#intial weapon selection
if equipped == 0:
    self['target'] = 2

I am guessing when it loaded, it would use the similar animation of kup and kdown or something.

I did now include a - on the property for health, but no change with this.

Should damage cube, remove cube, and player gets damaged by cube with damage effect using the filter, and the message ‘Pdie’

I am not sure what the position is with that. Could I simply just use the existing AI’s cube so headshot and bodyshot. One below and one above.

I removed the parent, and keep transformation. So I parent them to my new AI, it should be fine to use.

I did use the cube for movement, and then tried to add the bodyshot sensor, for a new AI, but it doesn’t work out too well. Can the bodyshot object so the middle one be used for both for a new AI? Do all three need to be use, because a bigger AI has all of them?

Armature is parent of the model. Then cube must be parent of the model object, and then bodyshot is child or something else.

Normally one cube is enough.

I tried again,

I edited the AI.

The AI doesn’t seek the player, not sure why this is.

I then simply tried to see if I could duplicate the wall and door, and placed it somewhere, included the open door object and trigger. The animation works but properly, but the doesn’t open once the scene is played only the arm movement and sound once.

The AI cube does actually damage the player now. But it didn’t remove itself, I notice this happened with the new AI using the duplicate cubes from the existing AI. :roll_eyes:

I tried using just the cube AI, the model just floats. Obviously the cube is the parent of all. Not sure. Static or dynamic for the cube doesn’t change anything. You can see the cube right ahead of the gun. So the AI floating to the left. :face_with_diagonal_mouth:

Hi,
why do you have the health2.py set to state2?
Do you understand how states work?
From your previous video it looks like the cube isn’t the parent of the armature but the child.

Here again (!!! see above!) is a solution for your cube without Python, hit sensors or different states.
On the left the properties. In the middle the logic bricks. On the right the physic settings.

BTW: Learn to look at the console for error messages. please!

Thank you for the response.

I edited the program bricks.

The cube I used on the new AI doesn’t cause damage, the AI floats around, while the cube remains on the ground seeking the player