Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ZCommon.acs"
- // This is an on-screen mouse script written by wtg62.
- // I've written it so that it tries to match your operating system mouse sensitivity.
- // So mess with your mouse settings as you like!
- // No matter what you do, you won't experience awkward cursor movement in game!
- // Extended Menu functions/Button clicking functionality by Redxone or Lewisk3.
- // Mouse's coordinates
- // Starting values don't matter that much, but I prefer it to start in the center of the screen.
- int mx = 0.5;
- int my = 0.5;
- int mb = 0;
- // Pixels to move every tic when using keyboard to move cursor.
- int kbSpeed = 10.0;
- bool inMenu = false;
- bool debugMenu;
- // Cursor graphic
- str cursorGraphic = "cursor";
- // Menu graphics
- str menuBase = "mBase";
- str menuSelect = "mSelect";
- int optionSelected = 1;
- // ID Lists
- // 10 IDs used by Debug mode.
- // Mouse is ID: 1.
- int baseID = 30;
- int selectOverlayID = 11;
- int imagesID = 12;
- int infoID = 17;
- // Set this to the max amount of images that can be used onscreen.
- int maxImages = 5;
- int imageIndex = 1;
- // End ID list.
- int hudLayers = 30;
- str optionsDesc[5] = {
- "Spawn a deadly archvile to help you rekt all them annoying enemies! \n\n(Press confirm key)",
- "Spawn a friendly shotgunner to help you! \n\n(Press confirm key)",
- "Spawn in a SupplyDrop!",
- "Herooo, tis optian numbra for Kappa",
- "Last option woot!"
- };
- // Some of these may be not very nessesary, but this is for compatibility in the future.
- int optionPosX [5] = {5525,16985,28977,40875,53059};
- int optionPosY [5] = {7585,7585,7585,7585,7585};
- int optionWidth [5] = {6605,6605,6605,6605,6605};
- int optionHeight[5] = {20181,20181,20181,20181,20181};
- // How many clickable options per screen.
- int optionsScreen = 5;
- // Hud size. The numbers are big because I want a small cursor graphic.
- int HUDX = 960;
- int HUDY = 600;
- // Yaw scaling
- int yawMul = 5.0;
- // -- Numerical processing stuff -- \\
- // This function will take any value from 0.0 to 1.0.
- // It will then convert it to a number between 0 and the "scale" variable.
- // It will return a fixed number.
- function int fixedToPixel(int x, int scale)
- {
- // Here, I multiply 'x' by our scale to get the appropriate number.
- // However, I must round down (basically truncate digits).
- // The best way to do this is to shift our bits to the right, and back to the left.
- // This effectively rounds down for us.
- return (FixedMul(x,scale<<16)>>16)<<16;
- }
- function int fconvX(int x)
- {
- return fixedToPixel(x,HUDX)+0.1;
- }
- function int fconvY(int x)
- {
- return fixedToPixel(x,HUDY)+0.1;
- }
- function int getImageSlot (void)
- {
- // Gets next available unused image slot.
- return imagesID+imageIndex-1
- }
- // -- Drawing functions -- \\
- function void drawDescription(void)
- {
- SetFont("BIGFONT");
- HudMessage(s:optionsDesc[optionSelected-1]; HUDMSG_PLAIN, infoID, CR_WHITE , fconvX(6000),fconvY(40000),0);
- }
- function void drawImage(str img, int xpos, int ypos)
- {
- SetFont(img);
- HudMessage(s:"a"; HUDMSG_PLAIN, getImageSlot(), CR_UNTRANSLATED, fconvX(xpos), fconvY(ypos),0);
- // Increase image slot index.
- imageIndex++;
- if(imageIndex > maxImages) imageIndex = 1;
- }
- function void clearDraw(int id)
- {
- HudMessage(s:"a"; HUDMSG_FADEOUT, id, CR_UNTRANSLATED, 0, 0, 0);
- }
- function void drawSelected (void)
- {
- SetFont(menuSelect);
- switch(optionSelected)
- {
- case 1:
- HudMessage(s:"a"; HUDMSG_PLAIN, selectOverlayID, CR_UNTRANSLATED, fconvX(optionPosX[0]), fconvY(optionPosY[0]),0);
- break;
- case 2:
- HudMessage(s:"a"; HUDMSG_PLAIN, selectOverlayID, CR_UNTRANSLATED, fconvX(optionPosX[1]), fconvY(optionPosY[1]),0);
- break;
- case 3:
- HudMessage(s:"a"; HUDMSG_PLAIN, selectOverlayID, CR_UNTRANSLATED, fconvX(optionPosX[2]), fconvY(optionPosY[2]),0);
- break;
- case 4:
- HudMessage(s:"a"; HUDMSG_PLAIN, selectOverlayID, CR_UNTRANSLATED, fconvX(optionPosX[3]), fconvY(optionPosY[3]),0);
- break;
- case 5:
- HudMessage(s:"a"; HUDMSG_PLAIN, selectOverlayID, CR_UNTRANSLATED, fconvX(optionPosX[4]), fconvY(optionPosY[4]),0);
- break;
- default:
- break;
- }
- drawDescription();
- }
- function void drawMenu (void)
- {
- SetFont(menuBase);
- HudMessage(s:"a"; HUDMSG_PLAIN, baseID, CR_UNTRANSLATED, fixedToPixel(0,HUDX)+0.1, fixedToPixel(0,HUDY)+0.1, 0);
- drawSelected();
- // Menu item graphics
- drawImage("VILEP1",optionPosX[0]+optionPosX[0]/2, (optionPosY[0]*2) + 7000);
- drawImage("SPOSA1",optionPosX[1]+optionPosX[1]/5, (optionPosY[1]*2) + 7000);
- drawImage("mSupply",optionPosX[2]+optionPosX[2]/8, (optionPosY[2]*2) + 7000);
- }
- function void clearMenu (void)
- {
- // Fade out menu items.
- HudMessage(s:"a"; HUDMSG_FADEOUT, 1, CR_UNTRANSLATED, fixedToPixel(mx,HUDX)+0.1, fixedToPixel(my,HUDY)+0.1, 0);
- for(int i = 0; i <= hudLayers; i++)
- {
- HudMessage(s:"a"; HUDMSG_FADEOUT, i, CR_UNTRANSLATED, 0, 0, 0);
- }
- }
- // -- Menu logic -- \\
- Script "rv_mouseMenu" (void)
- {
- if(inMenu == true)
- {
- // Level set up, not an important part of the script at all.
- //SetMusic("");
- SetPlayerProperty(0,1,PROP_TOTALLYFROZEN);
- // Set up
- SetHudSize(HUDX,HUDY,0); // I just use these numbers for a small cursor graphic.
- drawMenu();
- }
- while(inMenu)
- {
- // Debug coordinates.
- if(debugMenu)
- {
- SetFont("SMALLFONT");
- HudMessage(s:"X: " ; HUDMSG_PLAIN, 3, CR_UNTRANSLATED, fixedToPixel(mx-7000,HUDX)+0.1, fixedToPixel(my,HUDY)+0.1, 0);
- HudMessage(d:mx ; HUDMSG_PLAIN, 4, CR_UNTRANSLATED, fixedToPixel(mx-3500,HUDX)+0.1, fixedToPixel(my,HUDY)+0.1, 0);
- HudMessage(s:"Y: " ; HUDMSG_PLAIN, 5, CR_UNTRANSLATED, fixedToPixel(mx-7000,HUDX)+0.1, fixedToPixel(my+1000,HUDY)+0.1, 0);
- HudMessage(d:my ; HUDMSG_PLAIN, 6, CR_UNTRANSLATED, fixedToPixel(mx-3500,HUDX)+0.1, fixedToPixel(my+1000,HUDY)+0.1, 0);
- HudMessage(s:"B: " ; HUDMSG_PLAIN, 7, CR_UNTRANSLATED, fixedToPixel(mx-7000,HUDX)+0.1, fixedToPixel(my+2000,HUDY)+0.1, 0);
- HudMessage(d:mb ; HUDMSG_PLAIN, 8, CR_UNTRANSLATED, fixedToPixel(mx-3500,HUDX)+0.1, fixedToPixel(my+2000,HUDY)+0.1, 0);
- HudMessage(s:"S: " ; HUDMSG_PLAIN, 9, CR_UNTRANSLATED, fixedToPixel(mx-7000,HUDX)+0.1, fixedToPixel(my+3000,HUDY)+0.1, 0);
- HudMessage(d:optionSelected ; HUDMSG_PLAIN, 10, CR_UNTRANSLATED, fixedToPixel(mx-3500,HUDX)+0.1, fixedToPixel(my+3000,HUDY)+0.1, 0);
- }
- // We need to support keybinds for keyboard look.
- // So let's check if we're using the keyboard or mouse, and then respond appropriately.
- if(mb == 1 && !(GetPlayerInput(0,INPUT_BUTTONS) & BT_ATTACK))
- {
- mb = 0;
- for(int i = 0; i <= optionsScreen; i++)
- {
- if(mx >= optionPosX[i] && mx <= optionPosX[i] + optionWidth[i] && my >= optionPosY[i] && my <= optionPosY[i] + optionHeight[i])
- {
- optionSelected = i+1;
- }
- }
- drawMenu();
- }
- if(GetPlayerInput(0,INPUT_BUTTONS) & (BT_LEFT|BT_RIGHT|BT_LOOKUP|BT_LOOKDOWN))
- {
- // Keyboard controlled cursor
- // Should be slow enough for user to be able to precisely hover over stuff.
- // 'kbSpeed' pixels per tic.
- // I use our previously set hud size to make movement speed on both axes look the same.
- if(GetPlayerInput(0,INPUT_BUTTONS) & BT_LEFT) mx -= (kbSpeed/HUDX);
- if(GetPlayerInput(0,INPUT_BUTTONS) & BT_RIGHT) mx += (kbSpeed/HUDX);
- if(GetPlayerInput(0,INPUT_BUTTONS) & BT_LOOKUP) my -= kbSpeed/HUDY;
- if(GetPlayerInput(0,INPUT_BUTTONS) & BT_LOOKDOWN) my += kbSpeed/HUDY;
- }
- else
- {
- // Mouse click
- if(GetPlayerInput(0,INPUT_BUTTONS) & BT_ATTACK){
- mb = 1;
- }
- // So here's our mouse controlled cursor.
- // Basically, these 2 variables below will take our player's yaw and pitch input and scale it.
- // Input is scaled so that our in-game "cursor" movement accurately matches operating system mouse movement.
- // 'pitchscale' is also basically multiplied by 2.
- // Why? Because pitch input is 2x slower than yaw input.
- // Check for prescaled movement
- if(!GetCVar("m_noprescale")){ yawMul = 2.5; } else { yawMul = 5.0; }
- int yawScale = FixedDiv(yawMul,FixedMul(GetCVar("m_yaw"),GetCVar("mouse_sensitivity")));
- int pitchScale = FixedDiv(5.0,FixedMul(GetCVar("m_pitch"),GetCVar("mouse_sensitivity")));
- // Now we get our delta x and delta y. 'Delta' means 'change in'. So 'change in x', and 'change in y'.
- // We'll use these to offset our current mouse position.
- int dmx = -FixedMul(GetPlayerInput(0,INPUT_YAW),yawScale);
- int dmy = -FixedMul(GetPlayerInput(0,INPUT_PITCH),pitchScale);
- // Apply our offsets.
- mx += dmx;
- my += dmy;
- }
- if(inMenu == true)
- {
- // Clamp our mouse position, so our mouse doesn't go offscreen and into the abyss forever.
- if(mx < 0) mx = 0;
- if(my < 0) my = 0;
- if(mx > 0.999) mx = 0.999;
- if(my > 0.999) my = 0.999;
- // Time to display our cursor!
- // I have to remember that we used the SetHudSize function.
- // I can't use a value from 0.0 to 1.0 for our display coordinates.
- // I have to use a value from 0.0 to 960.0 for x, and 0.0 to 600.0 for y.
- // So that's why I have my fixedToPixel function defined above!
- // I also have to add 0.1 to each of our coordinates.
- // This signals to ZDoom I want the upper left corner of my image to be at the integer part of the coordinates.
- SetFont(cursorGraphic);
- HudMessage(s:"a"; HUDMSG_PLAIN, 1, CR_UNTRANSLATED, fixedToPixel(mx,HUDX)+0.1, fixedToPixel(my,HUDY)+0.1, 0);
- Delay(1);
- }
- }
- }
- Script "toggleMenu" (void)
- {
- debugMenu = getCVar("menu_debug");
- inMenu = !inMenu;
- if(!inMenu)
- {
- // Set level music back, unfreeze player.
- SetMusic("*", 0);
- SetPlayerProperty(0,0,PROP_TOTALLYFROZEN);
- clearMenu();
- }
- ACS_NamedExecute("rv_mouseMenu",0);
- }
- Script "confirmMenu" (void)
- {
- if(inMenu)
- {
- LocalAmbientSound("misc/chat",100.0);
- delay(10);
- //ACS_NamedExecute("toggleMenu", 0);
- //delay(10);
- switch(optionSelected)
- {
- case 1:
- do {
- delay(1);
- } until (Spawn("FriendlyVile", GetActorX(0)-100.0, GetActorY(0), GetActorZ(0), 8, GetActorAngle(0) >> 8));
- //Thing_Hate(8,!0,5);
- break;
- case 2:
- do {
- delay(1);
- } until (Spawn("FriendlyShotty", GetActorX(0)-100.0, GetActorY(0), GetActorZ(0), 8, GetActorAngle(0) >> 8));
- //Thing_Hate(8,!0,5);
- break;
- case 3:
- If(!Spawn("RandomWeapon", GetActorX(0)+40.0, GetActorY(0), GetActorZ(0)+0.25, 12, GetActorAngle(0) >> 8))
- {
- ACS_NamedExecute("toggleMenu", 0);
- delay(10);
- Print(s:"No room to spawn. ");
- }
- else
- {
- Spawn("TeleportFog", GetActorX(0)+40.0, GetActorY(0), GetActorZ(0), 12, GetActorAngle(0) >> 8);
- }
- break;
- case 4:
- break;
- case 5:
- break;
- default:
- // Just in case something really gets messed up :P
- SetFont("BIGFONT");
- HudMessage(s:"Invalid selection."; HUDMSG_PLAIN, infoID, CR_WHITE , fconvX(6000),fconvY(40000),0);
- delay(35);
- clearMenu();
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement