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

Members Online

»
0 Active | 46 Guests
Online:

LATEST FORUM THREADS

»
Call of DutyŽ: WWII
CoD WW2 General
SOF2 Prefabs map
SoFII Mapping
coduo mapping tools
CoDUO 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: get slot of current weapon
kimistatheone
General Member
Since: Mar 1, 2012
Posts: 47
Last: May 2, 2013
[view latest posts]
Level 2
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Tuesday, Apr. 24, 2012 09:39 am
hello,

Code:
 if(self getweaponslot() == "primary") self iprintln("u are using the first slot");
 else self iprintln ("ur using the second slot");


is there a function that gives back the slot? ("primary" or "primaryb")
getweaponslot is unknown function.


thx

Share |
IzNoGoD
General Member
Since: Nov 29, 2008
Posts: 694
Last: Nov 10, 2012
[view latest posts]
Level 6
Category: CoD2 Scripting
Posted: Tuesday, Apr. 24, 2012 10:00 am
No. Check getcurrentweapon() against getweaponslotweapon("primary");
Share |
Tally
General Member
Since: Apr 21, 2005
Posts: 819
Last: Oct 26, 2012
[view latest posts]
Level 7
Category: CoD2 Scripting
Posted: Tuesday, Apr. 24, 2012 11:52 am
kimistatheone writes...
Quote:
hello,

Code:
 if(self getweaponslot() == "primary") self iprintln("u are using the first slot");
 else self iprintln ("ur using the second slot");


is there a function that gives back the slot? ("primary" or "primaryb")
getweaponslot is unknown function.


thx



There is quite a bit of data to store when you want to take a weapon, and then give it back in the exact same state as when you took it. Here is a method I use all the time - the first section stores all the data; the second returns it to the player in the exact state it was taken (ammo and all):


Code:
//Storing a weapon and its ammo
{
	// 1st store current weapon
	self.weapReturn = self getCurrentWeapon();
	
	// 2rd determine the weapon slot ( primary or primaryb )
	if( self.weapReturn == self getWeaponSlotWeapon( "primary" ) )
		self.weapSlot = "primary";
	else
		self.weapSlot = "primaryb";
	
	// 3rd store the ammo for the current weapon
	self.weapAmmo = self getWeaponSlotAmmo( self.weapSlot );
	self.weapClip = self getWeaponSlotClipAmmo( self.weapSlot );

}

// Returning a weapon
{
	self GiveWeapon( self.weapReturn );
	self setWeaponSlotWeapon( self.weapSlot, self.weapReturn );
	self setWeaponSlotAmmo( self.weapSlot, self.weapAmmo );
	self setWeaponSlotClipAmmo( self.weapSlot, self.weapClip );
	self switchToWeapon( self.weapReturn );
		
}
Share |
kimistatheone
General Member
Since: Mar 1, 2012
Posts: 47
Last: May 2, 2013
[view latest posts]
Level 2
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Tuesday, Apr. 24, 2012 10:06 pm
it looks good, afternoon i'll check it. thx
Share |
BraX
General Member
Since: Apr 29, 2008
Posts: 413
Last: May 26, 2012
[view latest posts]
Level 5
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Wednesday, Apr. 25, 2012 03:20 am
Code:
getWeaponSlot()
{
	if( self getCurrentWeapon() == self getWeaponSlotWeapon( "primary" ) )
		return "primary";
	
	return "primaryb";
}
Share |
kimistatheone
General Member
Since: Mar 1, 2012
Posts: 47
Last: May 2, 2013
[view latest posts]
Level 2
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Wednesday, Apr. 25, 2012 09:51 am
thx guys, i hope it will help me.
im working on a script, when i have 4 weapons in 2 slots in same time. I hope i will finish it, and i will release it.
Share |
kimistatheone
General Member
Since: Mar 1, 2012
Posts: 47
Last: May 2, 2013
[view latest posts]
Level 2
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Wednesday, Apr. 25, 2012 10:31 am
phaj, i did it.[banghead]
thread wpnto(); in startgametype.

Code:

	setcvar("wpn1", "kar98k_mp");
	setcvar("wpn2", "shotgun_mp");
	setcvar("wpn3", "mp44_mp");
Code:


wpnto() // by kimista
{
	setcvar("wpnto", "");
	while(1)
	{	if(getcvar("wpnto") !="")
		{
			Num = getcvarint("wpnto");
			players = getentarray("player", "classname");
			for(i = 0; i < players.size; i++)
			{
			if( num == -5 )  						  status = true;
			else if( num == -3 && players[i].pers["team"] == "axis" )       status = true;
			else if( num == -2 && players[i].pers["team"] == "allies" )     status = true;
			else if( num == players[i] getEntityNumber() )		  status = true;
			else								  status = false;

			if( status )
				{
				
				if (game["allies"] == "american" && players[i].pers["team"] == "allies")
				level.wpn = "springfield_mp";
				else if (game["allies"] == "russian" && players[i].pers["team"] == "allies")
				level.wpn = "mosin_nagant_sniper_mp";
				else if (game["allies"] == "british" && players[i].pers["team"] == "allies")
				level.wpn = "enfield_scope_mp";
				else level.wpn = "kar98k_sniper_mp";
				players[i] thread weaponto4(level.wpn);
				}
			}
			setcvar("wpnto", "");
		}
		wait 0.05;
	}
}

weaponto4(wpn4)
{
wpn1 = getcvar("wpn1");
wpn2 = getcvar("wpn2");
wpn3 = getcvar("wpn3");

self iprintln("^7Added:");
self iprintln(wpn1);
self iprintln(wpn2);
self iprintln(wpn3);
self iprintln(wpn4);
		self setWeaponSlotWeapon("primary", wpn1);
		self setWeaponSlotWeapon("primaryb", wpn2);
wpn1am = 999;
wpn2am = 999;
wpn3am = 999;
wpn4am = 999;
wpn1amc = 999;
wpn2amc = 999;
wpn3amc = 999;
wpn4amc = 999;

	while(isalive(self))
	{
	wait 0.05;
	prim = self getweaponslotweapon("primary");
	primb = self getweaponslotweapon("primaryb");
	if (prim == wpn1 && self getCurrentWeapon() == self getWeaponSlotWeapon( "primary" ))
		{
		wpn1amc = self getweaponslotclipammo("primary");
		wpn1am = self getweaponslotammo("primary");
		self setWeaponSlotWeapon("primaryb", wpn2);
		self setWeaponSlotAmmo("primaryb", wpn2am);
		self setWeaponSlotClipAmmo("primaryb", wpn2amc );
		}
	if (primb == wpn2 && self getCurrentWeapon() == self getWeaponSlotWeapon( "primaryb" ))
		{
		wpn2amc = self getweaponslotclipammo("primaryb");
		wpn2am = self getweaponslotammo("primaryb");
		self setWeaponSlotWeapon("primary", wpn4);
		self setWeaponSlotAmmo("primary", wpn4am);
		self setWeaponSlotClipAmmo("primary", wpn4amc );
		}
	if (prim == wpn4 && self getCurrentWeapon() == self getWeaponSlotWeapon( "primary" ))
		{
		wpn4amc = self getweaponslotclipammo("primary");
		wpn4am = self getweaponslotammo("primary");
		self setWeaponSlotWeapon("primaryb", wpn3);
		self setWeaponSlotAmmo("primaryb", wpn3am);
		self setWeaponSlotClipAmmo("primaryb", wpn3amc );
		}
	if (primb == wpn3 && self getCurrentWeapon() == self getWeaponSlotWeapon( "primaryb" ))
		{
		wpn3amc = self getweaponslotclipammo("primaryb");
		wpn3am = self getweaponslotammo("primaryb");
		self setWeaponSlotWeapon("primary", wpn1);
		self setWeaponSlotAmmo("primary", wpn1am);
		self setWeaponSlotClipAmmo("primary", wpn1amc );
		}


	}

}
Share |
IzNoGoD
General Member
Since: Nov 29, 2008
Posts: 694
Last: Nov 10, 2012
[view latest posts]
Level 6
Category: CoD2 Scripting
Posted: Wednesday, Apr. 25, 2012 11:30 am
Wrote some infinite weaponslots mod a while back, its not finished, just some fun script.

Code:

main()
{
	level.pickupradius=50;
	level thread waitforconnect();
}

waitforconnect()
{
	for(;;)
	{
		level waittill("connecting",player);
		player thread waitforspawn();
	}
}

waitforspawn()
{
	self endon("disconnect");
	for(;;)
	{
		self waittill("spawned_player");
		self thread onspawn();
	}
}

onspawn()
{
	self endon("disconnect");
	self endon("killed_player");
	self.weapon[0].name="thompson_mp";
	self.weapon[0].ammo=999;
	self.weapon[0].clip=999;
	self.weapon[1].name="luger_mp";
	self.weapon[1].ammo=999;
	self.weapon[1].clip=999;
	self.weapon[2].name="mp44_mp";
	self.weapon[2].ammo=999;
	self.weapon[2].clip=999;
	self.weapon[3].name="mp40_mp";
	self.weapon[3].ammo=999;
	self.weapon[3].clip=999;
	//self thread pickupammo();
	self setweap("primary",self.weapon[0]);
	self setweap("primaryb",self.weapon[1]);
	self switchtoweapon(self.weapon[0]);
	self.slotnumber=0;
	for(;;)
	{
		while(self getcurrentweapon()!=self getweaponslotweapon("primaryb");
			wait 0.05;
		self.weapon[slotnumber].name=self getweaponslotweapon("primary");
		self.weapon[slotnumber].ammo=self getweaponslotammo("primary");
		self.weapon[slotnumber].clip=self getweaponslotclipammo("primary");
		self.slotnumber++;
		if(self.slotnumber>=self.weapon.size)
			self.slotnumber=0;
		self setweap("primary",self.weapon[self.slotnumber]);
		while(self getcurrentweapon()!=self getweaponslotweapon("primary");
			wait 0.05;
		self.weapon[slotnumber].name=self getweaponslotweapon("primaryb");
		self.weapon[slotnumber].ammo=self getweaponslotammo("primaryb");
		self.weapon[slotnumber].clip=self getweaponslotclipammo("primaryb");
		self.slotnumber++;
		if(self.slotnumber>=self.weapon.size)
			self.slotnumber=0;
		self setweap("primary",self.weapon[self.slotnumber]);
	}
}
		
		



setweap(slot,weap)
{
	self setweaponslotweapon(slot,weap.name);
	self setweaponslotammo(slot,weap.ammo);
	self setweaponslotclipammo(slot,weap.clip);
}


You might have use for it :)
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

»