Forum

Sniper Scope

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Sniper Scope

Postby redrum » Mon Oct 20, 2008 2:28 pm

I want to add a scope to my sniper rifle.
I used stuffcmds to alter the FOV.
The problem is that when the scope is disabled I "force" the player to a FOV of 110. What if they were using an FOV of 100? or 90?
How can I reset it back to their original FOV?
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby jim » Mon Oct 20, 2008 2:52 pm

Add some oldfov to store the normal fov in it?
zbang!
User avatar
jim
 
Posts: 599
Joined: Fri Aug 05, 2005 2:35 pm
Location: In The Sun

Postby redrum » Mon Oct 20, 2008 9:24 pm

I don't think that would work.
Nowhere in the .qc files is there any reference to .fov.
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby Wazat » Mon Oct 20, 2008 9:40 pm

Well, you may be able to use some of the QC callouts to obtain the value for storing. Or maybe you can set up an alias that rotates or something. LordHavoc or someone else who knows more about the callouts available might know.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Wazat
 
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Postby frag.machine » Mon Oct 20, 2008 11:45 pm

DISCLAIMER: Not tested

1) declare a variable to store the original FOV:

Code: Select all
float oldfov;


2) store it;
Code: Select all
oldfov = cvar ("fov");


3) do your stuffcmd's to change the cvar;

4) restore the original FOV value.
Code: Select all
stuffcmd ("fov ");
stuffcmd (ftos(oldfov));
stufcmd ("\n");
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Spike » Tue Oct 21, 2008 2:41 am

frag.machine. That'll only work in singleplayer, and will fail miserably on dedicated servers.
Quite frankly there is no generic method that will work with all clients/servers.

DP has DP_QC_VIEWZOOM or whatever its actually called.
there's a .float viewzoom field which can be set to something like 0.25 to zoom in.

Or you can request the client to send you their current fov via:
stuffcmd(client, "cmd myfov $fov\n"); but that has a tendancy to break, and still isn't supported in most engines, plus you need extra code to parse the response.

dp's viewzoom feature does exactly what you want.

or you can use csqc. :P

Failing that you can ask the user to put their fov into an alias so that it can be restored after. Although this does require the user to create an 'alias restorefov "fov 90" ' alias.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Lardarse » Tue Oct 21, 2008 5:22 am

Spike wrote:frag.machine. That'll only work in singleplayer, and will fail miserably on dedicated servers.
Quite frankly there is no generic method that will work with all clients/servers.

RuneQuake removed all fov-changing recently because of this.
User avatar
Lardarse
 
Posts: 266
Joined: Sat Nov 05, 2005 1:58 pm
Location: Bristol, UK

Postby Baker » Tue Oct 21, 2008 6:43 am

Lardarse wrote:
Spike wrote:frag.machine. That'll only work in singleplayer, and will fail miserably on dedicated servers.
Quite frankly there is no generic method that will work with all clients/servers.

RuneQuake removed all fov-changing recently because of this.


FOV changing is so evil that most Quakeworld clients have a cvar called default_fov to override the terrible behavior of mods that making the silly assumption that changing your FOV back to 90 is "restoring it back to normal".

Also evil: messing with a player's r_drawviewmodel value like the original rocket arena does.

Hopefully useful information

Since it is my understanding that RedRum is probably targetting only Quakeworld clients and aside from ezQuake, FTE, FuhQuake and the occasional DarkPlaces user I *think* you can the assumption that all those clients can save cvar values.

So you might be able to do something like sending them a couple of aliases to execute upon connecting that save their FOV and then one to execute the restore when your "special effect" is completed.

A quasi example that may require some adjustment:

alias savemyfov "set savedfov $fov" // Creates savedfov with a value of their fov
alias restoremyfov "set fov $savedfov" // Send restoremyfov to set their fov back to the saved setting
savemyfov // Have it execute upon connect


Then when you want to end the changed fov, send the "restoremyfov" to the client.

This is just a theory, but I don't offhand see any reason it wouldn't work.
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby redrum » Tue Oct 21, 2008 4:36 pm

didn't quite follow all that, sounds interesting though. I'll look into it.
Yes, I'm targetting QW clients only. Thanks.
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby Baker » Tue Oct 21, 2008 5:14 pm

Try this and you'll see what I mean.

1. Load up whatever Quakeworld client you use.
2. Load a map
3. In the console, type "set myfov $fov"
4. (you just saved your fov)
5. Now type "fov 20"
6. (you just changed your fov to be really small)
7. Now type "fov"
8. (It will show it is 20, just so you can see what is going on)
9. Now type "set fov $myfov"
10. (You have just restored your FOV to the original fov you were using in step #3)

ezQuake, FTE, DarkPlaces and FuhQuake all support this.

So ...

Player X connects. You stuffcmd him "set myfov $fov" so his FOV is saved.

When you want to change his FOV, stuffcmd him "fov 20" or whatever.

When you want to store it, stuffcmd him "set fov $myfov" and it goes back to his preferred setting.

["set myfov $fov" creates temporary cvar called myfov on the client-side that saves his fov. The server can't read it but you don't care what the value is, just that you can restore that fov value when you need to which you can do by doing the reverse, "set fov $myfov".]
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby Spike » Tue Oct 21, 2008 6:54 pm

If you make some gamecode that changes the fov and run it in FTE, FTE will latch the client's cvar. Whenever you set it to 90 (the default), it'll remove the latch, when you set it to something other than 90 it'll apply the latch. The user's preference is remembered the whole time, it just won't be used. Then again, viewzoom also works in FTE.
zquake, fuhquake(thus ezquake and any number of derivatives) and qw262 all have a default_fov cvar which works in a similar way to fte's. Its just a little less automatic.
Tbh, id's qw client shouldn't be used at all...

As far as I'm aware, all the above clients other than id's support "cmd myfov $fov\n" too. Although this is risky if your client lags out. Alternatively all can use setinfo as a way to tell the server what to use as the base, but this is not automatic.


set fov $myfov stuff is an extension and can still break if the user gets booted. Considering there's a default_fov or latching in all commonly used qw engines, its not a problem (anyone using id's client probably isn't playing seriously enough to care).
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby redrum » Tue Oct 21, 2008 8:49 pm

Baker, ok I see what you mean. That sounds like it should work the way I want it to.
Can't wait to get home and try it. :)
Spike, thanks for the input!
You guys are very helpfull.
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby MeTcHsteekle » Sat Oct 25, 2008 12:23 am

DDDDDDDAAAAAAAANNNNNNYYYYYYYY!!!!!!!!>:0
bah
MeTcHsteekle
 
Posts: 399
Joined: Thu May 15, 2008 10:46 pm
Location: its a secret

Postby r00k » Sat Oct 25, 2008 5:33 am

maybe is it possible that the server calls a generic aliases

like +fovdefault, or, +fovsnipe and just let the client determine the value?

if at all the client just doesnt change.

ok maybe its late and the beer is talking ... does this make sense??
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby Wazat » Sat Oct 25, 2008 2:16 pm

Well, the beer is right. :) I don't drink, but I do things like this in my mods often.

In Conquest and Ace of Nails for example I have an autoexec.cfg that sets +mlook and then executes game.cfg. That cfg sets up the player's special commands for the mod, both aliases and bindings (B key to buy from shops, secondary fire button, etc). The Readme practically begs the player to edit game.cfg to their liking.

So, you could have a game.cfg (or just autoexec.cfg) have this alias:

// The game calls this alias to zoom in/out with the sniper scope.
// Please change 90 to be the default FOV you play with so it resets
// correctly
alias +scopezoom "fov [some zoom]"
alias -scopezoom "fov 90"


I hope that's helpful.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Wazat
 
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Next

Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest