I assume your using a ray sensor to simulate bullet fire
Let me try to help you out:
#This is one of my old bullet fire scripts.
#I'll try to comment things as much as I can for you.
import GameLogic as G
cont = G.getCurrentController()
own = cont.getOwner() #getOwner, not sensor.
#When you assign sensors by name like below, you don't put a "[0]"-
#after that. That is done when you call in bulk: "cont.getSensors()[0]"-
#which would pick the first sensor from the top assigned to that object.
#Same goes with actuators.
#_=Sensors=_
leftclick = cont.getSensor("LeftClick")
ray = cont.getSensor("Ray")
#Message Actuator that will send a message to the hit object.
#That object would have a health prop and a logic brick setup-
#to decrease the healthprop by (<i>in your case</i>) 30 points, every time
#the message sensor (<i>on the hit object</i>) would recieve a message from
#the kill actuator (<i>which is attached to your player/weapon</i>)
#_=Actuators=_
kill = cont.getActuator("Kill")
#Get name of the hit object
obhit = ray.getHitObject().getName()
#Forget "40 frames", measure by time. You can do that by adding a-
#time prop, and you do that by going into the logic brick button window
#and hitting that long ADD property button. Set the property type to "time"
#and name it "time" no quotes.
#Then you call it like this: "own.time"
#Like a clock, it will start counting up seconds as soon as game starts.
if leftclick.isPositive() and ray.isPositive():
#Set a time condition for 2 seconds (<i>or whatever</i>) from fire to next fire:
if own.time > 2:
kill.setToPropName(obhit)#Set message actuator to message this OB
G.addActiveActuator(kill,1)#Send message
#reset timer to 0, so that the above statement will be false for 2sec
own.time = 0
else:
G.addActiveActuator(kill,0)#Dont's send message/shut down act
I didn’t test this particular timed version, but it should work for you. Play around with it, and if you have any questions don’t be afraid to ask.
PS: I’m glad you decided to take my suggestions. Learning the BGE PY API will help you out plenty, I guarantee it.
You probably don’t have the right logic brick setup (It’s a different setup all together). I gave you my script with comments so that you can implement parts of it in your script (and so you could understand and remove the parts that don’t have to be there in the first place like the “(“sensorname”)[0]”. You don’t do that when you call sensors by name, the [0] is not necessary).
Here try this:
#Your script structure this time. Same concepts.
#Add the time property like I described in my script
cont = GameLogic.getCurrentController()
own = cont.getOwner()#own should not be a sensor as you had before
Ray = cont.getSensors("Ray")#No need for [0]
mouse = cont.getSensors("mouse")#Or [1], because you named your logic
#bricks, Right?
#Instead of "shoot =" just write:
if mouse.isPositive() and Ray.isPositive():
#Same thing with time as in my script:
if own.time > 2:
Obj = Ray.getHitObject()
Obj.Health-= 30
#Same reset
own.time = 0
That should work in your setup.
PS: You can edit your posts, by using the “edit” option on the bottom right corner of the post.