Jump to content
Official BF Editor Forums
Sign in to follow this  
pmaxie4444

Need Help To Kitsystem

Recommended Posts

Hi here! I've got a problem and I don't know how to solve it.

here my code of my requestkit system on flag :

__________________________________________________________________________________________________________

import host, bf2, math

from bf2.stats.constants import *

kitList = [

'requestkit1',

'requestkit2',

'requestkit3',

'requestkit4',

'requestkit5',

'requestkit6',

'requestkit7',

'requestkit8',

]

for i in range(len(kitList)):

kitList = kitList.lower()

def init():

host.registerHandler('RemoteCommand', ComroseCmd, 1)

host.rcon_invoke('sv.numPlayersNeededToStart 1')

host.rcon_invoke('sv.serverName "Battlefield 2 Reloaded Server"')

host.rcon_invoke('sv.SpawnTime 15')

host.rcon_invoke('sv.ManDownTime 15')

def ComroseCmd(playerID, cmd):

if playerID == -1:

playerID = 255

player = bf2.playerManager.getPlayerByIndex(playerID)

cmd = cmd.split(' ')

if cmd[0] != 'spawn' and len(cmd) != '2':

return

else:

if cmd[1].lower() in kitList:

#print player.getVehicle().templateName

spawnKit(cmd[1].lower(), player)

pass

else:

pass

pass

return

def spawnKit(kit, player):

controlPoints = bf2.objectManager.getObjectsOfType('dice.hfe.world.ObjectTemplate.ControlPoint')

for cp in controlPoints:

if player.getTeam() == cp.cp_getParam("team"):

if getVectorDistance(player.getDefaultVehicle().getPosition(), cp.getPosition()) <= 100:

break

else:

pass

else:

pass

else:

return

pos = player.getDefaultVehicle().getPosition()

team = bf2.gameLogic.getTeamName(player.getTeam())

kitName = team + "_" + kit + "_PU"

host.rcon_invoke("ObjectTemplate.create ObjectSpawner spawn_" + kit)

host.rcon_invoke("ObjectTemplate.activeSafe ObjectSpawner spawn_" + kit)

host.rcon_invoke("ObjectTemplate.isNotSaveable 1")

host.rcon_invoke("ObjectTemplate.hasMobilePhysics 0")

host.rcon_invoke("ObjectTemplate.setObjectTemplate 2 " + kitName)

host.rcon_invoke("Object.create spawn_" + kit)

host.rcon_invoke("Object.absolutePosition " + str(pos[0]) + "/" + str(pos[1]-1) + "/" + str(pos[2]))

host.rcon_invoke("Object.rotation 0.000/0.000/0.000")

host.rcon_invoke("Object.team 2")

host.rcon_invoke("Object.delete")

def getVectorDistance(pos1, pos2):

diffVec = [math.fabs(pos1[0] - pos2[0]), math.fabs(pos1[1] - pos2[1]), math.fabs(pos1[2] - pos2[2])]

return math.sqrt(diffVec[0] * diffVec[0] + diffVec[1] * diffVec[1] + diffVec[2] * diffVec[2])

__________________________________________________________________________________________________________

This code work perfectly, but I want to add another system. What i want to do is :

kitName = team + "_" + thekitwithwhatyouspawnedwhenyouwheredie + "_" + kit + "_PU"

By this way, if I spawn in medic after dieing, I want to be able to request only custom medit kits.

Same if I spawn with Support class, I want to request only Support kits.

I know that i need to add 7*7 new kit by army, but that what I want :)

Can anyone help me?

PS : sorry for bad english =S

Share this post


Link to post
Share on other sites

You can get the current kit name with "player.getKit().templateName". The player might have picked up another kit after spawn though. If you want to take that into account too, you could go for onPlayerSpawn directly, but it will be necessary to add some kind of timer to get the kit name shortly after spawning because asking for the kit right on spawn doesn't work correctly. After that the kit name can be saved as an attribute of the player object, e.g. "player.kitname=player.getKit().templateName" which can be accessed from anywhere.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×