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

Members Online

»
0 Active | 36 Guests
Online:

LATEST FORUM THREADS

»
map test
CoD Mapping
first map
CoD4 MP Mapping
eXtreme+ v2.9
CoDBO Map + Mod Releases
Gaming
Q4 General

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: Calculator?
Zelzahim
General Member
Since: Dec 31, 2008
Posts: 42
Last: Sep 23, 2010
[view latest posts]
Level 2
Category: CoD2 Scripting
Posted: Tuesday, Dec. 22, 2009 08:17 am
Evening.

Im trying to create a simple "calculator" for use in a planned multiplayer artillery system. I want to be able to move the spot where the artillery hits at custom, so i thought i might start out with a simple variable called sum.

I want to be able to increase and decrease the value of the variable "sum" by pressing two triggers_use named inc and dec, but i just cant get it to work.

Any ideas?

Well, this is my script so far. All it does is showing the current sum when you press a button.

Quote:
main()
{

thread output();

}
output()

{

sum = 10;

sumtrig = getent ("sum","targetname");

while(1)
{

sumtrig waittill ("trigger");

iprintln("Your current value is:");
wait (0.1);
iprintln(sum);

}

}
Share |
playername
Preferred Member
Since: Aug 24, 2006
Posts: 821
Last: Apr 15, 2011
[view latest posts]
Level 7
Forum Moderator
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Tuesday, Dec. 22, 2009 08:39 am
Hello Zelzahim!
In order for "sum" to increase, you need to add somewhere the addition operator to tell "sum" to increase:
sum++; OR sum += 1; OR sum = sum+1;

As for having two triggers to do this, try this script (untested)! I used two trigger_uses with targetnames of "inc" and "dec"

Code:
main()
{
	// Setup the global sum
	level.sum = 10;

	// Thread the inc trigger and dec trigger functions
	incTrig = getEnt("inc", "targetname");
	decTrig = getEnt("dec", "targetname");

	thread trigWatch(incTrig, true); // TRUE -> Set to increase when triggered
	thread trigWatch(decTrig, false); // FALSE -> Set to decrease when triggered
}

trigWatch(trig, inc)
{
	// If the trigger wasn't found, leave the function so we don't get errors.
	if(!isDefined(trig))
		return;

	while(1)
	{
		trig waittill("trigger"); // wait for trigger

		// IF we are set to increase, THEN increase. IF NOT, THEN decrease.
		if(isDefined(inc) && inc == true)
			level.sum++;
		else
			level.sum--;

		iprintln("Your current value is: "+level.sum);
	}
}
nullFew tips for coding.
1. Keep the script as short as possible.
2. Don't comment every line. Only comment portions where they may be needed to point something out.
3. Don't over complicate the script, keep it organized and easy to read.

These help you find simple errors and makes it easy to make changes.
Share |
Zelzahim
General Member
Since: Dec 31, 2008
Posts: 42
Last: Sep 23, 2010
[view latest posts]
Level 2
Category: CoD2 Scripting
Posted: Tuesday, Dec. 22, 2009 08:53 am
Thanks alot for the quick response. It worked perfectly, thank you!

Also, if you want it to increase 10 each time, how do you do it? It just increases 1.
Share |
playername
Preferred Member
Since: Aug 24, 2006
Posts: 821
Last: Apr 15, 2011
[view latest posts]
Level 7
Forum Moderator
Im a fan of MODSonair
Category: CoD2 Scripting
Posted: Tuesday, Dec. 22, 2009 09:00 am
Just replace the if part with this.

Code:
if(isDefined(inc) && inc == true)
			level.sum += 10;
		else
			level.sum -= 10;
nullFew tips for coding.
1. Keep the script as short as possible.
2. Don't comment every line. Only comment portions where they may be needed to point something out.
3. Don't over complicate the script, keep it organized and easy to read.

These help you find simple errors and makes it easy to make changes.
Share |
Zelzahim
General Member
Since: Dec 31, 2008
Posts: 42
Last: Sep 23, 2010
[view latest posts]
Level 2
Category: CoD2 Scripting
Posted: Tuesday, Dec. 22, 2009 09:12 am
Thank you yet again, sir.
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

»