示例#1
0
    def position_sp_distance(self):
        # vertical distance must be signed
        v = (Vector3(0, self.position_sp.y, 0) - Vector3(0, self.position.y, 0)).y

        h = Vector3.Distance(
            Vector3(self.position.x, 0, self.position.z),
            Vector3(self.position_sp.x, 0, self.position_sp.z))

        d = Vector3.Distance(self.position_sp, self.position)

        return Vector3(h, v, d)
示例#2
0
    def OnEntityDeath(self, victim, hitinfo):

        ini = hitinfo.Initiator if hitinfo else None
        att_ent = ini if ini and ini.ToPlayer() else None

        if victim and victim.ToPlayer():

            dmg = str(victim.lastDamage).upper()
            vic_sid = self.playerid(victim)
            vic_dic = self.db[vic_sid]

            if dmg == 'SUICIDE':

                vic_dic['SUICIDES'] += 1
                if vic_dic['DEATHS']:
                    vic_dic['SUICIDE RATIO'] = self.sfloat(float(vic_dic['SUICIDES']) / vic_dic['DEATHS'])

            elif att_ent and dmg in ('SLASH', 'BLUNT', 'STAB', 'BULLET', 'BITE'):

                att_sid = self.playerid(att_ent)
                att_dic = self.db[att_sid]

                if victim.IsSleeping():
                    att_dic['SLEEPERS'] += 1
                else:
                    att_dic['KILLS'] += 1

                if att_dic['DEATHS']:
                    att_dic['KDR'] = self.sfloat(float(att_dic['KILLS']) / att_dic['DEATHS'])

                d = float('%2f' % Vector3.Distance(victim.transform.position, att_ent.transform.position))
                if d > att_dic['RANGE']:
                    att_dic['RANGE'] = d

                self.db[att_sid].update(att_dic)

            vic_dic['DEATHS'] += 1
            if vic_dic['DEATHS']:
                vic_dic['KDR'] = self.sfloat(float(vic_dic['KILLS']) / vic_dic['DEATHS'])

            self.db[vic_sid].update(vic_dic)

        elif victim and 'animals' in str(victim) and att_ent:

            att_sid = self.playerid(att_ent)
            att_dic = self.db[att_sid]

            att_dic['ANIMALS'] += 1
            d = float('%.2f' % Vector3.Distance(victim.transform.position, att_ent.transform.position))
            if d > att_dic['RANGE']:
                att_dic['RANGE'] = d

            self.db[att_sid].update(att_dic)
示例#3
0
    def distance(self, p1, p2):

        return Vector3.Distance(p1, p2)
示例#4
0
    def OnEntityDeath(self, ent, info):
        '''Called when an entity dies'''

        # Death info
        ini = info.Initiator if info and info.Initiator else False

        # Is entity a Player?
        if ent.ToPlayer():

            vic_uid = self.playerid(ent)

            # Is Player not a NPC or has it data?
            if len(vic_uid
                   ) == 17 and vic_uid in self.db and self._IsPlayerInZone(
                       ent):

                # Victim info
                vic = self.db[vic_uid]
                dmg = str(ent.lastDamage)

                vic['deaths'] += 1

                if vic['deaths']:

                    vic['kdr'] = self._float(
                        float(vic['pvpkills']) / vic['deaths'])

                # Was it a suicide?
                if dmg == 'Suicide':

                    vic['suicides'] += 1

                    if vic['deaths']:

                        vic['sdr'] = self._float(
                            float(vic['suicides']) / vic['deaths'])

                self._RemovePlayerFromZones(ent)

        # Check for attacker
        if ini:

            # Is attacker a player and not the victim?
            if ini.ToPlayer() and ini != ent and self._IsPlayerInZone(ini):

                att_uid = self.playerid(ini)

                # Is Player not a NPC or has it data?
                if len(att_uid) == 17 and att_uid in self.db:

                    att = self.db[att_uid]

                    # Check if victim is a Player
                    if ent.ToPlayer() and self._IsPlayerInZone(ent):

                        # Victim UID
                        vic_uid = self.playerid(ent)

                        if len(vic_uid) == 17:

                            att['pvpkills'] += 1

                            if att['deaths']:

                                att['kdr'] = self._float(
                                    float(att['pvpkills']) / att['deaths'])

                            # Is victim sleeping?
                            if ent.IsSleeping():

                                att['sleepers'] += 1

                            # Check for distance
                            dis = Vector3.Distance(ini.transform.position,
                                                   ent.transform.position)

                            if dis > att['pvpdistance']:

                                att['pvpdistance'] = dis

                        # Else is an Human NPC
                        else:

                            att['npckills'] += 1

                        self._RemovePlayerFromZones(ent)

                    # Is victim an Animal?
                    if 'animal' in str(ent):

                        att['animals'] += 1

                        # Check for distance
                        dis = Vector3.Distance(ini.transform.position,
                                               ent.transform.position)

                        if dis > att['pvedistance']:

                            att['pvedistance'] = dis

                    # Is victim a Barrel?
                    if 'barrel' in str(ent):

                        att['barrels'] += 1

                    if 'autoturret' in str(ent):

                        att['turrets'] += 1

                    self._RemovePlayerFromZones(ini)

        # Is victim an Helicopter?
        if '/patrolhelicopter.prefab' in str(ent) and str(
                ent) in self.helis_cache:

            uid = self.helis_cache[str(ent)]

            if len(uid) == 17 and uid in self.db:

                self.db[uid]['helis'] += 1

            # De-cache helicopter
            del self.helis_cache[str(ent)]