Little help with SCRIPTED zooming? (having some problems)

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Little help with SCRIPTED zooming? (having some problems)

Post by metal_head »

I'm trying to make scripted zooming, but I'm having some problems. The script works fine (that means that the console shows no errors :D:D ), but it doesn't zoom (of course...it's made by me)
Here's the code:

Code: Select all

{
Spawn[ ()
{
Console(true);
LowLevel("zoom");
} ]

zoom[ ()
{
self.ThinkTime = 0.0;

if (IsKeyDown(12))
{
SetCameraWindow(0.5);
}|

if (IsKeyDown(12) = false)
{
SetCameraWindow(2);
HighLevel("Spawn");
}
} ]
}
So the script should check if key 12 (Backspace) is pressed and then SetCameraWindow(0.5); and then checks if key 12 is NOT pressed and sets the FOV back (the SetCameraWindow(2); is executed all the time when the key 12 is not pressed, right? How can I make it not to be executed every frame?).

Also I wanna ask about what command should I use best for zoom overlay, I can use HUD picture, Flipbook, but I want to know the best command for this.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Little help with SCRIPTED zooming? (having some problems)

Post by Juutis »

{
Spawn[ ()
{
Console(true);
LowLevel("zoom");
} ]

zoom[ ()
{
self.ThinkTime = 0.0;

if (IsKeyDown(12))
{
SetCameraWindow(0.5);
}| <-- what is this?

if (IsKeyDown(12) = false)
{
SetCameraWindow(2);
HighLevel("Spawn");
}
} ]
}
Apart from that the script should work.

There is, however, a bug in RF: The command only works if you have a weapon with zoomamount 2 or greater armed.
How can I make it not to be executed every frame?.

Code: Select all

{
zoomed  [false]

Spawn[ ()
{
Console(true);
LowLevel("zoom");
} ]

zoom[ ()
{
self.ThinkTime = 0.0;

if (IsKeyDown(12) and (zoomed = false))
{
zoomed = true;
SetCameraWindow(0.5);
}

if ((IsKeyDown(12) = false) and zoomed)
{
zoomed = false;
SetCameraWindow(2);
}
} ]
}
Pain is only psychological.
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Little help with SCRIPTED zooming? (having some problems)

Post by metal_head »

Oh, thank you som much, that has been bothering me for days (how do you know all theese things about the bugs and stuff :D )!

How didn't I think of using a variable, I now feel a little stupid.
Juutis wrote:
if (IsKeyDown(12))
{
SetCameraWindow(0.5);
}| <-- what is this?
huh..that wasn't in the script when I posted the message, strange :D


And my last question is about the overlay, I know how to do it, but what is really the best way, for example I want the overlay to stay fullscreen even when the user changes the game's resolution to a higher or lower one (the current zoom overlay does that) If I make the overlay a hud picture, it will scale down if the user changes the game's resolution. Should I use a flipbook or something else?
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Little help with SCRIPTED zooming? (having some problems)

Post by Juutis »

metal_head wrote:And my last question is about the overlay, I know how to do it, but what is really the best way, for example I want the overlay to stay fullscreen even when the user changes the game's resolution to a higher or lower one (the current zoom overlay does that) If I make the overlay a hud picture, it will scale down if the user changes the game's resolution. Should I use a flipbook or something else?
I'm struggling with the same issue on my game too. So far the best solution I've found is to have a separate image for each resolution. If only we could scale the flipbook images... :?
Pain is only psychological.
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Little help with SCRIPTED zooming? (having some problems)

Post by metal_head »

Well different images for different resolutions are OK for me, but how would the script know what is the current resolution :? ?

Oh yeah, I found another problem, the weapon won't fire while I've pressed the zoom button, is this another bug, or just someth8ing from the script that's blocking the button?
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Little help with SCRIPTED zooming? (having some problems)

Post by Juutis »

metal_head wrote:Well different images for different resolutions are OK for me, but how would the script know what is the current resolution :? ?
int GetScreenWidth();
Returns the width of the screen in pixels.

int GetScreenHeight();
Returns the height of the screen in pixels.
metal_head wrote:Oh yeah, I found another problem, the weapon won't fire while I've pressed the zoom button, is this another bug, or just someth8ing from the script that's blocking the button?
Well, the script works for me. Are you using the built-in weapons?
Pain is only psychological.
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Little help with SCRIPTED zooming? (having some problems)

Post by metal_head »

Yep, I'm using the bult- in weapos, I changed the zoom key to "Z" (just for ease) and if Z is pressed, the weapon won't fire...I made a test level with no scripts, and I found out that no weapon will fire if the Z key is pressed, so I changed the zoom key to "=" and now it's OK.
I also managed to make the script remove the HUD while zooming and then restore it back when the "=" key is released, but I got another problem:

Code: Select all

{
zoomed  [false]

Spawn[ ()
{
Console(true);
LowLevel("zoom");
} ]

zoom[ ()
{
self.ThinkTime = 0.0;

if (IsKeyDown(77) and (zoomed = false))
{
zoomed = true;
SetHudDraw(false);
DrawFlipBookImage("inferno",0,0,0,200,255,255,255,1);
SetCameraWindow(0.4);
}

if ((IsKeyDown(77) = false) and zoomed)
{
SetHudDraw(true);
zoomed = false;
SetCameraWindow(2);
}
} ]
}
The flipbook only shows for 1 frame after I've pressed the zoom key, is it possible to make it stay on screen as long as the button's pressed?

I also couldn't figure out how to remove the crosshair (because the weapon I wanna use the script on has a crosshair too) while zoomed...I looked for commands, but maybe there's no way for this to be done :(

Oh yeah, and what is the scripting name of the right mouse button, I couldn't find it, I wanna make the weapons zoom via the R mouse button.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Little help with SCRIPTED zooming? (having some problems)

Post by Juutis »

IIRC the right mouse button is key number 73.
The flipbook only shows for 1 frame after I've pressed the zoom key, is it possible to make it stay on screen as long as the button's pressed?
The following part is executed only once when you press the button, remember? To prevent the SetCameraWindow() from being executed every frame:

Code: Select all

if (IsKeyDown(77) and (zoomed = false))
{
zoomed = true;
SetHudDraw(false);
DrawFlipBookImage("inferno",0,0,0,200,255,255,255,1);
SetCameraWindow(0.4);
}
So you'll need another if-statement where you don't check the value of the 'zoomed' variable. Or alternatively, you can first check if the button is pressed and then a separate if-statement for checking the 'zoomed' variable. Something like this:

Code: Select all

zoom[ ()
{
self.ThinkTime = 0.0;

if (IsKeyDown(77))
{
    DrawFlipBookImage("inferno",0,0,0,200,255,255,255,1);

    if(zoomed = false)
    {
        SetCameraWindow(0.4);
        zoomed = true;
        SetHudDraw(false);
    }
}

if ((IsKeyDown(77) = false) and zoomed)
{
    SetHudDraw(true);
    zoomed = false;
    SetCameraWindow(2);
}
} ]

And no, I don't think there's a command for disabling the crosshair.
Pain is only psychological.
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Little help with SCRIPTED zooming? (having some problems)

Post by metal_head »

Thanks, Juutis, everything's OK now :)!

And no, I don't think there's a command for disabling the crosshair.
well than I guess I'll have to disable the crosshair and put a script that will draw a flipbook when the weapon is picked up.
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Little help with SCRIPTED zooming? (having some problems)

Post by metal_head »

Amm, I have another problem here, it's something really simple (maybe), but I can't get it working:
I'm making a sniper scope zoom too, it's a little bit different:
When you click once , it zooms, when you release the mouse, it doesn't unzoom, than when you click again it zooms even more, and than if you click one more time, it uznooms. I got it working, but I got a little speed problem, that I'm trying to slow down.If I click and hold the right mouse button, the zooming states will start cycling really fast (each one on the next frame), so I decided that I can make a variable, that decreases by 1 every frame, and than if it's value is equal or smaller than zero, the next zoom state will get triggered if the player presses the R mouse button. Now I'm not sure if this is a good idea (the one with the variable), because the variable will keep decreasing every frame, and dunno...it may cause the game to crash...or... dunno, but the fact is that it's not working, when I cklick the right mouse button for the first time, it zooms and than nevermind what I do, nothing changes, even if I switch the weapon...so the script stops somewhere, but what's stopping it?

Code: Select all

if (IsKeyDown(73) and (self.player_weapon = 6))
{
zoomagain = 10000;
self.think = "sniperzoom";
}
} ]

sniperzoom[ ()
{
zoomagain = zoomagain - 1;
DrawFlipBookImage("sniperscope",0,0,0,200,255,255,255,1);
SetCameraWindow(0.4);

if (IsKeyDown(73) and (zoomagain <= 0))
{
zoomagain = 10000;
self.think = "andagain";
}
} ]

andagain[ ()
{
zoomagain = zoomagain - 1;
DrawFlipBookImage("sniperscope",0,0,0,200,255,255,255,1);
SetCameraWindow(0.1);
if (IsKeyDown(73) and (zoomagain <= 0))
{
zoomagain = 10000;
SetHudDraw(true);
SetCameraWindow(2);
HighLevel("Spawn");
}
} ] 
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Little help with SCRIPTED zooming? (having some problems)

Post by Juutis »

I think your problem here is that you set zoomagain to 10,000 and with each frame you only decrease it by one. So if the game runs with a steady 50fps it takes 200 seconds, more than 3 minutes, to decrease the variable to zero. On top of that, making the script depend this much on the frame rate is not a good idea. You could use time instead, like between every button press the script waits for 0.5 seconds. The built-in variable self.time is useful here:

Code: Select all

if (IsKeyDown(73) and (self.player_weapon = 6))
{
zoomagain = self.time + 0.5;
SetCameraWindow(0.4);
self.think = "sniperzoom";
}
} ]

sniperzoom[ ()
{
DrawFlipBookImage("sniperscope",0,0,0,200,255,255,255,1);

if (IsKeyDown(73) and (zoomagain <= self.time))
{
zoomagain = self.time + 0.5;
SetCameraWindow(0.1);
self.think = "andagain";
}
} ]
(Tip: You should definitely move the SetCameraWindow() command inside the if-statement of the previous order so it only gets executed once)


However, what I would do is add a variable to remember if the mouse key was pressed last frame. That way you can change the zoom level when the button is actually pressed and not if it's held down. So that you have to release the button to zoom again.

Code: Select all

if (IsKeyDown(73) and (self.player_weapon = 6) and button_released)
{
button_released = false;
SetCameraWindow(0.4);
self.think = "sniperzoom";
}
} ]

sniperzoom[ ()
{
DrawFlipBookImage("sniperscope",0,0,0,200,255,255,255,1);

if (IsKeyDown(73) = false)
{
button_released = true;
}

if (IsKeyDown(73) and button_released)
{
button_released = false;
SetCameraWindow(0.1);
self.think = "andagain";
}
} ]

andagain[ ()
{
DrawFlipBookImage("sniperscope",0,0,0,200,255,255,255,1);

if (IsKeyDown(73) = false)
{
button_released = true;
}

if (IsKeyDown(73) and button_released)
{
SetHudDraw(true);
SetCameraWindow(2);
button_released = false;
HighLevel("Spawn");
}
} ] 
Pain is only psychological.
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Little help with SCRIPTED zooming? (having some problems)

Post by metal_head »

OOOH yeah, and I was thinking about timing it ... I need lessons on THINKING seriously :D
Post Reply