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

Members Online

»
0 Active | 68 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 4
Category: CoD4 Scripting
Scripting and coding with Call of Duty 4.
Moderators: foyleman, Foxhound, Mystic, StrYdeR, batistablr, Welshy, DrBiggzz, supersword, playername, novemberdobby
Latest Posts
Subscribed Posts
Search
Restricted Access Topic is Locked subscribe
Author Topic: How to create a new weapon (need help)
Bodkin
General Member
Since: Nov 20, 2005
Posts: 75
Last: Dec 10, 2008
[view latest posts]
Level 3
Category: CoD4 Scripting
Posted: Wednesday, Sep. 3, 2008 08:21 am
hi
I am new to scripting so just trying to make a few scripts to get the hang of it.

I have made my first script that jams your weapons randomly:

_weaponjam
Code:
main()
{

	thread setisjammed();

}

setisjammed()
{
	self.isjammed = 0;
	thread checkjammed();
}

checkjammed()
{
	while(1)
	{
		if( self.isjammed == 0)
		{
			thread weaponjam();
		}
		wait 0.05;
	}
}

weaponjam()
{
	if( self AttackButtonPressed() )
	{
		self.weapon = self GetCurrentWeapon();
		self.weaponammo = (self GetAmmoCount( self.weapon ) - 1);
		self.noammo = self GetAmmoCount( self.weapon );
			if( self.noammo == 0 )
			{
				self.isjammed = 0;
			}

			else if( RandomInt( 200 ) == 100 )
			{
				thread jamweapon();
			}
	}
}

jamweapon()
{
	self.isjammed = 1;
	self TakeWeapon( self.weapon );
	self PlayLocalSound( "weap_dryfire_smg_plr" );
					
		if(!isdefined(self.jamwarning))
		{
			self.jamwarning = newClientHudElem(self);
			self.jamwarning.archived = false;
			self.jamwarning.x = 320;
			self.jamwarning.y = 100;
			self.jamwarning.alignX = "center";
			self.jamwarning.alignY = "middle";
			self.jamwarning.sort = 1;
			self.jamwarning.fontscale = 1.5;
		}
		
		thread warningmsg();
}

warningmsg()
{	
	self.jamwarning SetPulseFX( 40, 4000 , 600 );
	self.jamwarning setText("^1Weapon Jammed!!!");
	self sayteam("^7My Weapon Has ^1Jammed!!!");
	wait 2;

	thread startclearjam();

	self.jamwarning setText("^7Press ^3F ^7to clear");
	level.jamwarning FadeOverTime( 2.8 );  
	level.jamwarning.alpha = 0.3;
	wait 3;
	self.jamwarning Destroy();
}

startclearjam()
{
	while(1)
	{
		if(self.isjammed == 1)
		{
			thread clearjam();
		}
		wait 0.05;
	}
}

clearjam()
{
	if( self.isplanting == true )
	{
		self.plantwait = 1;
	}

	else if( self.isdefusing == true )
	{
		self.defusewait = 1;
	}

	else if( self.plantwait == 1 )
	{
		wait (1.5);
		self.plantwait = 0;
	}

	else if( self.defusewait == 1 )
	{
		wait (1.5);
		self.defusewait = 0;
	}

	else if( self.isplanting == false )
	{
		if( self UseButtonPressed() )
		{
			self GiveWeapon( self.weapon, 0 );
			if( self HasWeapon( self.weapon ) )
			{
				self SwitchToWeapon( self.weapon );
				self SetWeaponAmmoStock( self.weapon, self.weaponammo );
				self SetWeaponAmmoClip( self.weapon, 0);
				self.clearedmsg = 0;
				thread jammsg();
			}
		}
	}
	else
	{
	self.isjammed = 1;
	}
}

jammsg()
{
	while(self.clearedmsg == 0)
	{
		self.clipcount = self GetWeaponAmmoClip( self.weapon );

		if( (self.clipcount) >= 1 )
		{
			self.clearedmsg = 1;
			self.isjammed = 0;
			if(!isdefined(self.jamwarning))
			{
				self.jamwarning = newClientHudElem(self);
				self.jamwarning.archived = false;
				self.jamwarning.x = 320;
				self.jamwarning.y = 100;
				self.jamwarning.alignX = "center";
				self.jamwarning.alignY = "middle";
				self.jamwarning.sort = 1;
				self.jamwarning.fontscale = 1.5;
			}
			
			wait (1.5);	
			self.jamwarning SetPulseFX( 40, 4000 , 600 );		
			self.jamwarning setText("^2Weapon Jam Cleared");
			self sayteam ("^2Jam Cleared and Ready To go");
			wait 2;
			self.jamwarning Destroy();
		}
		wait 0.05;
	}
}

This seems to work fine, however the script seems abit long ... wondering if people could give me a few pointers for making it better and easier to read.

Also i now want to make a new weapon (tape player) ... well actually just copy the "c4_mp" and rename it to "tape_mp", then edit it so that footstep sounds are played in the area were the tape has been frown. (trick the enemy [devilishgrin] hehe)

When i add the tape_mp to weapons\mp\ , and then create a script for onspawnplayer

wait 20;
GiveWeapon( "tape_mp", 0 )

it does not give the player the weapon. Ive also tried copying the "mp5_mp" weapon file and pasting it to my weapons\mp then renaming it to "tape_mp" with out editing it at all, however in game it still doesnt give the player the weapon. Im guessing ive got to edit another file to tell the game what "tape_mp" is ... any ideas?

Thanks Bodkin.

edited on Sep. 3, 2008 04:22 am by Bodkin

edited on Sep. 3, 2008 04:22 am by Bodkin

edited on Sep. 3, 2008 04:29 am by Bodkin
Share |
Bodkin
General Member
Since: Nov 20, 2005
Posts: 75
Last: Dec 10, 2008
[view latest posts]
Level 3
Category: CoD4 Scripting
Posted: Wednesday, Sep. 3, 2008 09:37 pm
wondering if i have to use the asset manager to import the new weapon file?
Share |
Tally
General Member
Since: Apr 21, 2005
Posts: 819
Last: Oct 26, 2012
[view latest posts]
Level 7
Category: CoD4 Scripting
Posted: Thursday, Sep. 4, 2008 08:10 am
There are a couple of things I want to advise on:

1. You are running threads without stating the ent on which to run them. Is is self? Or level? What?

Without stating "what" to run on, the game will only spit out script_runtime errors, telling you that undefined is not an object or field vector

2. You try to use a randomint() but dont appear to specify what ent or vector to initiate on.

3. COD4 uses boolean logic. Things are either true, or false; defined or undefined.

Now, whereas 1 and 0 are boolean values of sorts, a truer check on a variables boolean state would be something like this:

Code:
setisjammed()
{
	self.isjammed = false;
	self thread checkjammed();
}

checkjammed()
{
	while(1)
	{
		if( !self.isjammed )
		{
			self thread weaponjam();
		}
		wait 0.05;
	}
}


4. To get a new weapon ingame, you need to compile the weapon file into your mod.ff file. A copy of this file must also be in RAW format, in your mods IWD file. So, basically, 2 identical weapons files, one compiled into fast file, the other RAW one in the IWD file.

In your mod.csv file, put something like this:

Quote:
weapon,mp/tape_mp


It must also be precached somewhere, at the Callback_StartGametype() stage of gamestate.

edited on Sep. 4, 2008 04:13 am by Tally
Share |
Bodkin
General Member
Since: Nov 20, 2005
Posts: 75
Last: Dec 10, 2008
[view latest posts]
Level 3
Category: CoD4 Scripting
Posted: Thursday, Sep. 4, 2008 08:58 am
Thanks alot Tally [thumbs_up],

will take into account what you advised and rewrite my weapon jamming script, ... hopefully i will get it right.

also with the randomint() , what do you mean by specify on ent or vector? [confused] ... should i have done something like:

Code:
jamrandom = randomint(100);

if(jamrandom == 50)
	{
	//code
	}


^^ thats probally a real noob question to ask lol, but just tryin to make sure i understand things.
Share |
Restricted Access Topic is Locked subscribe
MODSonline.com Forums : Call of Duty 4 : CoD4 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

»