Cobra_SFX Posted July 2, 2010 Report Share Posted July 2, 2010 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 :/ Quote Link to comment Share on other sites More sharing options...
Krauzi Posted July 3, 2010 Report Share Posted July 3, 2010 (edited) 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 July 3, 2010 by Krauzi Quote Link to comment Share on other sites More sharing options...
Freeze Posted July 3, 2010 Report Share Posted July 3, 2010 (edited) Not sure why it's not loading but... if text[0:1] == "turbo": should be if text[:5] == "turbo": Edited July 3, 2010 by Freeze Quote Link to comment Share on other sites More sharing options...
Krauzi Posted July 3, 2010 Report Share Posted July 3, 2010 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]). Quote Link to comment Share on other sites More sharing options...
Cobra_SFX Posted July 3, 2010 Author Report Share Posted July 3, 2010 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. Quote Link to comment Share on other sites More sharing options...
Krauzi Posted July 3, 2010 Report Share Posted July 3, 2010 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") ) : ] Quote Link to comment Share on other sites More sharing options...
Cobra_SFX Posted July 3, 2010 Author Report Share Posted July 3, 2010 (edited) 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 July 4, 2010 by Cobra_SFX Quote Link to comment Share on other sites More sharing options...
Krauzi Posted July 4, 2010 Report Share Posted July 4, 2010 (edited) 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 July 4, 2010 by Krauzi Quote Link to comment Share on other sites More sharing options...
Cobra_SFX Posted July 4, 2010 Author Report Share Posted July 4, 2010 Excellent stuff Krauzi, just tried it and flying around the map at great speed Thanks for all your help, ill try the Clan ID/Ranking one now, i know the codes for the ranks etc Quote Link to comment Share on other sites More sharing options...
Cobra_SFX Posted July 4, 2010 Author Report Share Posted July 4, 2010 (edited) 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 July 5, 2010 by Cobra_SFX Quote Link to comment Share on other sites More sharing options...
Freeze Posted July 5, 2010 Report Share Posted July 5, 2010 For in-game ranking... bf2.gameLogic.sendRankEvent(playerObject, value, 0) Where playerObject is the bf2.PlayerManager(playerid) object and value is from 0-21 (you can use other values but they crash at one point). Quote Link to comment Share on other sites More sharing options...
Cobra_SFX Posted July 6, 2010 Author Report Share Posted July 6, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.