Login x
User Name:
Password:
Social Links Facebook Twitter YouTube Steam RSS News Feeds

Members Online

»
0 Active | 84 Guests
Online:

LATEST FORUM THREADS

»
CoD: Battle Royale
CoD+UO Map + Mod Releases
Damaged .pk3's
CoD Mapping
heli to attack ai
CoD4 SP Mapping

Forums

»

Welcome to the MODSonline.com forums. Looking for Frequently Asked Questions? Check out our FAQs section or search it out using the SEARCH link below. If you are new here, you may want to check out our rules and this great user's guide to the forums and the website.
For more mapping and modding information, see our Wiki: MODSonWiki.com

Jump To:
Forum: All Forums : Call of Duty 2
Category: CoD2 Scripting
Scripting and coding with Call of Duty 2.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked subscribe
Author Topic: Advanced Scripting Question
r00t_
General Member
Since: Dec 15, 2010
Posts: 51
Last: May 16, 2011
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Wednesday, Dec. 15, 2010 03:45 am
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 [banghead]

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 [biggrin]

And please check out the site for b3, it is great! and runs on a large assortment of games.
Share |
liltc64
General Member
Since: Feb 12, 2007
Posts: 906
Last: Oct 22, 2012
[view latest posts]
Level 7
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Wednesday, Dec. 15, 2010 04:53 am
well to see wich one is working python or your script you might wana do somthing more simpler, try starting with a simple iprintlnbold? just have it print a msg if it dosnt happend then your python script isnt working. i would tell if ur script is working but im confused by the B3CvarValue and B3PlayerNum iv never worked with B3 before and i dont want to give u false info so just try out what i said and see what works and what dosnt.
Share |
Pedro699
General Member
Since: Jun 19, 2006
Posts: 781
Last: Dec 18, 2010
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Wednesday, Dec. 15, 2010 01:28 pm
As liltc says try a simple iprintln first.

Having looked at your script there are a number of issues with it. First off, you say you want to move a player, but you appear to be spawning a model and moving it up a bit instead.

You also have 4 different cvar names in your script, instead of 2 - make sure your python is setting the right ones.

You also need to make sure it is threaded correctly - post your complete gsc file for help with this.

Providing it is threaded correctly, then I would rewrite your script as follows:

Code:
// The B3 !teleport command:
_b3_teleport()
{
	B3TargetNum = getcvarint("b3_teleportto");
	B3PlayerNum = getcvarint("b3_teleported");
	setcvar("b3_teleported", "");
	setcvar("b3_teleportto", "");
	
	playerToMove = undefined;
	target = undefined;

	players = getentarray("player", "classname");
	
	for(i = 0; i < players.size; i++)
	{
		player = players[i];
		
    	num = player getEntityNumber();
    	
    	if(player.sessionstate == "playing") // check they are alive
    	{
         if(num == B3PlayerNum) // found player to move
            playerToMove = player;
         else if(num == B3TargetNum) // found target location player
            target = player.origin;
    	}
	}
	
	if(isDefined(playerToMove) && isDefined(target)) // found both bits of info
	{
      playerToMove setorigin(target);
      iprintln("Player " + playerToMove.name + " has been moved!");
	}
	else
	{
      iprintln("One of the required players was not found");
	}
}


There is a potential problem with this idea that the player moved will get stuck inside the target player, but I don't know how CoD will react to this. If they do get stuck it becomes a lot more complicated as you need to find a free space.

Share |
r00t_
General Member
Since: Dec 15, 2010
Posts: 51
Last: May 16, 2011
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Thursday, Dec. 16, 2010 01:41 am
Your script makes me think "what was I thinking?!"
And I am almost positive the python script is currently working, because I have made simpler commands like !invisible and !visible that work fine [biggrin]

About the character getting stuck, I do not think a player can get stuck in another player, but if it's possible, could you edit that script to offset the Z coordinate of the person being teleported so it is slightly higher than the person that is calling them over? Like just adding 10 to the Z axis?
I think it is possible, but I don't know how to go about doing it.

And thank you, this has been a BIG help.

PS Pedro, if you wouldn't mind, could you PM me your xfire, I'd like to shoot you some more questions about scripts I'm also working on. Or I could PM you.
Share |
Pedro699
General Member
Since: Jun 19, 2006
Posts: 781
Last: Dec 18, 2010
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Thursday, Dec. 16, 2010 12:33 pm
You can offset the target by making this modification:

playerToMove setorigin( target + (0,0,10) );

I think you may be correct about player not getting stuck in each other, as with large servers which sometimes have twice as many players as spawnpoints its usually fine.

The only thing that may be a problem is if either player is crouched or prone and the other is in a different stance in an enclosed space. Its possible in this case that the moved player may get stuck in the map.

An alternative would be to search all available spawn points and find one nearby, as these have clearance for the player (possibly combined with forcing their stance to crouch or standing if they are prone).
Share |
r00t_
General Member
Since: Dec 15, 2010
Posts: 51
Last: May 16, 2011
[view latest posts]
Level 3
Category: CoD2 Scripting
Posted: Thursday, Dec. 16, 2010 07:31 pm
All of those are viable concerns, but I'm not going to worry about it. If a player gets stuck and has to /kill, i can always compensate for his death.

Also, I was wondering what you thought about a !give command and a !giveammo command.

Details for !give:
-!give [name] [weapon]
-give the player a weapons with full ammo

And !giveammo:
-!giveammo [name]
-would give max ammo for the weapon in slot one. (and possible slot 2 as well)

here is what i have so far for !give:
Code:
// The B3 !give command:
_b3_give()
{
	B3PlayerNum = getcvarint("b3_gname");
	B3CvarValue = getcvar("b3_gun");
	setcvar("b3_gun", "");
	setcvar("b3_gname", "");

	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 setweaponslotweapon("primary", B3CvarValue);
		}
	}
}


and !giveammo (currently the !giveammo command takes another argument that tells what type of ammo to give the player. I would like to change this so that it just gives the proper ammo for the weapon the player already has)
Code:
// The B3 !giveammo command:
_b3_giveammo()
{
	B3PlayerNum = getcvarint("b3_giveammo");
	B3CvarValue = getcvarint("b3_ammo");
	setcvar("b3_giveammo", "");
	setcvar("b3_ammo", "");

	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 GiveWeaponSlotAmmo ("primary", B3CvarValue);
		}
	}
}
Share |
Pedro699
General Member
Since: Jun 19, 2006
Posts: 781
Last: Dec 18, 2010
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Friday, Dec. 17, 2010 11:13 am
The !give code looks fine, although you'll probably want to check that the weapon being given is a valid string. There are a list of weapon names in maps/mp/gametypes/_weapons.gsc that you can pull out and modify.

For the !giveammo command, simply set the ammo for one (or both) weapon slots:

player setweaponslotammo( "primary", 999 );
player setweaponslotammo( "primaryb", 999 );
Share |
Restricted Access Topic is Locked subscribe
MODSonline.com Forums : Call of Duty 2 : CoD2 Scripting

Latest Syndicated News

»
Codutility.com up and runn...
Nice, and there still using the logo and template for the screenshots, which...
Codutility.com up and runn...
dundy writes...Quote:Call of Duty modding and mapping is barly alive only a ...
Codutility.com up and runn...
Mystic writes...Quote:It seems to me the like the site is completely dead? ...
Codutility.com up and runn...
It seems to me the like the site is completely dead?

Partners & Friends

»