Page 1 of 1

Script not working in cj

Posted: March 20th, 2011, 11:43 pm
by B4.
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;
    }
}

Re: Script not working in cj

Posted: March 21st, 2011, 1:28 am
by Drofder2004
Define your entity first.
ent = getent("watertrigger","targetname");

Then you can use the entity in the code.
isTouching(ent)

Re: Script not working in cj

Posted: March 21st, 2011, 6:10 am
by B4.
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; 
   }
}

Re: Script not working in cj

Posted: March 21st, 2011, 1:14 pm
by Drofder2004
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;
}

Re: Script not working in cj

Posted: March 21st, 2011, 7:07 pm
by IzNoGoD
please use !player.isdrowning instead of player.isdrowning==false
Its less coding xD

Re: Script not working in cj

Posted: March 21st, 2011, 8:12 pm
by Rezil
IzNoGoD wrote:please use !player.isdrowning instead of player.isdrowning==false
Its less coding xD
Semantics semantics.

Re: Script not working in cj

Posted: March 21st, 2011, 9:01 pm
by IzNoGoD
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")))

Re: Script not working in cj

Posted: March 22nd, 2011, 3:56 am
by Drofder2004
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:

Re: Script not working in cj

Posted: March 22nd, 2011, 3:49 pm
by B4.
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.