A little question

Topics regarding Scripting with Reality Factory
Lynkyn
Posts: 48
Joined: Sat Jun 21, 2008 2:17 pm

A little question

Post by Lynkyn »

How can I do that when I'm shotting, the camera moves? (I was thinking about a random) I answer this on the spanish forum, but no one knows how to do it.
But it must be something like this:

{
If (GetAttribute(''xweapon'') != 1) and (GetAttribute("xbullets") != >0) and (IsKeyDown(72))
{
self.camera_pitch + 45 }////////I want to do a random but I dont know how
}

I don't know scripting, but I think to put a Pawn camera and associate it this Script...

Can you give me some help?
Thanks and excuse me for the mistakes :wink:
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: A little question

Post by Juutis »

Fairly simple: First make the pawn detect if a weapon has been fired. The easiest way would be to look at the bullets and if they decrease, the gun must've been fired. Then you can use the TiltCamera() and RotateEntity() to rotate the camera. So, the script:

Code: Select all

if(GetAttribute("bullets","Player") < lastbullets)   //if bullets have decreased since last update
{
     RotateEntity("Player",0,random(-10,10),0);   //only rotate around Y-axis
     TiltCamera(random(-10,10)/100);                //tilt the camera. must be a very small value

     lastbullets = GetAttribute("bullets","Player");  //update 'lastbullets'
}

if(GetAttribute("bullets","Player") > lastbullets)
{
    lastbullets = GetAttribute("bullets","Player");  //update 'lastbullets' if the player receives more bullets
}
Something like this should work. 'lastbullets' is a variable that you need to add in the beginning of the script. It holds the last amount of ammo that the pawn knows. Then if the actual amount of ammo (the attribute) changes, the pawn's variable doesn't and the pawn can see if the ammo has decreased or increased. If it decreases it rotates the player and tilts the camera. If it increases it updates the variable so it keeps up with the attribute.
Pain is only psychological.
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: A little question

Post by metal_head »

Is that for a scripted player,or it can be used on the default player,by putting an invisible pan holding this script?
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: A little question

Post by Juutis »

It works with the built-in player. May work with a scripted player too, depending on how it is scripted.
Pain is only psychological.
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: A little question

Post by metal_head »

So if I want to get it working with the built in player,the script should look like this:
lastbullets [0]
bullets [0]

Code: Select all

Spawn[ ()
{	
if(GetAttribute("bullets","Player") < lastbullets)   //if bullets have decreased since last update
{
     RotateEntity("Player",0,random(-10,10),0);   //only rotate around Y-axis
     TiltCamera(random(-10,10)/100);                //tilt the camera. must be a very small value

     lastbullets = GetAttribute("bullets","Player");  //update 'lastbullets'
}

if(GetAttribute("bullets","Player") > lastbullets)
{
    lastbullets = GetAttribute("bullets","Player");  //update 'lastbullets' if the player receives more bullets
}
Return();
	}]
right? or I'm making a mistake(I'm sure about that).Sorry that I'm interfeering,but I would like something like that in my game too.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: A little question

Post by Juutis »

You'd have to execute that in low level. And you might want to hide the pawn etc. So the script would be:

Code: Select all

{
lastbullets    [0]

Spawn[ ()
{
     PawnRender(false);
     LowLevel("run");
}

run[ ()
{
     self.ThinkTime = 0.1;

     if(GetAttribute("bullets","Player") < lastbullets)   //if bullets have decreased since last update
     {
          RotateEntity("Player",0,random(-10,10),0);   //only rotate around Y-axis
          TiltCamera(random(-10,10)/100);                //tilt the camera. must be a very small value

          lastbullets = GetAttribute("bullets","Player");  //update 'lastbullets'
     }

     if(GetAttribute("bullets","Player") > lastbullets)
     {
         lastbullets = GetAttribute("bullets","Player");  //update 'lastbullets' if the player receives more bullets
     }
}

}
Also, no need for the variable 'bullets'. bullets is a player attribute and lastbullets is a variable.
Pain is only psychological.
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: A little question

Post by metal_head »

I changed the attribute from "bullets" to "pistol_shell",but when I tested the script,it didn't work.I put a Console(true); so I can see where's the problem,but the console didn't show up either. What can I be doing wrong?
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: A little question

Post by Juutis »

Oh, sorry. My bad. The orders are missing ] from the end.

Code: Select all

{
lastbullets    [0]

Spawn[ ()
{
     PawnRender(false);
     LowLevel("run");
} ]

run[ ()
{
     self.ThinkTime = 0.1;

     if(GetAttribute("bullets","Player") < lastbullets)   //if bullets have decreased since last update
     {
          RotateEntity("Player",0,random(-10,10),0);   //only rotate around Y-axis
          TiltCamera(random(-10,10)/100);                //tilt the camera. must be a very small value

          lastbullets = GetAttribute("bullets","Player");  //update 'lastbullets'
     }

     if(GetAttribute("bullets","Player") > lastbullets)
     {
         lastbullets = GetAttribute("bullets","Player");  //update 'lastbullets' if the player receives more bullets
     }
} ]

}
Pain is only psychological.
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: A little question

Post by metal_head »

Thanks a lot again,I just removed the PawnRender(false); because the console sait PawnRender method not found or something like that.

I'm thinking of putting you like a programmer in my game's credits (If you agree of course)

Just one more question:
I made a small modification in the script,actually I made it more simple:

Code: Select all

RotateEntity("Player",0,3,0);   //only rotate around Y-axis
 TiltCamera(0,10/100);

what shoul I do to make the camera tilt upwards,because after my modiffication I made it tilt left,but I want it to tilt upwards.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: A little question

Post by Juutis »

RotateEntity() tilts the camera to the left and right. TiltCamera up and down.

TiltCamera() takes only one parameter. So it should be TiltCamera(10/100); [= TiltCamera(0.1);], not TiltCamera(0,10/100);. And if I remember correctly negative values tilt the camera upwards. Not sure about that though.
Pain is only psychological.
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: A little question

Post by metal_head »

Thanks,everything is now ok!
Lynkyn
Posts: 48
Joined: Sat Jun 21, 2008 2:17 pm

Re: A little question

Post by Lynkyn »

Really thanks you!
but, maybe because I dont speak right english, maybe because I am a noob with scripts, i have another question:

If I want the script run, i must to put this?:
Pawn:
PawnType: camera (???? this is my question#1)
Scriptname: arma.s (this is the name of the script)
Spawnorder: ??? (this is my question#2 XD)

Thanks again
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: A little question

Post by metal_head »

PawnType - name of the pawn which will hold the script (mine is dinosaur) :D yes,I put a dinosaur to hold the script,little stupid...
ScriptName - the name of the script(mine is "cameratilt.s")
SpawnOrder - Spawn

I've uploaded the script,download this one and put it like that in the level and you'll see that when you shoot with the 10mm_shell,the camera will tilt up

Translated to spanish:
PawnType - nombre del peón que celebrará el script (el mío es de dinosaurio): D sí, me puso un dinosaurio para celebrar el guión, poco estúpido ...
ScriptName - el nombre del script (el mío es "cameratilt.s")
SpawnOrder - Spawn

He subido el guión, descargue éste y ponerlo al igual que en el nivel y verás que cuando se disparan con la 10mm_shell, la cámara se incline hasta
Attachments
cameratilt.rar
(429 Bytes) Downloaded 62 times
Lynkyn
Posts: 48
Joined: Sat Jun 21, 2008 2:17 pm

Re: A little question

Post by Lynkyn »

Thanks, I will change 10mm_shell for 9mm (one of my ammunitions) and try :wink:

EDIT it doesn't work. But its because I dont understand really what I must to write on Pawn Type :( dinosaur? camera? XDDDDDD
EDIT2 YEEEEEEEAH IT WORKS!! I push camera on Pawn Type and It's works! but, always the camera goes a little up.... what i must to write to do a random (left, right, up, down)

THANKS YOU VERY VERY VERY MUCH :D :D :D
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: A little question

Post by Juutis »

Lynkyn wrote:EDIT2 YEEEEEEEAH IT WORKS!! I push camera on Pawn Type and It's works! but, always the camera goes a little up.... what i must to write to do a random (left, right, up, down)
Use my version of the script. metal_head removed the random() functions in his version.

Code: Select all

{
lastbullets    [0]

Spawn[ ()
{
     LowLevel("run");
} ]

run[ ()
{
     self.ThinkTime = 0.1;

     if(GetAttribute("bullets","Player") < lastbullets)   //if bullets have decreased since last update
     {
          RotateEntity("Player",0,random(-10,10),0);   //only rotate around Y-axis
          TiltCamera(random(-10,10)/100);                //tilt the camera. must be a very small value

          lastbullets = GetAttribute("bullets","Player");  //update 'lastbullets'
     }

     if(GetAttribute("bullets","Player") > lastbullets)
     {
         lastbullets = GetAttribute("bullets","Player");  //update 'lastbullets' if the player receives more bullets
     }
} ]

}
Pain is only psychological.
Post Reply