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

##############################################################
#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()
own = c.owner
         
space = 0.003
         
# sensors
ray = c.sensors["Ray"]
ray2 = c.sensors['blood']
knife = c.sensors['knife']
m24 = c.sensors['m24']
glock = c.sensors['glock']
single = c.sensors['single']
timer = c.sensors['timer']

# actuator
spawn = c.actuators["spawns"]
spawn2 = c.actuators['spawnb']

#groundhit      
if ray.positive and m24.positive or ray.positive and glock.positive:
 # Get info
  pos_vec = Vector(ray.hitPosition)
  normal_vec = Vector(ray.hitNormal)
         
 # make object
  spawn.instantAddObject()
  bullet_hole = spawn.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz


#bloodhit
if ray2.positive and m24.positive or ray2.positive and glock.positive:
 #send hit message
  target = ray2.hitObject.name
  own.sendMessage("hit","",target)
 # Get info
  pos_vec = Vector(ray2.hitPosition)
  normal_vec = Vector(ray2.hitNormal)
         
 # make object
  spawn2.instantAddObject()
  bullet_hole = spawn2.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
  
  
#knifehit
if knife.positive and single.positive and timer.positive == True:
 #send hit message
  target = ray2.hitObject.name
  own.sendMessage("knife","",target)
 # Get info
  pos_vec = Vector(ray2.hitPosition)
  normal_vec = Vector(ray2.hitNormal)
         
 # make object
  spawn2.instantAddObject()
  bullet_hole = spawn2.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz

This code is different.

One should give an effect, and the other is a different one from that one.

##############################################################
#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['Ray2']
glockflare = c.sensors['glockflare']
m24flare = c.sensors['m24flare']

# 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

I want to add the effect to the main one.

What should I be looking out for?

I think the knife is the addition. I added the objects so that code should detect the objects in their layer.

Thank you

1 Like

you need stopped copy and insert script if you dont understand how this scripts work. Script in you example for create bullet hole and normalization on surface objects bullet hole object - if you need create shot, muzzle shot, and bullet - get gun barrel -

gun = own.children['glock_collider'] # if children parenting to owner
barrel = gun.children['glock_barrel'] # empty children for gun

mouse_lb = cont.sensors['Mouse_LB']

if mouse_lb.positive:
bullet = scene.addObject("bullet_glock", barrel, 1000)
muzzle = scene.addObject("muzzle_glock", barrel, 3) # this add muzzle flash
muzzle.worldPosition = barrel.worldPosition # assign position muzzle flash to barrel

and for you bullet assign script - create bullet hole and movement. If you use scripts and dont understand how work scripts and code - start learning python and then you will start creating your own scripts because no one will do it for you just like that

1 Like

Nothing to do with bullet firing, I added items from the tutorial files into the demo, which should give blood effect using the objects and the code.

The difference between the two is what?

And to be exact about what I mean I reviewed the part 15 file of the FPS tutorials

So it should work, enemy property on the Ai doesn’t show anything.

2 Likes
#bloodhit
if ray2.positive and m24.positive or ray2.positive and glock.positive:
 #send hit message
  target = ray2.hitObject.name
  own.sendMessage("hit","",target)
 # Get info
  pos_vec = Vector(ray2.hitPosition)
  normal_vec = Vector(ray2.hitNormal)

So this message should activate the blood texture animation meshes in the layer below layer 1, i’d guess. So enemy is the property, but that alone isn’t enough.
This is in the demo, but the part 15 file doesn’t have this as the script is shorter.

The second script has these, where as the demo doesn’t.

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

The key one. Does it mean I need a brick named blood, which is already the meshes in the layer below.

So this image shows what I mean about the objects added into the layer the same as the one from the tutorial series.

1 Like
##############################################################
#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()
own = c.owner
         
space = 0.003
         
# sensors
ray = c.sensors["Ray"]
ray2 = c.sensors['blood']
knife = c.sensors['knife']
m24 = c.sensors['m24']
glock = c.sensors['glock']
single = c.sensors['single']
timer = c.sensors['timer']

# actuator
spawn = c.actuators["spawns"]
spawn2 = c.actuators['spawnb']
ground_hole = c.actuators['bullet_hole']
body_hole = c.actuators['blood_hole']
ground = c.actuators['ground']
blood = c.actuators['blood']

#groundhit      
if ray.positive and m24.positive or ray.positive and glock.positive:
 # Get info
  pos_vec = Vector(ray.hitPosition)
  normal_vec = Vector(ray.hitNormal)
         
 # make object
  spawn.instantAddObject()
  bullet_hole = spawn.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz


#bloodhit
if ray2.positive and m24.positive or ray2.positive and glock.positive:
 #send hit message
  target = ray2.hitObject.name
  own.sendMessage("hit","",target)
 # Get info
  pos_vec = Vector(ray2.hitPosition)
  normal_vec = Vector(ray2.hitNormal)
         
 # make object
  spawn2.instantAddObject()
  bullet_hole = spawn2.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
  
  
#knifehit
if knife.positive and single.positive and timer.positive == True:
 #send hit message
  target = ray2.hitObject.name
  own.sendMessage("knife","",target)
 # Get info
  pos_vec = Vector(ray2.hitPosition)
  normal_vec = Vector(ray2.hitNormal)
         
 # make object
  spawn2.instantAddObject()
  bullet_hole = spawn2.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz

I tried the new code, no change in the effect. I did also try append the enemy cube, but that hasn’t change the lack of no effect.

The demo file only has two emptys above, they are called, bloodhit and groundhit, but they don’t appear to do anything, as if they did I wouldn’t be making this topic.

:roll_eyes:

The 2 scripts at the start of your thread are different.
You can see that they have different sensors and actuators.
These are all names of logic bricks that are needed to be connected to the python-brick.

What kind of bricks these are you can’t tell from their names.
E.g. a Sensor called ‘blood’ doesn’t tell you what kind of brick you have to create.
If you turn Window->“Toggle System Console” you can see what kind of errors you get.
e.g. of missing bricks
I bet these will be many error messages.

So each script is for a specific blend file. If you copy paste scripts then you have to adapt the blend or the script to work together.

1 Like

example_shot_muzzle_bullet_hole_blood.blend (117.4 KB)

1 Like

I’ll tell you again - your problem is that you don’t understand the scripts that you use in your projects, the actuators in your example are shot, blood, create mesh objects with textures and the script assigns them to the wall surface by aligning along the Z axis. all the same can be done much easier - I threw you an example, you just need to make an effort and learn python - and then things like getting positions, vectors, normals and ray throws will no longer be a problem for you, as in principle everything else in the game engine

1 Like

spawns

spawnb

Add object brick name^

So that is the name of those bricks linked with this python code bullethit.py in the demo version

##############################################################
#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()
own = c.owner
         
space = 0.003
         
# sensors
ray = c.sensors["Ray"]
ray2 = c.sensors['blood']
knife = c.sensors['knife']
m24 = c.sensors['m24']
glock = c.sensors['glock']
single = c.sensors['single']
timer = c.sensors['timer']

# actuator
spawn = c.actuators["spawns"]
spawn2 = c.actuators['spawnb']

#groundhit      
if ray.positive and m24.positive or ray.positive and glock.positive:
 # Get info
  pos_vec = Vector(ray.hitPosition)
  normal_vec = Vector(ray.hitNormal)
         
 # make object
  spawn.instantAddObject()
  bullet_hole = spawn.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz


#bloodhit
if ray2.positive and m24.positive or ray2.positive and glock.positive:
 #send hit message
  target = ray2.hitObject.name
  own.sendMessage("hit","",target)
 # Get info
  pos_vec = Vector(ray2.hitPosition)
  normal_vec = Vector(ray2.hitNormal)
         
 # make object
  spawn2.instantAddObject()
  bullet_hole = spawn2.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
  
  
#knifehit
if knife.positive and single.positive and timer.positive == True:
 #send hit message
  target = ray2.hitObject.name
  own.sendMessage("knife","",target)
 # Get info
  pos_vec = Vector(ray2.hitPosition)
  normal_vec = Vector(ray2.hitNormal)
         
 # make object
  spawn2.instantAddObject()
  bullet_hole = spawn2.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz

Timer is probably this brick, those two there are linked to the bullethit python script. So whether I use the objects from the Part 15 tutorial or not, the code should load some effect? It didn’t before my addition, and obviously no change in what I added or just showed a new script example, when the script appears use some type of add in effect for the blood.

So timer there represents the time sensor?

I am not a programmer, I tried to learn python in late 2013, I was twenty four. I tried visual studio fifteen years ago at college, Visual basic. I didn’t pass the section of the course. Or even the Maths unit. I passed the course, but not enough to go to level 3, which would lead to university.

Yes :slight_smile:

I am also not a programmer but learnt a lot by wanting to get an idea become true. Some years ago I started from Zero with Basic to get some macros working in LibreOffice. When looking through the Tutorials I thought this is way too complex (arrays , loops) and I will never need it. But step after step more and more was possible and at the end I learnt all the stuff. BECAUSE I wanted to realize my ideas.
Now I looked again at the Blender BGE and “suddenly” understood a lot of Python.
Had the idea of a Marble game and it’s like before: By wanting to realize an idea I just HAD to learn all necessary stuff to create my first game (“Marble and Ball” which you can find in this forum and certainly is ugly programming in the eyes of a real programmer)

I had a look at the 1.1demo blend you linked in the other thread and must say this is a huge project which is way too complex for learning if you didn’t follow all the tutorials from start. And I even don’t know at which level he started.
I would begin with a small but interesting idea and a cleaner blend.

3 Likes

And I’m not a programmer - I’m a lawyer, I studied programming myself first with C/C++, then I accidentally found Martin Dawson’s book “Programming in Python” and began to study and look for examples of how to program correctly for BGE, it turned out not so difficult if you know the basics.I would advise you to find this book and read it in order to understand the basics, since I see that you can’t read someone else’s code, I read that code with an example back in 2014 when I just started learning programming and most importantly, I understood what the actuator is responsible for and was able to supplement it for the work of spawn 6 objects through one actuator - just left the value empty. and through the dictionary, I substituted objects to add to the scene. Programming on the game engine itself is not distinguished by sophisticated complexity - you always need to import the game engine and logic, all other modules - math, random, vector, time, audi and others are added if necessary. It all depends on your desire to study and the desire to make your dream come true. Something I was philosophizing about - did the example that I threw off fit you?

1 Like

These are the actuators you need to create and connect to the bullethit.py.
Each is an “edit_object->addobject” and spawns different objects and empties of different hidden layers.
You have to make sure all these are present.
Then you must also have a look at the Sensors and their names. And check the if-statements.It seems they are a bit different in the files.
All in all this requires Sherlock Holmes.

In other words, you are an academic.

The level is complex, but because of what it has, I thought to try and edit, and add some objects, the first apptempts I tried back in April failed, a skeleton object for AI, didn’t work. It was made in 2.68.

I then decided to use the AI there, and add or edit it do something more, now that it doesn’t work in the area, I would like it to, I will have to leave that, and just use my own.

The guy who made it, the New Zealander, sounds British to me, but he does sound like a New Zealander, has the accent. He only went with the tutorial to just the player setup, not the actual demo, clearly nobody was interested in his project tutorial, so he closed it up.

That is the thing, the code has all those,

In the default one, I have already noticed spawns brick and the code reference of that word, and then splat object, so what is with that, could it be the guy placed that object for the demo in the game? So in the first layer, so I didn’t need to add the bloody effect from part 15 into the layer below layer 1, as I thought it was missing or not included.

Groundhit

Well add ground_hole, blood below spawns and spawnsb, and connect them, then add the object. Beyond that I am not sure.

##############################################################
#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()
own = c.owner
         
space = 0.003
         
# sensors
ray = c.sensors["Ray"]
ray2 = c.sensors['blood']
knife = c.sensors['knife']
m24 = c.sensors['m24']
glock = c.sensors['glock']
single = c.sensors['single']
timer = c.sensors['timer']

# actuator
spawn = c.actuators["spawns"]
spawn2 = c.actuators['spawnb']
ground_hole = c.actuators['bullet_hole']
body_hole = c.actuators['blood_hole']
ground = c.actuators['ground']
blood = c.actuators['blood']

#groundhit      
if ray.positive and m24.positive or ray.positive and glock.positive:
 # Get info
  pos_vec = Vector(ray.hitPosition)
  normal_vec = Vector(ray.hitNormal)
         
 # make object
  spawn.instantAddObject()
  bullet_hole = spawn.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz


#bloodhit
if ray2.positive and m24.positive or ray2.positive and glock.positive:
 #send hit message
  target = ray2.hitObject.name
  own.sendMessage("hit","",target)
 # Get info
  pos_vec = Vector(ray2.hitPosition)
  normal_vec = Vector(ray2.hitNormal)
         
 # make object
  spawn2.instantAddObject()
  bullet_hole = spawn2.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
  
  
#knifehit
if knife.positive and single.positive and timer.positive == True:
 #send hit message
  target = ray2.hitObject.name
  own.sendMessage("knife","",target)
 # Get info
  pos_vec = Vector(ray2.hitPosition)
  normal_vec = Vector(ray2.hitNormal)
         
 # make object
  spawn2.instantAddObject()
  bullet_hole = spawn2.objectLastCreated
         
 # position hole
  bullet_hole.alignAxisToVect(normal_vec.xyz, 2, 1)
  normal_vec.magnitude = space
  bullet_hole.worldPosition = (pos_vec + normal_vec).xyz
#bloodhit
if ray2.positive and m24.positive or ray2.positive and glock.positive:
 #send hit message
  target = ray2.hitObject.name
  own.sendMessage("hit","",target)

No im simply lawyer, just i like computer games and always dream make game

way you not looking my example? i make all spawn objects from script, and i not use actuators - because script add object very-very simply

I did open it in blender 2.78, but nothing happened with the gun object, what was suppose to happen?

As for the bullethit code, I don’t know what more I can do, I tried my searching of it, and looking at the bricks, and tried adding the sensors.

You may be to see why the objects linked do not load in the game of the first layer.

Good that you posted your file :slight_smile:
Please do turn on
Window->“Toggle System Console

start your game, then look at all the errors. (You can see the System Console Window in your Taskbar. It will be a 2nd window, perhaps "hidden behind your Blender Icon.)
It tells you

 File "lightcontrol1.py", line 3, in <module>
AttributeError: module 'bge' has no attribute 'lngic'

It means you have a spelling error and must change
cont = bge.lngic.getCurrentController()
to
cont = bge.logic.getCurrentController()

Then 3 or more errors in “knife.py”, “randomsmoke”, “randomfire” that

Python script error - object 'gun spawn', controller 'knife':
Traceback (most recent call last):
  File "knife.py", line 5, in <module>
NameError: name 'bge' is not defined

This means you have to add
import bge
at the top of each script

Then:

File "m24flare.py", line 23, in <module>
NameError: name 'scend' is not defined

in lines 23 and 27 correct the word
scend
to
scene

Then in "findplayer.py " and others

change
['cover']==o
to
if i['cover'] == 'safe':

And so on and so on.