You are here: Big Brother Bot ForumCommunity DevelopersPlugin Developershelp with developping plugins for BF3
Pages: [1]   Go Down
  Print  
Author Topic: help with developping plugins for BF3  (Read 576 times) Bookmark and Share
Beta Testers
*
OS: Windows
Type: Owner dedicated server(s)
Gameservers: BF3
Posts: 134
Offline Offline
eliteclangaming.com
WWW
« on: November 18, 2011, 02:35:37 PM »

Okay, I am still running into some confusion. I have tried making a different plugin to do the same thing as before with vehicles, I understand that I can just use a config to do this with poweradmin but I am trying to learn more about developing for B3 and I do that best by just getting my hands dirty so I would rather make it work. Anyway, I am still having difficulty getting the self.console.write function to actually do anything useful. Has something changed in the way it works? I had a plugin that I wrote for Call of Duty 1 back in the day that used it just fine. Here is my code and the log from its use. It appears to me that B3 is just saying the commands in game as opposed to actually executing the changes. Any insight would be very much so appreciated. Our server is running infantry only most of the time however we are also using a config to allow vehicles to be turned on mid game. Since people are forgetful, admins sometimes forget to turn off the vehicles before they leave and vehicle exploits get out of hand without anyone to monitor it. Thus I decided to write this plugin to turn off vehicles at the end of each map to counter that problem.


Here is my code thus far:

Code: python
__version__ = '1.0.1'
__author__  = 'Wright'

import b3, thread, time, string
import b3
import b3.events
import b3.plugin

#--------------------------------------------------------------------------------------------------

class VehiclePlugin(b3.plugin.Plugin):
requiresConfigFile = False

def onStartup(self):
self.registerEvent(b3.events.EVT_GAME_ROUND_END)
self.debug('Ensuring vehicles get disabled after use...')

def onEvent(self, event):
if event.type == b3.events.EVT_GAME_ROUND_END:
s = self.abstractParser
self.console.write(('vars.vehicleSpawnAllowed 0'))
self.debug('Vehicles shut off.')

However when a round ends, it doesn't change the server variable. Vehicles remain on. Here is the log entry for it. I don't understand why nothing is getting changed.

Code: log
110914 13:19:07 VERBOSE 'Queueing event Game Round End 2'
110914 13:19:07 VERBOSE "Queueing event round player scores PlayerInfoBlock[{'squadId': '1', 'name': 'Elite-Kal', 'kills': '0', 'deaths': '2', 'teamId': '2', 'score': '11550', 'guid': 'EA_FB51EF2486F684ED22FC54BA60243B73'}]"
110914 13:19:07 VERBOSE 'Parsing Event: Game Round End: VehiclePlugin'
110914 13:19:07 DEBUG 'VehiclePlugin: Vehicles shut off.'
110914 13:19:07 DEBUG "getCommand: ('admin.say', '[b3] vars.vehicleSpawnAllowed 0', 'all')"
110914 13:19:07 VERBOSE u"RCON :\t ('admin.say', '[b3] vars.vehicleSpawnAllowed 0', 'all')"
110914 13:19:07 VERBOSE 'Parsing Event: round player scores: Poweradminbf3Plugin'
110914 13:19:08 CONSOLE "['player.onChat', 'Server', '[b3] vars.vehicleSpawnAllowed 0']"
110914 13:19:08 VERBOSE u'RCON response:\t []'
Logged

xfire: blitzwright

Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3478
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #1 on: November 18, 2011, 03:09:43 PM »

due to how the commands are sent to Frostbite engine, the self.console.write method works differently for games based on Frostbite engines.

usually you would send a rcon command (let say "/rcon say hello") with : self.console.write("say hello")

with Frostbite, if you want to send the 'vars.vehicleSpawnAllowed 0' command, you have to separate the command from its arguments. In this case, the command is "'vars.vehicleSpawnAllowed" and there is 1 parameter : "0".
To send this to the Frosbite engine, you use pile up the command and its parameters into a tuple or list python structure and you pass that structure to the self.console.write.

I.E.:

self.console.(['vars.vehicleSpawnAllowed', '0'])  # here we use a python list
or
self.console.(('vars.vehicleSpawnAllowed', '0'))  # and here a python tuple

What can be confusing is the way you write a tuple of one element in python.
Let say I want to get a tuple of the single element "foo", if I write
Code: python
myvar = ("foo")
type(myvar) will reply "str"

one correct way to make a tuple of one element is :
Code: python
myvar = tuple("foo")
and type(myvar) is 'tuple' as expected.

another way to get the same tuple is :
Code: python
myvar = ("foo",)
notice the comma just before closing the tuple

to sum up :
Code: python
assert type(("foo",)) == tuple
assert type(tuple("foo")) == tuple
assert type(("foo")) != tuple

I suggest you play a bit with tuple with dreampie

in your code :
Code:
self.console.write(('vars.vehicleSpawnAllowed 0'))
should be
Code:
self.console.write(('vars.vehicleSpawnAllowed', 0))

« Last Edit: November 18, 2011, 04:13:19 PM by Courgette » Logged

Beta Testers
*
OS: Windows
Type: Owner dedicated server(s)
Gameservers: BF3
Posts: 134
Offline Offline
eliteclangaming.com
WWW
« Reply #2 on: November 18, 2011, 03:35:15 PM »

Thanks for your reply, this helps me a lot. I was quite frustrated because B3 was simply refusing to do what I wanted it to do. Now I understand why.

Is it a better practice to use the the python list or the tuple?

Sorry I posted that topic in the wrong location, I will be sure to place it here for development questions in the future.
Logged

xfire: blitzwright
Senior Dev.
*
OS: Linux
Type: Home user
Posts: 3478
Offline Offline
WWW
Support Specialty: B3-Core, UrT/SmG/BFBC2 parsers, Plugin development
« Reply #3 on: November 18, 2011, 04:11:23 PM »

Is it a better practice to use the the python list or the tuple?
My understanding is that tuples are faster than lists because they are immutable objects (hence are read-only object once created)

In that particular case it does not make any difference because we're not using thousands of them per second. I should probably have used lists to avoid confusion with plugin dev and the "strange" syntax for writing a single item tuple.
Logged

Beta Testers
*
OS: Windows
Type: Owner dedicated server(s)
Gameservers: BF3
Posts: 134
Offline Offline
eliteclangaming.com
WWW
« Reply #4 on: November 18, 2011, 09:31:25 PM »

Thanks for the explanation, I am sure I will have more questions in the future as I continue to refine my skills.
Logged

xfire: blitzwright
Tags:
Pages: [1]   Go Up
  Print  
 
Jump to:  


Rate this page +1 at Google Search


SimplePortal 2.3.1 © 2008-2009, SimplePortal