Jump to content
Official BF Editor Forums

Some Script Help Anyone?


Cobra_SFX
 Share

Recommended Posts

Can anyone tell me why this doesnt do anything ingame? ...

import bf2
import host

def init():

	host.rcon_invoke('game.sayall "Scrippy Loaded"')
	host.registerHandler('ChatMessage', onChatMessage, 1)


def onChatMessage(playerid, text, channel, flags):
			if playerID == -1: 
					playerID = 255

			text = text.replace("*\xA71DEAD\xA70*", "")
			text = text.replace("HUD_TEXT_CHAT_SQUAD", "")
			text = text.replace("HUD_TEXT_CHAT_TEAM", "")
			text = text.replace("HUD_TEXT_CHAT_COMMANDER", "")
			#if text.find("turbo") ==0:
			if text[0:1] == "turbo":
					host.rcon_invoke("ObjectTemplate.activeSafe Engine JEEP_FAAV_Engine")
					host.rcon_invoke("ObjectTemplate.setTorque 600 ")
					host.rcon_invoke("ObjectTemplate.newCar2.maxRpm 8000 ")
					host.rcon_invoke('game.sayall "|ccc| Turbo Activated!|ccc|"')
					host.rcon_invoke('game.sayall "end of invoke!"')

I get no errors on load but also nothing ingame when i type turbo in the chat, no messages appear ingame, its like its not being loaded or is being ignored :/

Link to comment
Share on other sites

i think that the "if text[0:1] == "turbo"" thing doesnt work!

You should better replace the whole text.replace stuff with:

text = text[ len(text)-len("turbo") : ]

if text == "turbo": #host.rcon_invoke stuff

EDIT: Full code then:

import bf2
import host

def init():
   host.rcon_invoke('game.sayall "Scrippy Loaded"')
   host.registerHandler('ChatMessage', onChatMessage, 1)


def onChatMessage(playerid, text, channel, flags):
   if playerID == -1: playerID = 255

   text = text[ len(text)-len("turbo") : ]
   if text == "turbo":
       host.rcon_invoke("ObjectTemplate.activeSafe Engine JEEP_FAAV_Engine")
       host.rcon_invoke("ObjectTemplate.setTorque 600 ")
       host.rcon_invoke("ObjectTemplate.newCar2.maxRpm 8000 ")
       host.rcon_invoke('game.sayall "|ccc| Turbo Activated!|ccc|"')
       host.rcon_invoke('game.sayall "end of invoke!"')

Edited by Krauzi
Link to comment
Share on other sites

Not sure why it's not loading but...

if text[0:1] == "turbo":

should be

if text[:5] == "turbo":

dont get into habit of doing this that way! You better code universal (this will avoid many error sources) like I've done in my script (which is also a lot of faster then the whole replace stuff [because you only copy a array once in comparison to 4 time copy with the replace stuff]).

Link to comment
Share on other sites

Thanks for the help guys :)

I get a syntax error (invalid syntax) on this line Krausi ...

text = text[ len(text)-len("turbo") : ]

Ive tried changing the spacing n stuff but same error

Also tried that 5 in the other scrippy freeze, still not working that version, yeh i wasnt sure about that [0:1] i did try other methods but to no avail.

Link to comment
Share on other sites

Thanks for the help guys :)

I get a syntax error (invalid syntax) on this line Krausi ...

text = text[ len(text)-len("turbo") : ]

Ive tried changing the spacing n stuff but same error

Also tried that 5 in the other scrippy freeze, still not working that version, yeh i wasnt sure about that [0:1] i did try other methods but to no avail.

ups maybe there was a syntax change with the array operator within python 2.3 -> < 2.3.

Maybe try this one:

text = text[ ( len(text)-len("turbo") ) : ]

Link to comment
Share on other sites

Same error mate, would it make any difference if im using it in the BF2 demo?

Good idea BTW i like the idea of using an array as once it starts working i can add all the vehicles for those fun nights :)

Can i also use an array of clan members names in this way to say award ranks as they join the server? (serverside mod per session)

Edited by Cobra_SFX
Link to comment
Share on other sites

ok then they changed a lot between 2.3 and < 2.3.

Then maybe this works

strlen = len(text)-len("turbo")
text = text[ strlen : len(text) ]

Anyway there shouldnt be any difference between demo and final bf2 (python side only).

About your last question: I think you mean something like this:

Clan_Members = ["name1", "name2", "name3", "name4"]
def onPlayerSpawn( player, soldier ):
   if player.getName() in Clan_Members: #dunno weather this works because the CLAN tag could be in the name
       if not hasattr(player, "greet_sent"):
           sendrankstuff( player, rank, otherargs ) #i dont know the function for this atm
           player.greet_sent = True

something like that should work.

EDIT: I tested my script out and it seems to work on my BF2 client 1.5 (non demo):


import bf2
import host

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


def onChatMessage(playerid, text, channel, flags):
   if len(text) < len("turbo"):
       return

   text = text[ len(text)-len("turbo") : ]
   if text == "turbo":
       host.rcon_invoke("ObjectTemplate.activeSafe Engine JEEP_FAAV_Engine")
       host.rcon_invoke("ObjectTemplate.setTorque 600 ")
       host.rcon_invoke("ObjectTemplate.newCar2.maxRpm 8000 ")
       host.rcon_invoke('game.sayall "|ccc|Turbo Activated!|ccc|"')

Edited by Krauzi
Link to comment
Share on other sites

Update ...

I can get myself ranked ingame and it shows in the TAB screen, however no-one else sees this nor do they see stripes above my head ingame, reading the stats.py i found this line ...

success = host.pers_plrRequestStats(player.index, 1, "&info=rank")

and some other juicy code ...

value = host.pers_getStatsKeyVal("rank")
	if g_debug: print "Player",player.index,"Rank:",value
	player.score.rank = int(value)
	player.stats.rank = int(value)

Can i force the Rank avatar to show ingame above the player messing around with this or is it done somewhere different? This is for a serverside mod.

Any help appreciated,

Cobs

ps ... Thought you might wanna see a vid update :)

Edited by Cobra_SFX
Link to comment
Share on other sites

I got it sorted anyway Freeze, i knew the values, what was happening was they didnt show ... until another person turned up ingame and the round started (handy timing so other players can see you get ranked hehe), going to expand it now based on score etc as i tried a few weeks ago but the damn thing got confused somewhere and tracked players wrong. Things are looking up :)

Link to comment
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...
 Share

×
×
  • Create New...