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

King of Camelot and his host.rcon_invoke("object.create

Recommended Posts

King of Camelot is claiming we can creat stuff like vehicles and control points in game...

Now I have tested this and it works on a local server but not on dedicated server....and I would expect that it would not work. But low and behold it spawned a truck, however, I could not see it.

Yet I believe it spawned it server side since its collision was there. Now if this method was to work on a dedicated server it would open up new possibilities for python modding.

So I am trying to enter the new truck in the servers object list now and will see if this works.

If King of Camelot has any suggestions on how host.rcon_invoke("object.create "... can work on dedicated servers let us know!

Ill have more on this when I finish playing with it.....

Share this post


Link to post
Share on other sites

Hmm, I'm guilty of not testing things. I had assumed it would work on dedicated servers since it worked fine on a local server, and the code was only dealing with creating objects, which are server side (code-wise). I'm going to look into this more, hopefully it can work with dedicated servers.

Sorry if I'm mistaken. :oops:

Share this post


Link to post
Share on other sites

Ha, I knew I wasn't crazy after all the time I spent working on this. I had always thought that gameLogic.createObject did the same thing as object.create, just in a different way.

It turns out that gameLogic.createObject does WORK on dedicated server. So, the following code should be used instead of object.create:

host.rcon_invoke("gameLogic.createObject VehicleName")

This code will ONLY work if that vehicle template has been loaded on that map already. For example, USJEP_HMMWV works fine on Strike at Karkand, while JEEP_FAAV will crash the server since it is not loaded on Strike at Karkand.

One odd thing about gameLogic.createObject is that it spawns the object where your crosshairs are pointed, and I can't get it to spawn elsewhere. I haven't had other people in the server to test it with me, but I assume its spawning at my crosshairs because I am the active player. The active player can be found by doing:

host.rcon_invoke("player.active")

On Mach10's concerns about the flags not having network information attached, Mach10 was right, attempting to spawn flag_us would cause nothing to show up in-game. However, there is a fix. :wink: We can just add the network information manually, with the following python code:

host.rcon_invoke("objecttemplate.active flag_us")



host.rcon_invoke("objecttemplate.networkableInfo BasicInfo")

I did the preceding code and then spawned flag_us, and lo and behold, the flag showed up! No modifications to .CON files needed!

I really think there is a lot of potential here, and we need more people playing around with this. Hopefully we will learn more and overcome the quirks as we play around! Well, I'm done for the night. All work and no play makes me a dull boy. :wink: I'm off to play BF2, after all, its no fun coding for a game you never get to play!

I expect to see responses here when I check back tomorrow, as I hope everyone gets a chance to play around with this!

This might make using these kind of commands a lot easier:

def onChatMessage(playerId, text, channel, flags):



if text.find('list') == 0:



 first = text.replace('list ', '')



 print host.rcon_invoke('Console.getactivemethods ' + str(first))



else:



 print host.rcon_invoke(str(text))

I use that code so that I can type commands such as gameLogic.createObject just like I would in console. Typing "list gameLogic" will give the same result as typing gameLogic in the console and hitting tab twice. All commands must be typed in Say All, and all output is sent to the python log (I use the Python Log found here: http://codeflow.org/files/bf2pythonlog.zip to view the results in real time). Happy python coding!

Share this post


Link to post
Share on other sites

heres a fun little test just tried on a quick localserver (connect to dedi on your own box)

  # player events



 host.registerHandler('PlayerDeath', onPlayerDeathCQ)



 host.registerHandler('PlayerKilled', onPlayerKilledCQ)



 host.registerHandler('PlayerRevived', onPlayerRevived)



 host.registerHandler('PlayerSpawn', onPlayerSpawn)



 host.registerHandler('EnterVehicle', onEnterVehicle)



 host.registerHandler('ExitVehicle', onExitVehicle)



 host.rcon_invoke("objecttemplate.active kni_knife")



 host.rcon_invoke("ObjectTemplate.projectileTemplate hydra_70") 



 host.rcon_invoke("ObjectTemplate.projectileTemplate ObjectTemplate.velocity 1000")

findings:

No visual projectile (probably just missed a var there. They have reorgainised alot, after all).

Tabbed out to go woot after blowing my own leg off and let the guys know 'bout the new discovery, and the thing was back to being an ordinary knife until I re-selected it...

anyways. Great job man. You Rock.

(and before anybody goes wtf why would you want to do that, its research)

Share this post


Link to post
Share on other sites

Well scratch number 1 off the list of things we wanted. We have access to all the console commands that are hidden. you guys understand the power we just found ?

There are 1000's of commands out there. Just fire up bf2_r.exe open the console and double tap the tab button. Theres no telling how many there are we can access now. Things like nametag, nametags,skydome,player,game,gameLogic, chat,radio,hudbuilder and zillions more and they are just the top level commands....this is a new language in and of itself. No longer can BF2 python be called weak. But so much to learn......how can we hope to use all this without documentation.....

1. How to spawn a vehicle

host.rcon_invoke("gameLogic.createObject ce_truck")

actually spawns a working ce_truck on a dedicated server! So what if its not where we want it, setposition it!

2. Pause the game works

host.rcon_invoke("gameLogic.togglePause")

3. Set maximumlevelviewdistance sets the server variable but doesnt effect the fog distance (didnt test to see if it did when the map changed)

host.rcon_invoke("gameLogic.maximumlevelviewdistance 2000")

4. getTeamName works, although I couldnt get setTeamname to work

host.rcon_invoke("gameLogic.getTeamName")

5. create an inactive bot from python

host.rcon_invoke("gameLogic.createObject ce_red_soldier")

I am trying things like typing, these things in order to no avail, it spawns a bot who just stands there:

host.rcon_invoke("objecttemplate.active ce_red_soldier")

host.rcon_invoke("objecttemplate.networkableInfo BasicInfo")

host.rcon_invoke("ObjectTemplate.aiTemplate Soldier")

host.rcon_invoke("gameLogic.createObject ce_red_soldier")

anyway i never got the bot to work right. but I bet we could.

(edit: I never did try the player.isAi command after this)

6. all these sv. type commands work from within python.

load

save

configFile

serverName

password

internet

maxConnectionType

welcomeMessage

serverIP

serverPort

allowFreeCam

allowExternalViews

allowNoseCam

hitIndicator

maxPlayers

numReservedSlots

numPlayersNeededToStart

notEnoughPlayersRestartDelay

startDelay

endDelay

spawnTime

manDownTime

endOfRoundDelay

ticketRatio

roundsPerMap

timeLimit

scoreLimit

soldierFriendlyFire

vehicleFriendlyFire

soldierSplashFriendlyFire

vehicleSplashFriendlyFire

tkPunishEnabled

tkNumPunishToKick

tkPunishByDefault

votingEnabled

voteTime

minPlayersForVoting

voipEnabled

voipServerRemote

voipServerRemoteIP

voipServerPort

voipBFClientPort

voipBFServerPort

voipSharedPassword

voipQuality

gameSpyPort

allowNATNegotiation

interfaceIP

timeBeforeRestartMap

autoBalanceTeam

teamRatioPercent

autoRecord

demoIndexURL

demoDownloadURL

autoDemoHook

demoQuality

adminScript

sponsorText

sponsorLogoURL

communityLogoURL

radioSpamInterval

radioMaxSpamFlagCount

radioBlockedDurationTime

useGlobalRank

useGlobalUnlocks

ranked

punkBuster

6. list of gameLogic. commands available

togglePause

maximumLevelViewDistance

reset

refreshTriggerables

setTeamLanguage

getTeamLanguage

setTeamName

getTeamName

setTeamFlag

becomeSquadLeader

enableVoHelp

supplyDropHeight

supplyDropNumSecsToLive

hitIndicationThreshold

messages.setVolumes

messages.addMessage

messages.addRadioVoice

messages.addRadioFilter

messages.addHelpMessage

messages.playRadioMessage

messages.playHelpMessage

setKit

teleport

teleportTo

teleportCameraTo

setAirMouseInverted

setAirMouseSensitivity

remoteCommand

createObject

outputPlayerStats

spawnPlayers

spawnAtCameraPosition

setBeforeSpawnCamera

printCameraCoordToConsole

getBeforeSpawnCameraPosition

getBeforeSpawnCameraDirection

setDefaultNumberOfTickets

getDefaultNumberOfTickets

setDefaultNumberOfTicketsEx

getDefaultNumberOfTicketsEx

setNumberOfTickets

getNumberOfTickets

defaultTimeToNextAIWave

timeToNextAIWave

setTicketLossAtEndPerMin

getTicketLossAtEndPerMin

setTicketLossPerMin

getTicketLossPerMin

damageForBeingOutSideWorld

timeAllowedOutSideWorld

roundNr

spawnObjectSpeed

defaultLevel

7. player. commands!!

isAlive

team

spawnGroup

kit

pickup (whats does this one do??)

setFov

moveTo

create

active

listPlayerClasses

list

saveAll

isAi

isNetwork

name

vehicle

setVehicleWithInputId

8. Syntax for gameLogic commands

gameLogic.setTeamName 1 "CH"

gameLogic.setTeamName 2 "US"

gameLogic.setTeamLanguage 1 "English"

gameLogic.setTeamLanguage 2 "English"

gameLogic.setTeamFlag 0 "flag_invisible"

gameLogic.setTeamFlag 1 "flag_ch"

gameLogic.setTeamFlag 2 "flag_us"

gameLogic.setKit 1 0 "CE_Specops" "ce_red_soldier"

gameLogic.setKit 2 0 "CE_Specops" "ce_blue_soldier"

gameLogic.setKit 1 1 "CE_Sniper" "ce_red_soldier"

gameLogic.setKit 2 1 "CE_Sniper" "ce_blue_soldier"

gameLogic.setKit 1 2 "CE_Assault" "ce_red_soldier"

gameLogic.setKit 2 2 "CE_Assault" "ce_blue_soldier"

gameLogic.setKit 1 3 "CE_Support" "ce_red_soldier"

gameLogic.setKit 2 3 "CE_Support" "ce_blue_soldier"

gameLogic.setKit 1 4 "CE_Engineer" "ce_red_soldier"

gameLogic.setKit 2 4 "CE_Engineer" "ce_blue_soldier"

gameLogic.setKit 1 5 "CE_Medic" "ce_red_soldier"

gameLogic.setKit 2 5 "CE_Medic" "ce_blue_soldier"

gameLogic.setKit 1 6 "CE_AT" "ce_red_soldier"

gameLogic.setKit 2 6 "CE_AT" "ce_blue_soldier"

I was able to change the stuff assigned to each kit, in real time. In other words if you had kit 6 I could change setKit from CE_AT to CE_Medic. And next time you die you will get the CE_Medic kit.

I think we have to access the player himself to change kits and that is not in gameLogic. Actually to change kits we need to access the soldier object not the player object.

Share this post


Link to post
Share on other sites

I'm trying to get gameLogic.messages.playRadioMessage to work. It would (pretty much) solve this problem:

http://bfeditor.org/forums/index.php?showtopic=3463

I've tried sending it with and wihout quotes around the sound name and w/wo specifying a team:

host.rcon_invoke('gameLogic.messages.playRadioMessage "AUTO_RULES_ticketlevel_2"')



host.rcon_invoke('gameLogic.messages.playRadioMessage AUTO_RULES_ticketlevel_2')



host.rcon_invoke('gameLogic.messages.playRadioMessage 2 "AUTO_RULES_ticketlevel_2"')



host.rcon_invoke('gameLogic.messages.playRadioMessage 2 AUTO_RULES_ticketlevel_2')

None seem to work. I've tried it with several built-in sounds. Any ideas?

Share this post


Link to post
Share on other sites

That didn't work either. Thanks. Sorry for OT here: You shouldn't have to use that escape for the double quotes if the string is enclosed with single quotes.

Share this post


Link to post
Share on other sites

You can play around with the gravity settings in real-time by using:

host.rcon_invoke("physics.gravity X")

I forget what the normal setting is, but its around -15.

Also, I think we would all be really interested in getting this to work:

host.rcon_invoke("player.setVehicleWithInputId")

Unfortunately, i haven't figured out what arguments it wants for it to work. Using console.getArgumentTypes player setVehicleWithInputId, I was able to determine that the first argument is of type: IObject_ptrproxy and the second is of type: int. I still have no idea what it wants to work, since I'm not sure what IObject_ptrproxy is. Hopefully we can figure this out, as it may be the key to putting players in vehicles!

Share this post


Link to post
Share on other sites
pickup (whats does this one do??)

I have played around with that one of a while. It does change the current player's kit. You use it as such: player.pickup us_sniper Unfortunately, the new kit doesn't work. (Guns don't do anything) The player drops his old kit, and if he picks it up, the new kit that was spawned is stuck on the ground, no one can pick it up. So, unless someone can figure out how to fix this command, it is broken for the moment :(.

Share this post


Link to post
Share on other sites

Not quite following the player commands at the moment enough to test this with any clarity, been a long night. however...

objects_servercommonNetworkables.con

has the actual baseline networkable definitions, such as:

rem *** Basic ***



NetworkableInfo.createNewInfo BasicInfo



NetworkableInfo.setPredictionMode PMLinear

wich fixed the flag thing, as well as

rem *** FirearmsInfo ***



NetworkableInfo.createNewInfo HandFireArmsInfo



NetworkableInfo.setPredictionMode PMNone



NetworkableInfo.setForceNetworkableId 1

looking at the kit code, it's just got

rem *** Kit ***



NetworkableInfo.createNewInfo KitInfo



NetworkableInfo.setPredictionMode PMNone

now heres a blast form the past for us:

NetworkableInfo.createNewInfo KitInfo



NetworkableInfo.setHasOrientation 1



NetworkableInfo.setBasePriority c_NIGhostAlways



NetworkableInfo.setPredictionMode PMNone

Is the old 1942 version...

'fraid thats as coherent as I get when im feelin out ideas, folks.

Share this post


Link to post
Share on other sites

player.pickup works on weapons not kits....

Like when my soldier has kit CE_medic

I was able to add the ce_medikit to the kit by "player.pickup ce_medikit"

and I am able to fill a players existing kit with new weapons, this works if you make sure the new weapon has

1. a unique itemIndex that the player does not have yet.

Now I dont know about removing weapons yet, but adding seems to work.

This works fine during the game with no problems but when you disconnect the game it causes a crash to desktop:

D:DiceCanada_Xpack_PatchCodeBF2GameGameLogicGameLogic.cpp(913): Error: GameLogic: leaked object during reset (possible hierarchy change during destroy):ce_medikit

if we could find a way to get around this exit crash this method would work ok.

Share this post


Link to post
Share on other sites
player.pickup works on weapons not kits....

Interesting. I'm suprised it even works for kits at all. It looks like they key to figure this stuff out is testing, testing, and more testing. Hopefully it will pay off in the long run.

Share this post


Link to post
Share on other sites
None seem to work. I've tried it with several built-in sounds. Any ideas?

Couple of things. Putting print in front of the host.rcon_invoke() code will cause any error message to be printed to the python log. Also, I use

print host.rcon_invoke("console.getArgumentTypes commandPart1 commandPart2")

To find out how many arguments the command needs, and what type. In your case, the following:

print host.rcon_invoke("console.getArgumentTypes gameLogic messages.playRadioMessage")

returns with int std::string std::string std::string. So, we are looking at 4 arguments, the first one being an integer and the other 3 being strings. Hope that helps!

I'm personally interested in gameLogic.remoteCommand. It could give us even more access to the game engine. The following:

print host.rcon_invoke("console.getArgumentTypes gameLogic remoteCommand")

Returns int int int int int, but it says it only needs 1 argument, so the other 4 are optional. This command isn't going to be easy to figure out, since I have no idea what kind of integers its looking for, and the number of possible combinations for 5 integers is more than I want to guess and check. :wink: Maybe somebody has some insight on this function.

Share this post


Link to post
Share on other sites

King of Camelot mentioned this early in the thread...

This code will ONLY work if that vehicle template has been loaded on that map already.
D:DiceCanada_Xpack_PatchCodeBF2GameGameLogicGameLogic.cpp(913): Error: GameLogic: leaked object during reset (possible hierarchy change during destroy):ce_medikit

if we could find a way to get around this exit crash this method would work ok.

IIRC kits can be customized on a per map basis (at work so I can't verify). By any chance is the "weapon" missing/removed from your test kit? I'm guessing not since it works at all. I wonder if there's a way to modify the hierarchy on the fly with the rcon_invoke. Unfortunately, it sounds to me that since this is forcing things to happen, it doesn't happily co-exist with the way bf2 normally loads objects and keeps track of the memory allocations. If that's the case (hope I'm wrong) there might not be a fix.

I can also create dropped kits through gameLogic.createObject CE_Medic.
Very cool!
Couple of things. Putting print in front of the host.rcon_invoke() code will cause any error message to be printed to the python log. Also, I use

print host.rcon_invoke("console.getArgumentTypes commandPart1 commandPart2")

To find out how many arguments the command needs, and what type. In your case, the following:

print host.rcon_invoke("console.getArgumentTypes gameLogic messages.playRadioMessage")

Thanks! Very useful... I'll be trying that when I get home ;)

Share this post


Link to post
Share on other sites

So if we have a host.rcon_invoke command that requires text variables such as:

host.rcon_invoke("gameLogic.createObject VehicleName")







host.rcon_invoke("physics.gravity X")

everything works.

but what is your trying to use

host.rcon_invoke("player.setVehicleWithInputId".....

where the one variable type IObject_ptrproxy, that is not a text variable, how do you enter it? I mean how do we enter non text variables, like objects or players?

host.rcon_invoke("player.setVehicleWithInputId", Object)

Will the rcon_invoke command even work with the variable added like that?

Share this post


Link to post
Share on other sites
where the one variable type IObject_ptrproxy, that is not a text variable, how do you enter it?

It's wants a pointer to "remote" object, typical RPC stuff. The value of the pointer (integer most likely) could possibly be inserted as text, but how to get that value? From what I remember physicalObject.token is a number. I would try this:

(edited to add "id" text, after reading King's post below)

Share this post


Link to post
Share on other sites
host.rcon_invoke("player.setVehicleWithInputId".....

where the one variable type IObject_ptrproxy, that is not a text variable, how do you enter it? I mean how do we enter non text variables, like objects or players?

I looked into this some more, and I started looking at the argument types of commands I already know how to use. I found that:

host.rcon_invoke("object.active")

needs a world world::IObject_ptrproxy type argument. I'm not sure what the world:: part has to do with anything, but I assume it means nothing, just like how the std:: on std::string doesn't change anything. Anyways, I know that object.active requires an object's ID number, in the form of "id55555". So:

host.rcon_invoke("object.active id785")

works, but:

host.rcon_invoke("object.active 785")

doesn't. So, I think IObject_ptrproxy is just an id number for an object, which makes sense because you need to tell the game what object to put the player in when using player.setVehicleWithInputId. Ok, so we know what the first argument needs to be, but I'm still not sure about the second one. We know it needs to be an integer, but why? What does this integer have to do with anything? Anyways, I'm off to play around with this function some more. Maybe my new found knowledge can help me crack it.

Share this post


Link to post
Share on other sites
where the one variable type IObject_ptrproxy' date=' that is not a text variable' date=' how do you enter it?[/quote'']

It's wants a pointer to "remote" object, typical RPC stuff. The value of the pointer (integer most likely) could possibly be inserted as text, but how to get that value? From what I remember physicalObject.token is a number. I would try this:

(edited to add "id" text, after reading King's post below)

Token is actually just a reference to a PyCObject, which as far as I know doesn't help us. I too looked at physicalObject.token a while back. Unfortunately, the BF2 engine uses id numbers in the form of "idXXXX" to identify objects, and I don't know of anyway to go from a python physicalObject to that object's ID number in the BF2 engine. So, basically, even if we have the object in python, we have to find it in the BF2 engine. I usually use:

host.rcon_invoke("object.listObjectsofTemplate TemplateName")

to look up objects. The only hard part is when you get a ton of objects back, like when looking for a kit such as us_sniper. When that happens, the only way to find the one you want would be to find the absolutePosition of all of them, and compare it to the position of the object in python. This is obviously not the best way, but it is the only way I can think of at the moment.

Anyways, good news on the host.rcon_invoke("player.setVehicleWithInputId") front! I was playing around with this command in BF2_r.exe, and found that I can somewhat make it workable. I entered a vehicle, and used player.vehicle to find the BF2 engine's id for it. Once I got that ID, I exited the vehicle, and used the following code:

host.rcon_invoke("player.setVehicleWithInputId idXXXX 5")

To my astonishment, it actually put me in the vehicle...sort of. I found myself physically inside the shell of the object, but without a Hud, or control of the vehicle. I could switch weapons(I heard the noises), but I couldn't see anything other than the physical vehicle. When I tried to exit the vehicle, it wouldn't let me, so I commit suicide, which then crashed the game. I get the same results when I use 1 at the end of the code instead of 5.

So, I am partway to figuring out how to put players in vehicles. All I need to do is figure out what it wants me to put in for the integer to make this work, and we may be able to put players in vehicles through python. I figure you would also be able to make them exit the vehicle by either putting in nothing for the vehicle ID, or more likely by entering the ID of their soldier object. Well, off to play some more.

EDIT: I just tried using 0 for the last integer, and got an interesting result. I was trying to put myself in a helicopter, and using 0 put me into it, and put me into a spin, as if I was holding down the D key. I could use the A key to counter-act this and stop the spinning. I have a feeling the last integer has something to do with keyboard keys or something. This would make sense, I realize now, because the name of the command is player.setVehicleWithInputID. InputID could be referring to keyboard input, and that could be what that last integer is.

EDIT2: This is starting to make more sense. I looked into what name command the D key was mapped to in the control CON files, and found this line:

ControlMap.addKeysToAxisMapping [b]c_PIYaw[/b] IDFKeyboard IDKey_D IDKey_A

I then used the following code:

host.rcon_invoke("console.listConstants")

I knew from past experience that this returns a list of all constants(which are named with c_ in front of their name, like c_PIYAW). The code returned this list(I cut it down so it won't be too long):

c_PIUse 10



c_PIWeaponSelect1 14



c_PIWeaponSelect2 15



c_PIWeaponSelect3 16



c_PIWeaponSelect4 17



c_PIWeaponSelect5 18



c_PIWeaponSelect6 19



c_PIWeaponSelect7 20



c_PIWeaponSelect8 21



c_PIWeaponSelect9 22



[b]c_PIYaw 0[/b]



c_Release 1



c_totalAccess 7



c_True 1



c_Win32 1



c_Xbox 0

Sure enough, there is the c_PIYaw, and its value is 0! So, this confirms that the last integer is referring to control mapping constants, and I now have a list of them. Now, to find the one that lets me control the vehicle like normal.

EDIT 3: I have come to the conclusion that this function may be broken. Good old DICE just loves to tempt us, but never gives us anything to work with. I found that the function would except constants in place of the integer, which made testing easier for me. I was able to get Stingers somewhat working by using the function with c_PIAction. This let me use my mouse to look around with the Stinger like usual, but nothing else. The HUD was still broken, and I could not fire or exit the Stinger. I could also see my arms floating in mid-air where I had been standing before I did the command. The game also crashed when I tried to exit. I had a lot of hope for this command, but unless anyone else has insight on it, it appears that DICE never made that function work correctly. :(

--------------------------------------------------------------

This function has even odder results when run on a dedicated server. Looks like its totally broken, atleast for the moment.

Share this post


Link to post
Share on other sites

Sorry for the dumb question and especially if I missed the answer somewhere, but why does it keep giving me "Unautherised method!" errors? I'm trying this on a local server.

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  

×