If anyone reading this is familiar with b3, you may also be familiar with the poweradmin plugin that you can add to it.
For those of you who are new to b3, it is a bot made entirely in python that runs alongside your gameserver. You give it access to your rcon password and therefore gives you many benefits for ingame administrating.
The poweradmin plugin is scripted in python and also is linked to a game mod.
For example, here is the python part of an ingame b3 command that explodes (and kills) a player ingame (presumably for being "naughty")
Code:
def cmd_paexplode(self, data, client, cmd=None):
"""\
<player> [<reason>] - Blow the player up.
(You can safely use the command without the 'pa' at the beginning)
"""
# this will split the player name and the message
input = self._adminPlugin.parseUserCmd(data)
if input:
# input[0] is the player id
sclient = self._adminPlugin.findClientPrompt(input[0], client)
if not sclient:
# a player matchin the name was not found, a list of closest matches will be displayed
# we can exit here and the user will retry with a more specific player
return False
else:
client.message('^7Invalid data, try !help switch')
return False
if len(input[1]):
sclient.message('^3You are being killed: ^7%s' % (input[1]))
# are we still here? Let's execute the kill
self.console.setCvar( 'b3_explode','%s' % sclient.cid )
return True
And the cod2 script for explode:
Code:
_b3_explode()
{
B3PlayerNum = getcvarint("b3_explode");
setcvar("b3_explode", "");
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
player = players[i];
thisPlayerNum = player getEntityNumber();
if(thisPlayerNum == B3PlayerNum) // this is the one we're looking for
{
player thread _cmd_explode_threaded();
}
}
}
_cmd_explode_threaded()
{
if (self.pers["team"] != "spectator")
{
if(isAlive(self))
{
playfx(level._effect["bombexplosion"], self.origin);
self playSound("mortar_explosion" + (randomInt(5) + 1));
wait .05;
self suicide();
iprintln(self.name + "^7 was blown to bits!");
}
}
return;
}
This all seems confusing, but basically all that happens is the python script first of all checks for when an admin types "!explode [name]", and then runs the python script above. All that script does is change a cvar that the cod2 script checks for. Once the cvar changes from empty, the cod2 script executes and explodes whoever the intended target is.
So now that you've learned something, it's time to get to my question. it is quite possible to add your own commands to the poweradmin plugin. I have decided to make a somewhat complicated command that works like this:
-syntax = "!teleport [name1] [name2]"
-name1 = the person to teleport
-name2 = the person to teleport name1 to
For this, I won't try to confuse anyone with my python script, but it is noteworthy to point out that instead of just changing one cvar (like explode), it has to change two (because there are two names).
Lets get to the cod2 code:
Code:
// The B3 !teleport command:
_b3_teleport()
{
B3PlayerNum = getcvarint("b3_teleportto");
B3CvarValue = getcvarint("b3_teleported");
setcvar("teleported", "");
setcvar("teleportto", "");
found = 1
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
player = players[i];
thisPlayerNum = player getEntityNumber();
if(thisPlayerNum == B3PlayerNum) // this is the one we're looking for
{
found = found + 1;
end = player;
}
if(thisPlayerNum == B3CvarValue) // this is the one we're looking for
{
found = found + 1;
begin = player;
}
if(found == 3)
{
model = spawn("script_model", teleported.orgin);
model setModel("xmodel/prop_bear");
begin linkto(model);
model moveto(end.origin, 0.5);
model movez(20, 2);
model waittil ("movedone");
begin unlink();
model delete();
}
}
}
Finally, this is my question: Will this script work (presumably). I have tested with b3 and my python script, and when i type my !teleport command, nothing happens. So i need to know if it is a problem with my cod2 script, or python
Thanks to whoever read this through in its entirety. This post my be a little too advanced for the difficulty that is present on this website, but I figured I'd try here
And please check out the site for
b3, it is great! and runs on a large assortment of games.