Getting a name from a model/ray collision (shooting a gun)

Hey, I was retrying to get my “gun” to work and found that my old code didn’t work for my new network. Me being dum, I deleted that part of the code and retry to setup a new one. This seems to not do what I want fully, but not sure how to go about it really.

I prints the nodepath but I need the holder for it if theres a way?
example:
self.userlist[self.data[0]] = loader.loadModel(“towns/cube”)
I need to get the self.userlist[self.data[0]] name for it.

          self.mpos=base.mouseWatcherNode.getMouse()
          self.pickerRay.setFromLens(base.camNode, self.mpos.getX(), self.mpos.getY())
          base.cTrav.traverse(render) 
          if base.handler.getNumEntries() > 0:
            base.handler.sortEntries()
            self.pickedObj=base.handler.getEntry(0).getIntoNodePath()
            if not self.pickedObj.isEmpty():
                #self.send = ("Shoot" + " " + self.pickedObj)
                print self.pickedObj #Need the name of the model/handle for the model so I can compare it to a list of online users.

If I got you lost on what I was talking about. I just need to know who i’m clicking on “bob” or “bill” and not that they are both cubes.

Ok I got the top to work, but now when I “shoot” my game seems to crash and i dont understand why 100% o.o; long as I dont shoot it works its werid…

Error code


C:\game>cd c:\game\

C:\game>ppython mradr.py
DirectStart: Starting the game.
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
1
2
3
4
5
6
Traceback (most recent call last):
  File "mradr.py", line 311, in sendfor
    self.client.send(self.Pos)
TypeError: 'str' object is not callable
:task(error): Exception occurred in PythonTask sendforTask
Traceback (most recent call last):
  File "mradr.py", line 527, in <module>
    run()
  File "C:\Panda3D-1.6.2\direct\showbase\ShowBase.py", line 2423, in run
    self.taskMgr.run()
  File "C:\Panda3D-1.6.2\direct\task\TaskNew.py", line 471, in run
    self.step()
  File "C:\Panda3D-1.6.2\direct\task\TaskNew.py", line 429, in step
    self.mgr.poll()
  File "mradr.py", line 311, in sendfor
    self.client.send(self.Pos)
TypeError: 'str' object is not callable

Chunks of the code that work togather to work.

    def sendfor(self, task):
      if base.camera.getPos() != self.tempmovexyz or base.camera.getHpr() != self.tempmovehpr:
        self.youX = base.camera.getX()
        self.youY = base.camera.getY()
        self.youZ = base.camera.getZ()
        self.youH = base.camera.getH()
        self.youP = base.camera.getP()
        self.youR = base.camera.getR()
        self.Pos = ("MyPos" + " " + str(self.youX)  + " " + str(self.youY)  + " " + str(self.youZ) +  " " + str(self.youH) + " " + str(self.youP) + " " + str(self.youR) + "\n")
        self.client.send(self.Pos)
        self.tempmovexyz = base.camera.getPos()
        self.tempmovehpr = base.camera.getHpr()
      return Task.again



           try:
              self.data = self.read.strip().split(" ")[:8]
              self.userlist[self.data[0]].posInterval(.543,Point3(float(self.data[2]),float(self.data[3]),float(self.data[4])),fluid=1).start()
              self.userlist[self.data[0]].hprInterval(.300,Point3(float(self.data[5]),float(self.data[6]),float(self.data[7])),fluid=1).start()
            except:
              return
          elif "Shoot" == self.data[1] and self.data[2] == self.Name.get():
            self.LogonScreenBackGround = loader.loadSfx("Music/Sounds/changer.wav")
            self.LogonScreenBackGround.play()
          elif "Chat" == self.data[1]:
            self.readtext = TextNode('read') #Setup the node
            self.readtext.setText(self.read) #Set the data into the node
            self.readtextNodePath = aspect2d.attachNewNode(self.readtext) #convert it
            self.readtextNodePath.setScale(0.06) #size the text up
            self.myScrolledList.addItem(self.readtextNodePath)



      if (self.keyMap["shoot"]!=0):
          if self.CanShoot == False:
            if task.time >= self.ShootTime + 1:
              self.ShootTime = task.time
              self.CanShoot = True
          else:
            self.CanShoot = False
            self.mpos=base.mouseWatcherNode.getMouse()
            self.pickerRay.setFromLens(base.camNode, self.mpos.getX(), self.mpos.getY())
            base.cTrav.traverse(render) 
            if base.handler.getNumEntries() > 0:
              base.handler.sortEntries()
              self.pickedObj=base.handler.getEntry(0).getIntoNodePath()
              if not self.pickedObj.isEmpty():
                if self.pickedObj.getParent().getParent().getName() in self.userlist:
                  self.LogonScreenBackGround = loader.loadSfx("Music/Sounds/click.wav")
                  self.LogonScreenBackGround.play()
                  self.client.send = ("Shoot" + " " + str(self.pickedObj.getParent().getParent().getName()))

This looks like a typo:

self.client.send = ("Shoot" + " " + str(self.pickedObj.getParent().getParent().getName())) 

shouldn’t that be:

self.client.send("Shoot" + " " + str(self.pickedObj.getParent().getParent().getName())) 

Haha your right, ty. Just got over from being sick with strep throat so i’m not in the right “mind” yet still. :slight_smile: