Script not working in cj

Have questions about CoD4 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
User avatar
B4.
CJ Newbie
CJ Newbie
Posts: 81
Joined: September 5th, 2010, 7:01 am
Location: Australia

Script not working in cj

Post by B4. » March 20th, 2011, 11:43 pm

When i started this gsc I got it to working in tdm, now im using the cj mod to test map, teleports and pop up messages they are not working, ive tried a few different ways now and still get nothing to work.

Did have a problem with the "while(player isTouching("watertrigger", "targetname"))" as it didnt stop looping after you moved out of the trigger.

Also wondering if any1 knows how they did the timed drowning in lighthouse? was it a counter on the loop then player suicide()?
But how would you put the progress bar in?

Start and finish messages are once only and the water and teleports are multiple.

This is my first time at cod scripting so learning on the go, not sure if there is different references between tdm and cj with mods

Code: Select all

main()
{
   
	maps\mp\_load::main();

	//maps\mp\_compass::setupMiniMap("compass_map_mp_valley");

	VisionSetNaked( "mp_valley" );
	ambientPlay("ambient_valley");

	game["allies"] = "sas";
	game["axis"] = "russian";
	game["attackers"] = "axis";
	game["defenders"] = "allies";
	game["allies_soldiertype"] = "woodland";
	game["axis_soldiertype"] = "woodland";

	setdvar( "r_specularcolorscale", "1" );

	thread starttrigger();
	thread portal1trigger();
	thread portal2trigger();
	thread watertrigger();
	thread finishtrigger();

}

starttrigger()
{
	trig1 = getEnt("starttrigger", "targetname"); 
	while(1)
   {	
	trig1 waittill("trigger", player); 
	player iprintlnbold("Welcome to mp_valley");
	wait 0.1;
    }
}

portal1trigger()
{
	trig2 = getEnt("portal1trigger", "targetname"); 
	while(1)
    {
	trig2 waittill("trigger", player); 
	org = (680,32,26); 
	wait 0.1;
	player setOrigin(org, 0.1);
    }
}

portal2trigger()
{
	trig3 = getEnt("portal2trigger", "targetname"); 
	while(1)
    {
	trig3 waittill("trigger", player); 
	org = (800,32,960); 
	wait 0.1;
	player setOrigin(org, 0.1);
    }
}

watertrigger()
{
	trig4 = getEnt("watertrigger", "targetname"); 
	trig4 waittill("trigger", player); 
	
	while(player isTouching("watertrigger", "targetname")) 
	{
		player iprintlnbold("You are drowning!");
		wait 1; 
	}
}

finishtrigger()
{
	trig5 = getEnt("finishtrigger", "targetname");
	while(1)
   {	
	trig5 waittill("trigger", player);
	player iprintlnbold("Congradulations!!!!");
	wait 0.1;
    }
}

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13315
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Script not working in cj

Post by Drofder2004 » March 21st, 2011, 1:28 am

Define your entity first.
ent = getent("watertrigger","targetname");

Then you can use the entity in the code.
isTouching(ent)
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
B4.
CJ Newbie
CJ Newbie
Posts: 81
Joined: September 5th, 2010, 7:01 am
Location: Australia

Re: Script not working in cj

Post by B4. » March 21st, 2011, 6:10 am

No luck,
Used the trig4 to do it.

Code: Select all

watertrigger()
{
   trig4 = getEnt("watertrigger", "targetname"); 
   
   trig4 waittill("trigger", player); 
   
   while(player isTouching(trig4)) 
   {
      player iprintlnbold("You are drowning!");
      wait 1; 
   }
}

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13315
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Script not working in cj

Post by Drofder2004 » March 21st, 2011, 1:14 pm

The problem with this code is that it will only work once.
Another problem you will see is that only one person can "drown" at the same time.

Try the following (untested).

Code: Select all

watertrigger()
{
   water = getEnt("watertrigger", "targetname"); 
   
   while(1)
   {
      water waittill("trigger", player);
      if(!isDefined(player.drowning) || player.drowning == false)
         player thread drown(water);
   }
}

drown(water)
{
   self.drowning = true;
   while(self isTouching(water))
   {
      self iprintlnbold("You are drowning!");
      wait 1;
   }
   self.drowning = false;
}
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: Script not working in cj

Post by IzNoGoD » March 21st, 2011, 7:07 pm

please use !player.isdrowning instead of player.isdrowning==false
Its less coding xD
LMGTFY!

Its not a glitch... Its the future!

User avatar
Rezil
Core Staff
Core Staff
Posts: 2030
Joined: July 24th, 2006, 11:21 am
Location: Cramped in a small cubicle/making another jump map

Re: Script not working in cj

Post by Rezil » March 21st, 2011, 8:12 pm

IzNoGoD wrote:please use !player.isdrowning instead of player.isdrowning==false
Its less coding xD
Semantics semantics.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: Script not working in cj

Post by IzNoGoD » March 21st, 2011, 9:01 pm

Sematics start to matter when you use code like:

Code: Select all

						smallforward=anglestoforward(spreadangles);
						forward=maps\mp\_utility::vectorscale(smallforward,10000);
						point=self geteyepos();
						point=point-maps\mp\_utility::vectorscale(smallforward,vectorDot((self.origin[0],self.origin[1],0)-(point[0],point[1],0),smallforward));
						point=bullettrace(point,point-maps\mp\_utility::vectorscale(smallforward,20),false,undefined)["position"];
						trace[0]=bullettrace(point,point+forward,true,self);
and

Code: Select all

					if(usebcount<7)
					{
						if(!hassprinted&&self.oldorigin!=self.origin&&self.sprinttime>level.sprinttime/4&&self getstance()=="stand"&&!self isholdingnade()&&!self issniping())
							usebcount++;
					}
					else
					{
						if(!hassprinted&&self.oldorigin!=self.origin&&!self attackbuttonpressed()&&self.sprinttime>level.sprinttime/4&&self getstance()=="stand"&&!self isholdingnade()&&!self issniping())
						{
							self.sprinting=true;
							hassprinted=true;
							usebcount=0;
							self thread sprint();
						}
					}
First code isnt working correct yet though :(

Edit: fixed the first code, finally, after 3 months.
Seemed like the bug of firing thru thick walls is caused by those wall being friggin HOLLOW!!!!

now my longest line is:

Code: Select all

while(i<10&&!isplayer(trace[i]["entity"])&&remainingwall>0&&trace[i]["fraction"]<1&&distance(trace[i]["position"],point)<maxrange(weap)&&!canbedamaged(trace[i]["entity"])&&isdefined(trace[i]["surfacetype"])&&trace[i]["surfacetype"]!="default"&&(i==0||(isdefined(traceback[i]["surfacetype"])&&traceback[i]["surfacetype"]!="default")))
LMGTFY!

Its not a glitch... Its the future!

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13315
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: Script not working in cj

Post by Drofder2004 » March 22nd, 2011, 3:56 am

IzNoGoD wrote:please use !player.isdrowning instead of player.isdrowning==false
Its less coding xD
When 2 bytes becomes a crucial amount of difference in file size, I will change my coding... before that happens, I will continue to use a coding preference that is more universal amongst languages and easier to read back later on.

Having good looking coding is not greater than having easier to understand coding :)

---
And seriously, this is not a matter of semantics at all. This is programming not English.

If method one works EXACTLY the same as method 2, then neither is superior. The code is intepreted by an engine, the engine is not judging you on your choice of words, all the engine cares for is that it can be read.
The only matter that is considered in programming is etiquette, which is a matter for personal taste, not a judgement on ability. The way you have written your code above goes against the etiquette I would use if I were to code it myself.

:roll:
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

User avatar
B4.
CJ Newbie
CJ Newbie
Posts: 81
Joined: September 5th, 2010, 7:01 am
Location: Australia

Re: Script not working in cj

Post by B4. » March 22nd, 2011, 3:49 pm

Thanks
I'll give it a go in the mornin.

Ill go with the style layed out the best on the eyes, comps dont care what it looks like but we've got to be able to read and debug without going blind from eye strain.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests