PDA

View Full Version : How To Find a Player's Cvar Using a Menu?



Tally
28th November 2014, 12:21
Okay, I have searched but couldn't find anything. I am trying to find a certain cvar for a player using a menu. I thought I knew the method, but so far all I get is zip. Anyone advise me how to do it please?

So that there are no misunderstandings - this is for COD1. There is no method to detect when a player is ADS in COD1 (there is in UO but not COD1). When a player is ADS, it sets a client dvar "cl_run" to 1. If I can return the dvar value, I can detect if they are ADS.

Tally
28th November 2014, 15:02
bump characters 250

IzNoGoD
28th November 2014, 15:04
openmenuondvar might do the trick (in your menu), which opens another menu with a scriptmenuresponse. As for cod doesnt detect multiple responses per frame (due to waittill waiting at least one frame), you can add another exec in the original .menu file which will also give a response, would look like:


onopen
{
openmenuondvar cl_run 1 menu_run;
exec "scriptmenuresponse menu_run nope";
}

with in your onopen of menu_run:


scriptmenuresponse "yep";

This will produce either a yep or a nope scriptmenuresponse (you might wanna disable the nope for testing purposes and/or make the second scriptmenuresponse into an execnow instead due to timining issues). Another way to detect this would be to automatically query the cvar using getclientinfo(), a function build into libcod (and codextended afaik)

Disclaimer: menu files are crappy, thus the syntaxis in the snippets posted here might not be correct. Doing this purely from memory. If you find any errors, please post :)

Tally
28th November 2014, 15:27
openmenuondvar might do the trick (in your menu), which opens another menu with a scriptmenuresponse. As for cod doesnt detect multiple responses per frame (due to waittill waiting at least one frame), you can add another exec in the original .menu file which will also give a response, would look like:


onopen
{
openmenuondvar cl_run 1 menu_run;
exec "scriptmenuresponse menu_run nope";
}

with in your onopen of menu_run:


scriptmenuresponse "yep";

This will produce either a yep or a nope scriptmenuresponse (you might wanna disable the nope for testing purposes and/or make the second scriptmenuresponse into an execnow instead due to timining issues). Another way to detect this would be to automatically query the cvar using getclientinfo(), a function build into libcod (and codextended afaik)

Disclaimer: menu files are crappy, thus the syntaxis in the snippets posted here might not be correct. Doing this purely from memory. If you find any errors, please post :)

Nope, no openmenuondvar in COD1. Is there another way?

serthy
28th November 2014, 15:52
If cutom keybinds are possible in CoD1 (onOpen in menu etc.)
maybe something like this might work:
bind MOUSE2 "openscriptmenu adsmenu ads;toggle_ads";
+ monitor ads via menuresponse's
(this requires monitoring weaponswitches, spawning, everything else where ads is triggered...)

or maybe execondvarvalue exists?

IzNoGoD
28th November 2014, 16:04
it might be an uiscript openmenuondvar, although im not sure.

If it doesnt work, you're most likely confined to codextended + getuserinfo + making the cvar readable by the server (which is easy tbh)

Tally
28th November 2014, 16:51
If cutom keybinds are possible in CoD1 (onOpen in menu etc.)
maybe something like this might work:
bind MOUSE2 "openscriptmenu adsmenu ads;toggle_ads";
+ monitor ads via menuresponse's
(this requires monitoring weaponswitches, spawning, everything else where ads is triggered...)

or maybe execondvarvalue exists?

Nope. custom keybinds are out. No openscriptmenu function. That was invented in COD2. I remember there being a whole hive of activity on the forums about it when we first discovered it, and how it could be exploited.

Tally
28th November 2014, 16:52
it might be an uiscript openmenuondvar, although im not sure.

If it doesnt work, you're most likely confined to codextended + getuserinfo + making the cvar readable by the server (which is easy tbh)

Nope. there is NO openmenuondvar. The word "dvar" was not invented then. Not until 2005. And yes: I tried "cvar" instead. COD1 is basically a Quake 3 engine. If you don't find it listed on the Quake 3 resources site, then it isn't in COD1.

Tally
29th November 2014, 19:55
Okay, I came at the problem from a different direction and solved it:


attachments()
{
if( self.pers["class"] != "sniper" && self.pers["class"] != "engineer" ) return;

// wait until the player model is solid on spawn ( otherwise it will return an invalid player model )
wait( 1 );

if( !isDefined( self.thumbmarker ) )
{
self.thumbmarker = spawn( "script_origin", (0,0,0) );
self.thumbmarker linkto( self, "TAG_WEAPON_LEFT", (0,0,0) , (0,0,0) );
}

if( !isDefined( self.headmarker ) )
{
self.headmarker = spawn( "script_origin", (0,0,0) );
self.headmarker linkto( self, "TAG_HELMET", (0,0,0) , (0,0,0) );
}

self thread MonitorforADS();
}

/*
METHOD TO FIND PLAYER ADS
-------------------------
Origin of the script_origins is relative to character model's origin. So, when
the arm is raised, the thumbmarker is moving further away and so registers as true.
*/
MonitorforADS()
{
self endon( "death" );
self endon( "disconnect" );

self.isADS = undefined;
for( ;; )
{
if( isdefined( self.headmarker ) && isDefined( self.thumbmarker ) )
{
// check for stance changes because the hud elements flash on while changing
while( self getStance() != "stand" )
{
self perks\_binoculars::cleanBinocularHintHud();
wait( 1.75 );
continue;
}

// I can only find a workable distance if the player is standing
while( self getStance() == "stand" )
{
if( [[level.distance2d]]( self.thumbmarker.origin, self.headmarker.origin ) >= 17 )
self.isADS = true;
else
self.isADS = undefined;

wait( 0.05 );
}
}

wait( 0.05 );
}
}


It's a bit limited. You have to be standing still, standing, and not changing stance. But it does work, and allows me to do what I wanted to accomplish. And as far as I can tell by trawling all the old COD1 mods, I am the first to do it for COD1.