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

Need Help With This Objectspawner Script!

Recommended Posts

Anyone found the misstake?

import host
import bf2

def init():
host.registerHandler('ChatMessage', onChatMessage)

def onChatMessage(playerID, text, channel, flags):
player = bf2.playerManager.getPlayerByIndex(playerID)
playerpos = player.getDefaultVehicle().getPosition()

if text.find('/') == 0:
	command, objtype, obj = text.split(' ')

	if command.split('/')[1] == 'request':
		playerData = [player.getTeam(), player.getName()]
		request(objtype, obj, playerpos, playerData)


def request(objtype, obj, pos, playerData):

playerTeam = playerData[0]

if objtype == 'kit':
		obj = obj.split(':')
		if obj[0] == 'Sniper' or obj[0] == 'sniper' or obj[0] == 'SNIPER':
			if obj[1] == '1':
				print playerData[1], "is requesting the Sniper kit # 1!"
				kitData = ['Kit_Sniper_1', 'Sniper_1_US', 'Sniper_1_MEC']
				spawnKit(kitData, pos, playerTeam)

			elif obj[1] == '2':
				print playerData[1], "is requesting the Sniper kit # 2!"
				kitData = ['Kit_Sniper_2', 'Sniper_2_US', 'Sniper_2_MEC']
				spawnKit(kitData, pos, playerTeam)

			else:
				print "Requesting Sniper kit # 3!"

		elif obj[0] == 'Medic' or obj[0] == 'medic' or obj[0] == 'MEDIC':
			if obj[1] == '1':
				print playerData[1], "is requesting the Medic kit # 1!"
				kitData = ['Kit_Medic_1', 'Medic_1_US', 'Medic_1_MEC']
				spawnKit(kitData, pos, playerTeam)
			elif obj[1] == '2':
				print playerData[1], "is requesting the Medic kit # 2!"
				kitData = ['Kit_Medic_2', 'Medic_2_US', 'Medic_2_MEC']
				spawnKit(kitData, pos, playerTeam)
			else:
				print "Requesting Medic kit # 3!"

		elif obj[0] == 'Assault' or obj[0] == 'assault' or obj[0] == 'ASSAULT':
			if obj[1] == '1':
				print playerData[1], "is requesting the Soldier kit # 1!"
				kitData = ['Kit_Assault_1', 'Assault_1_US', 'Assault_1_MEC']
				spawnKit(kitData, pos, playerTeam)
			elif obj[1] == '2':
				print playerData[1], "is requesting the Soldier kit # 2!"
				kitData = ['Kit_Assault_2', 'Assault_2_US', 'Assault_2_MEC']
				spawnKit(kitData, pos, playerTeam)
			else:
				print "Requesting Soldier kit # 3!"

		elif obj[0] == 'Support' or obj[0] == 'support' or obj[0] == 'SUPPORT':
			if obj[1] == '1':
				print playerData[1], "is requesting the Support kit # 1!"
				kitData = ['Kit_Support_1', 'Support_1_US', 'Support_1_MEC']
				spawnKit(kitData, pos, playerTeam)
			elif obj[1] == '2':
				print playerData[1], "is requesting the Support kit # 2!"
				kitData = ['Kit_Support_2', 'Support_2_US', 'Support_2_MEC']
				spawnKit(kitData, pos, playerTeam)
			else:
				print "Requesting Support kit # 3!"


def spawnKit(kitData, pos, Team = 2):

print "Spawning kit:", kitData[0]

host.rcon_invoke("ObjectTemplate.create ObjectSpawner spawn_") + kitData[0]
host.rcon_invoke("ObjectTemplate.activeSafe ObjectSpawner (EDIT:)spawn_") + kitData[0]
host.rcon_invoke("ObjectTemplate.isNotSaveable 1")
host.rcon_invoke("ObjectTemplate.hasMobilePhysics 0")
host.rcon_invoke("ObjectTemplate.setObjectTemplate 2 ") + kitData[1]
host.rcon_invoke("ObjectTemplate.setObjectTemplate 1 ") + kitData[2]

host.rcon_invoke("Object.create spawn_") + kitData[0]
host.rcon_invoke("Object.absolutePosition " + str(pos[0]) + "/" + str(pos[1]) + "/" + str(pos[2]))
host.rcon_invoke("Object.rotation 0.000/0.000/0.000")
host.rcon_invoke("Object.team ") + Team
host.rcon_invoke("Object.delete")

EDIT: If i manually enter:

	host.rcon_invoke("ObjectTemplate.create ObjectSpawner Kit_Sniper_1")
host.rcon_invoke("ObjectTemplate.activeSafe ObjectSpawner Kit_Sniper_1")
host.rcon_invoke("ObjectTemplate.isNotSaveable 1")
host.rcon_invoke("ObjectTemplate.hasMobilePhysics 0")
host.rcon_invoke("ObjectTemplate.setObjectTemplate 2 Sniper_1_US")
host.rcon_invoke("ObjectTemplate.setObjectTemplate 1 Sniper_1_MEC")

host.rcon_invoke("Object.create Kit_Sniper_1")
host.rcon_invoke("Object.absolutePosition " + str(pos[0]) + "/" + str(pos[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")

, it works. But i dont find any misstakes in the displaced part of the original script.

Edited by Krauzi

Share this post


Link to post
Share on other sites

def spawnKit(kitData, pos, Team = 2):

print "Spawning kit:", kitData[0]

host.rcon_invoke("ObjectTemplate.create ObjectSpawner spawn_" + kitData[0])
host.rcon_invoke("ObjectTemplate.activeSafe ObjectSpawner spawn_" + kitData[0])
host.rcon_invoke("ObjectTemplate.isNotSaveable 1")
host.rcon_invoke("ObjectTemplate.hasMobilePhysics 0")
host.rcon_invoke("ObjectTemplate.setObjectTemplate 2 " + kitData[1])
host.rcon_invoke("ObjectTemplate.setObjectTemplate 1 " + kitData[2])

host.rcon_invoke("Object.create spawn_" + kitData[0])
host.rcon_invoke("Object.absolutePosition " + str(pos[0]) + "/" + str(pos[1]) + "/" + str(pos[2]))
host.rcon_invoke("Object.rotation 0.000/0.000/0.000")
host.rcon_invoke("Object.team " + Team)
host.rcon_invoke("Object.delete")

? ;)

Edited by ScoutStrike

Share this post


Link to post
Share on other sites
def spawnKit(kitData, pos, Team = 2):

print "Spawning kit:", kitData[0]

host.rcon_invoke("ObjectTemplate.create ObjectSpawner spawn_" + kitData[0])
host.rcon_invoke("ObjectTemplate.activeSafe ObjectSpawner spawn_" + kitData[0])
host.rcon_invoke("ObjectTemplate.isNotSaveable 1")
host.rcon_invoke("ObjectTemplate.hasMobilePhysics 0")
host.rcon_invoke("ObjectTemplate.setObjectTemplate 2 " + kitData[1])
host.rcon_invoke("ObjectTemplate.setObjectTemplate 1 " + kitData[2])

host.rcon_invoke("Object.create spawn_" + kitData[0])
host.rcon_invoke("Object.absolutePosition " + str(pos[0]) + "/" + str(pos[1]) + "/" + str(pos[2]))
host.rcon_invoke("Object.rotation 0.000/0.000/0.000")
host.rcon_invoke("Object.team " + Team)
host.rcon_invoke("Object.delete")

? ;)

yesyes, sry i forgot to edit the first post. I've allrdy fixed that. But it didnt work....

Edited by Krauzi

Share this post


Link to post
Share on other sites

The debugger is your friend and puts errors encountered in python scripts into its server log file. Probably you should put some print statements into the right spot for further debugging.

Share this post


Link to post
Share on other sites

The debugger is your friend and puts errors encountered in python scripts into its server log file. Probably you should put some print statements into the right spot for further debugging.

alrdy done.

i used a print"0" - print "10" between the lines of the host.rcon_invoke("...") to detect my error. But all prints are wirten into the log file.

EDIT: I got something very funny: I get a MEC flag instead of the kit spawned to my position!

UHAAAAAAAAAAAAAAAA!

I could cry!

Why the hell is it working, if i enter the kits manually?

But if i add this:

	print "ObjectTemplate.create ObjectSpawner", kitData[0]
print "ObjectTemplate.activeSafe ObjectSpawner", kitData[0]
print "ObjectTemplate.isNotSaveable 1"
print "ObjectTemplate.hasMobilePhysics 0"
print "ObjectTemplate.setObjectTemplate 1", kitData[1]
print "ObjectTemplate.setObjectTemplate 2", kitData[2]

print "Object.create", kitData[0]
print "Object.absolutePosition", str(pos[0]), "/", str(pos[1]), "/", str(pos[2])
print "Object.rotation 0.000/0.000/0.000"
print "Object.team", Team
print "Object.delete"

i got exactly the same as i entered manually!

Edited by Krauzi

Share this post


Link to post
Share on other sites

Use Exception Printer def to know the prob and exception ingame.

btw, what's yo' prob?

Oh, you forgot to make sure playerId is 255 ;)

Edited by izrabf2

Share this post


Link to post
Share on other sites
Use Exception Printer def to know the prob and exception ingame.

btw, what's yo' prob?

Oh, you forgot to make sure playerId is 255 ;)

Hä? What shall i do?

playerId is not my problem. The problem is:

If i manually enter the kitData in the host.rcon... it works. If i use the array it doesnt.

So: The problem is the ARRAY!

EDIT: I get a ctd, as if the kit isnt loaded in the map. But ive added e.g.

ObjectTemplate.create ObjectSpawner Kit_Spawn_Sniper_1

ObjectTemplate.activeSafe ObjectSpawner Kit_Spawn_Sniper_1

ObjectTemplate.isNotSaveable 1

ObjectTemplate.hasMobilePhysics 0

ObjectTemplate.setObjectTemplate 2 Sniper_1_US

ObjectTemplate.setObjectTemplate 1 Sniper_1_MEC

into the GamePlayObjects.con for the map.

EDIT2: So after a few test, i found out, that host.rcon_invoke("..." + Team) is NOT working.

Edited by Krauzi

Share this post


Link to post
Share on other sites
host.rcon_invoke("Object.team " + Team)
yes, this won't work. look:

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> some_number = 5
>>> some_string = "hi"
>>> some_string + some_number
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects

instead, try:

>>> some_string + str(some_number)

in other words:

host.rcon_invoke("Object.team " + str(Team))

Edited by [FH]ctz

Share this post


Link to post
Share on other sites

Lol. of course. Now i see my mistake. Dont know why i forgot the str....

thx for help.

Edited by Krauzi

Share this post


Link to post
Share on other sites
TypeError: cannot concatenate 'str' and 'int' objects

Pretty self-explaining error message :P

host.rcon_invoke accepts only strings as argument so you'll need to convert any numbers (int's, floats, doubles ) to a string before feeding rcon_invoke with them.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...