This page was pulled into the static site from the original vBulletin thread — rescued from the Internet Archive or the vBulletin backup database after the forum upgrade made the live threads unreachable; original authorship is credited below.
Screen Resolution
1.2.0.2
By Sevion
Very efficient method of getting a player's screen resolution. Requires players to "calibrate" the screen.
V1.3.0.0 will appear with a separate module library to allow for the easier creation of dialogs (eliminates the scripters' need to multiply all values by aspect ratio).
Docs
- What Screen Resolution does:
Screen Resolution allows scripters to get a player's screen resolution and aspect ratio to easily display the correct sizes and x/y offests for dialogs and other on-screen objects.
- How Screen Resolution was made:
While making some dialogs, I got the idea that while they display correctly in my 1920 x 1080 resolution, it may not display correctly in any others. So, I tested around and was correct. With this, you just have to use the getAsPercent functions and you'll get the proper values.
- Get a player's screen properties:
- lib_sr_getResX( EventPlayer() )
- lib_sr_getResY( EventPlayer() )
- lib_sr_getRatio( EventPlayer() )
- lib_sr_isCalibrated( EventPlayer() )
- lib_sr_getXAsPercent( value, EventPlayer() )
- lib_sr_getYAsPercent( value, EventPlayer() )
Calibrate a player's screen:
lib_sr_calibrate( EventPlayer() )
//==================================================================================================
//
// Library
//
// Name: Screen Resolution
// Author: Sevion
//
//==================================================================================================
include "TriggerLibs/NativeLib"
include "Libraries/DebugMode"
//==================================================================================================
//
// System Globals
//
//==================================================================================================
static bank lib_sr__banks;
static bool lib_sr__calibrated;
static int lib_sr__resX;
static int lib_sr__resY;
static fixed lib_sr__ratio;
static bool lib_sr__gettingResolution;
static const int lib_sr__RESOLUTION_COUNT = 97;
static int lib_sr__resolutions;
//==================================================================================================
//
// System Script
//
//==================================================================================================
int lib_sr_getResX ( int whichPlayer ) {
if ( !lib_sr__calibrated ) {
if (DEBUG_MODE)
{
lib_dm_debugMsg("ERROR (Screen Resolution): Attempted to get uncalibrated Resolution Width!");
}
return -1;
}
return lib_sr__resX;
}
int lib_sr_getResY ( int whichPlayer ) {
if ( !lib_sr__calibrated ) {
if (DEBUG_MODE)
{
lib_dm_debugMsg("ERROR (Screen Resolution): Attempted to get uncalibrated Resolution Height!");
}
return -1;
}
return lib_sr__resY;
}
fixed lib_sr_getRatio ( int whichPlayer ) {
if ( !lib_sr__calibrated ) {
if (DEBUG_MODE)
{
lib_dm_debugMsg("ERROR (Screen Resolution): Attempted to get uncalibrated Resolution Ratio!");
}
return -1;
}
return lib_sr__ratio;
}
int lib_sr_getXAsPercent ( int value, int whichPlayer ) {
if ( !lib_sr__calibrated ) {
if (DEBUG_MODE)
{
lib_dm_debugMsg("ERROR (Screen Resolution): Attempted to get uncalibrated Resolution X Percentage!");
}
return -1;
}
return value / lib_sr__resX;
}
int lib_sr_getYAsPercent ( int value, int whichPlayer ) {
if ( !lib_sr__calibrated ) {
if (DEBUG_MODE)
{
lib_dm_debugMsg("ERROR (Screen Resolution): Attempted to get uncalibrated Resolution Y Percentage!");
}
return -1;
}
return value / lib_sr__resY;
}
bool lib_sr_isCalibrated ( int whichPlayer ) {
return lib_sr__calibrated;
}
bool lib_sr_getResolutions (bool testConds, bool runActions) {
int lv_x;
int lv_y;
int lv_p;
int lv_i;
int lv_temp;
if (!runActions) {
return true;
}
lv_x = EventMouseClickedPosXUI() + 1;
lv_y = EventMouseClickedPosYUI() + 1;
lv_p = EventPlayer();
lv_i = lib_sr__RESOLUTION_COUNT - 1;
lv_temp = 0;
while ( lv_i >= 0 ) {
if ( lv_x == lib_sr__resolutions && lv_y == lib_sr__resolutions ) {
lv_temp = lv_i;
lv_i = -1;
}
if ( lv_x > lib_sr__resolutions || lv_y > lib_sr__resolutions ) {
lv_temp = lv_i;
}
lv_i -= 1;
}
lib_sr__resX = lib_sr__resolutions;
lib_sr__resY = lib_sr__resolutions;
lib_sr__ratio = lib_sr__resX / lib_sr__resY;
BankValueSetFromInt(lib_sr__banks, "screenData", "resolutionX", lib_sr__resX);
BankValueSetFromInt(lib_sr__banks, "screenData", "resolutionY", lib_sr__resY);
BankValueSetFromFixed(lib_sr__banks, "screenData", "aspectratio", lib_sr__ratio);
lib_sr__gettingResolution = false;
return false;
}
void lib_sr_calibrate ( int whichPlayer ) {
trigger lv_tempTrig;
libNtve_gf_HideGameUI(false, PlayerGroupSingle(whichPlayer));
lv_tempTrig = TriggerCreate("getResolutions");
TriggerAddEventMouseClicked(lv_tempTrig, whichPlayer, c_mouseButtonLeft, true);
UIDisplayMessage(PlayerGroupSingle(whichPlayer), c_messageAreaDirective, StringToText("Please calibrate your resolution by clicking in the bottom right corner."));
lib_sr__gettingResolution = true;
while ( lib_sr__gettingResolution && PlayerGroupHasPlayer(PlayerGroupActive(), whichPlayer) ) {
Wait(0.0, c_timeGame);
}
TriggerDestroy(lv_tempTrig);
BankValueSetFromFlag(lib_sr__banks, "screenData", "lib_sr__calibrated", true);
lib_sr__calibrated = true;
UIClearMessages(PlayerGroupSingle(whichPlayer), c_messageAreaDirective);
libNtve_gf_HideGameUI(true, PlayerGroupSingle(whichPlayer));
}
//--------------------------------------------------------------------------------------------------
// Library Initialization
//--------------------------------------------------------------------------------------------------
static void lib_sr__InitVariables() {
int lv_i = 15;
while ( lv_i >= 0 ) {
lib_sr__banks = BankLoad("lib_sr__screenData", lv_i);
lib_sr__calibrated = BankValueGetAsFlag(lib_sr__banks, "screenData", "lib_sr__calibrated");
if ( lib_sr__calibrated ) {
lib_sr__resX = BankValueGetAsInt(lib_sr__banks, "screenData", "resolutionX");
lib_sr__resX = BankValueGetAsInt(lib_sr__banks, "screenData", "resolutionY");
lib_sr__resX = BankValueGetAsInt(lib_sr__banks, "screenData", "aspectratio");
}
lib_sr__gettingResolution = false;
lv_i -= 1;
}
lib_sr__resolutions = 1024;
lib_sr__resolutions = 768;
lib_sr__resolutions = 1280;
lib_sr__resolutions = 800;
lib_sr__resolutions = 1280;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 1440;
lib_sr__resolutions = 900;
lib_sr__resolutions = 1680;
lib_sr__resolutions = 1050;
lib_sr__resolutions = 1366;
lib_sr__resolutions = 768;
lib_sr__resolutions = 800;
lib_sr__resolutions = 600;
lib_sr__resolutions = 1152;
lib_sr__resolutions = 864;
lib_sr__resolutions = 1920;
lib_sr__resolutions = 1080;
lib_sr__resolutions = 1280;
lib_sr__resolutions = 768;
lib_sr__resolutions = 1600;
lib_sr__resolutions = 900;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 600;
lib_sr__resolutions = 1280;
lib_sr__resolutions = 720;
lib_sr__resolutions = 1280;
lib_sr__resolutions = 960;
lib_sr__resolutions = 320;
lib_sr__resolutions = 396;
lib_sr__resolutions = 320;
lib_sr__resolutions = 480;
lib_sr__resolutions = 1360;
lib_sr__resolutions = 768;
lib_sr__resolutions = 1600;
lib_sr__resolutions = 1200;
lib_sr__resolutions = 1400;
lib_sr__resolutions = 1050;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 640;
lib_sr__resolutions = 1152;
lib_sr__resolutions = 720;
lib_sr__resolutions = 1093;
lib_sr__resolutions = 614;
lib_sr__resolutions = 768;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 819;
lib_sr__resolutions = 1344;
lib_sr__resolutions = 840;
lib_sr__resolutions = 819;
lib_sr__resolutions = 614;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 576;
lib_sr__resolutions = 2560;
lib_sr__resolutions = 1440;
lib_sr__resolutions = 1536;
lib_sr__resolutions = 864;
lib_sr__resolutions = 1311;
lib_sr__resolutions = 737;
lib_sr__resolutions = 240;
lib_sr__resolutions = 320;
lib_sr__resolutions = 1280;
lib_sr__resolutions = 854;
lib_sr__resolutions = 960;
lib_sr__resolutions = 600;
lib_sr__resolutions = 2560;
lib_sr__resolutions = 1600;
lib_sr__resolutions = 320;
lib_sr__resolutions = 240;
lib_sr__resolutions = 1536;
lib_sr__resolutions = 960;
lib_sr__resolutions = 480;
lib_sr__resolutions = 360;
lib_sr__resolutions = 1441;
lib_sr__resolutions = 810;
lib_sr__resolutions = 640;
lib_sr__resolutions = 480;
lib_sr__resolutions = 1080;
lib_sr__resolutions = 810;
lib_sr__resolutions = 480;
lib_sr__resolutions = 320;
lib_sr__resolutions = 1249;
lib_sr__resolutions = 702;
lib_sr__resolutions = 1120;
lib_sr__resolutions = 700;
lib_sr__resolutions = 234;
lib_sr__resolutions = 282;
lib_sr__resolutions = 983;
lib_sr__resolutions = 737;
lib_sr__resolutions = 1067;
lib_sr__resolutions = 800;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 614;
lib_sr__resolutions = 1192;
lib_sr__resolutions = 670;
lib_sr__resolutions = 1067;
lib_sr__resolutions = 600;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 480;
lib_sr__resolutions = 800;
lib_sr__resolutions = 853;
lib_sr__resolutions = 533;
lib_sr__resolutions = 1600;
lib_sr__resolutions = 1000;
lib_sr__resolutions = 1600;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 911;
lib_sr__resolutions = 512;
lib_sr__resolutions = 1140;
lib_sr__resolutions = 641;
lib_sr__resolutions = 1229;
lib_sr__resolutions = 983;
lib_sr__resolutions = 1680;
lib_sr__resolutions = 945;
lib_sr__resolutions = 800;
lib_sr__resolutions = 480;
lib_sr__resolutions = 1229;
lib_sr__resolutions = 768;
lib_sr__resolutions = 480;
lib_sr__resolutions = 854;
lib_sr__resolutions = 1525;
lib_sr__resolutions = 857;
lib_sr__resolutions = 1382;
lib_sr__resolutions = 864;
lib_sr__resolutions = 1170;
lib_sr__resolutions = 936;
lib_sr__resolutions = 983;
lib_sr__resolutions = 576;
lib_sr__resolutions = 1143;
lib_sr__resolutions = 857;
lib_sr__resolutions = 1120;
lib_sr__resolutions = 840;
lib_sr__resolutions = 1058;
lib_sr__resolutions = 595;
lib_sr__resolutions = 2048;
lib_sr__resolutions = 1152;
lib_sr__resolutions = 853;
lib_sr__resolutions = 683;
lib_sr__resolutions = 922;
lib_sr__resolutions = 691;
lib_sr__resolutions = 240;
lib_sr__resolutions = 160;
lib_sr__resolutions = 2560;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 1613;
lib_sr__resolutions = 1008;
lib_sr__resolutions = 360;
lib_sr__resolutions = 640;
lib_sr__resolutions = 936;
lib_sr__resolutions = 702;
lib_sr__resolutions = 1088;
lib_sr__resolutions = 614;
lib_sr__resolutions = 1117;
lib_sr__resolutions = 894;
lib_sr__resolutions = 360;
lib_sr__resolutions = 480;
lib_sr__resolutions = 1350;
lib_sr__resolutions = 844;
lib_sr__resolutions = 1152;
lib_sr__resolutions = 870;
lib_sr__resolutions = 1440;
lib_sr__resolutions = 960;
lib_sr__resolutions = 683;
lib_sr__resolutions = 512;
lib_sr__resolutions = 1080;
lib_sr__resolutions = 633;
lib_sr__resolutions = 1069;
lib_sr__resolutions = 855;
lib_sr__resolutions = 1317;
lib_sr__resolutions = 823;
lib_sr__resolutions = 1365;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 1350;
lib_sr__resolutions = 1080;
lib_sr__resolutions = 819;
lib_sr__resolutions = 480;
lib_sr__resolutions = 1170;
lib_sr__resolutions = 731;
lib_sr__resolutions = 1017;
lib_sr__resolutions = 572;
lib_sr__resolutions = 1024;
lib_sr__resolutions = 1280;
lib_sr__resolutions = 1117;
lib_sr__resolutions = 698;
lib_sr__resolutions = 1519;
lib_sr__resolutions = 949;
lib_sr__resolutions = 854;
lib_sr__resolutions = 480;
lib_sr__resolutions = 1300;
lib_sr__resolutions = 2300;
lib_sr__resolutions = 1276;
lib_sr__resolutions = 733;
}
static bool lib_sr__InitLib_completed = false;
void lib_sr_InitLib() {
if (lib_sr__InitLib_completed) {
return;
}
lib_sr__InitVariables();
lib_sr__InitLib_completed = true;
}
Change Log
1.0.0.0 wroteInitial Release
1.0.0.1 wroteFixed a minor bug on calibration boolean not saving
1.0.0.2 wroteFixed a minor bug on array initialization.
1.1.0.0 wroteAdded the misclick algorithm.
1.2.0.0 wroteChanged function names and added Dialog module.
Added a bunch of resolutions. Ninety-seven in total now. All from here and listed from most common to least common.
Added lib_sr_getXAsPercent ( value, EventPlayer() ) and lib_sr_getYAsPercent( value, EventPlayer() ).