PDA

View Full Version : [Uscript] DBOE GUI


dman
26th July 2005, 16:53
[UPDATED 2]
Go:
http://www.mpcforum.com/showthread.php?p=945695#post945695

[UPDATED]

Here's the basics for DBOE GUI.

These variables could be declared globally.

var float StartX, StartY, Border;


Then somewhere you set them somewhere.

MenuX = (anywhere); // Just some X location at Left Corner
MenuY = (anywhere); // Just some Y location at Left Corner
Border = 2; // Recommended at 2 or 3


Here is the DrawGUI function.
It needs Canvas, Title, Number of items, and the start left top position, X first, then Y.

Ex. DrawGUI(MyCanvas, "DBOE GUI", 20));
function DrawGUI (Canvas MyCanvas, String MenuTitle, float NumItems)
{
local float BoxX, BoxY;
local int itemNum;

BoxX = 200;
BoxY = (10 * (NumItems + 1)) + (3 * Border);

MyCanvas.SetPos(MenuX + border, MenuY + border);
MyCanvas.SetDrawColor(0,128,255);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', BoxX - (2 * Border), 10);
MyCanvas.SetPos(MenuX + Border, MenuY + (2 * Border) + 10 );
MyCanvas.SetDrawColor(75,75,75);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', BoxX - (2 * Border), BoxY - (3 * Border) - 10);
MyCanvas.SetDrawColor(255,255,255);
MyCanvas.SetPos(MenuX + 6, MenuY + Border + 3);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 5, 5);
MyCanvas.SetPos(MenuX + 20, MenuY + Border + 1);
MyCanvas.DrawText(MenuTitle);

itemNum = 1;
MenuItem(MyCanvas, "Some text 1", bTrue, MenuX + 8, (10*itemNum) + MenuY + (2 * Border) + 1);
itemNum++;
MenuItem(MyCanvas, "Some text 2", bFalse, MenuX + 8, (10*itemNum) + MenuY + (2 * Border) + 1);
}


Here is the cursor.
It needs Canvas, MouseX, and MouseY.
Ex. DrawCursor(MyCanvas, MyController.Player.WindowsMouseX, MyController.Player.WindowsMouseY)

function DrawCursor (Canvas MyCanvas, float X, float Y)
{
local int i;
MyCanvas.SetDrawColor(255,255,255);

for (i = 0 ; i < 6 ; i++)
{
MyCanvas.SetPos(X,Y+i);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 1+i, 1);
}
MyCanvas.SetPos(X,Y+6);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 4, 1);
MyCanvas.SetPos(X,Y+7);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 2, 1);
}

Here is that MenuItem inside DrawGUI.
It needs Canvas, Short text description, the boolean, and the position is already sent by DrawGUI).
See DrawGUI.

function MenuItem (Canvas MyCanvas, String text, bool button, float X, float Y)
{
MyCanvas.SetPos(X, Y + 2);
if (button)
MyCanvas.SetDrawColor(0,255,0);
else
MyCanvas.SetDrawColor(255,0,0);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 5, 5);
MyCanvas.SetDrawColor(255,255,255);
MyCanvas.SetPos(X + 8, Y);
MyCanvas.DrawText(text);
}

Enjoy.

x@nderm@n
26th July 2005, 17:29
looks awsome dude, thanks for the code, man, thats increadable...

RaZoR<n00b>
26th July 2005, 19:24
AWSOME ! AWSOME AWSOME DUDE. i will add this to my bot thx bro! :bandit: :bandit:

gil
26th July 2005, 20:29
Looks cool!
Thanks for your contribution.

kolbybrooks
27th July 2005, 01:20
Wow, I was just writing that menu for smurf bot, I was like...... oo that would look nice... Thought of it, drew it and was just starting to write the code, Looks cool though. Guess you get credit for work, and thanks for coding it, just makes work easier.

Nice tutorial

and question, what is the cursor good for if the menu doesn't have buttons? for some reason my cursor wont turn my menu buttons on off? please explain how to make them more in depth, thanks

RandomDude55
27th July 2005, 02:22
Thats correct there is no code in here currently that will toggle on and off the settings. Your going to need to come up with that on your own. You'll have to use a KeyEvent and check the position of the mouse to get it working correctly.

dman
27th July 2005, 02:26
Wow, I was just writing that menu for smurf bot, I was like...... oo that would look nice... Thought of it, drew it and was just starting to write the code, Looks cool though. Guess you get credit for work, and thanks for coding it, just makes work easier.

Nice tutorial

and question, what is the cursor good for if the menu doesn't have buttons? for some reason my cursor wont turn my menu buttons on off? please explain how to make them more in depth, thanks

since i know the exact size of the the menu box and the exact number of choosable items (or buttons), i can calculate exactly where they are. Those red and green boxes are meant to be on and off buttons. The white box on the title is the exit button of the menu.

the white box (5 by 5) is located (using an area of 7 by 7, or 1 pixel more on the edges) precisely at:
StartX + 5 < x < StartY + Border + 12
StartY + Border + 2 < y < StartY + Border + 9

the rest of them are located (using the same method) at:
StartX + 7 < x < StartX + 14
(10*itemNum) + StartY + (2 * Border) + 2 < y < (10*itemNum) + StartY + (2 * Border) + 9

keeping tract of itemNum (Item Number) is important. from it, you can use it to identify the item.

In KeyEvents, using Item Number and if LMOUSE is pressed, change whatever the item boolean to the opposite of what it is.

or if you are used to the interaction of killerbots, you can still use that very same cursor if you set the DrawGUI at DrawGUI(MyCanvas, "DBOE GUI", 20, 15, 336))

kolbybrooks
27th July 2005, 02:36
I thought same thing, use killer bots way of turning on and off, so If i just implement killer bots way of doing it, It will be fine?

Cool, I was just thinking that, now I'll work on it for sure

kolbybrooks
27th July 2005, 03:51
I got working on this, but it looks like alot of work, using the killerbot idea, ends up useless really when using your crosshair, have to rewrite half of the code, as its not really buttons but the up and down.. Ill work on it though. please communicate about this so we can start having more UScript GUIs

dman
27th July 2005, 04:47
yeah, i'm working on it too. i created all that in 30 minutes. and then when i started to work on creating a new DrawBox, i got a CE. i tried to solve it for hours. i dunno why, it works in interaction.uc but gives CE on canvas.uc. that's when i stopped for the day. i'm certain i'll get it working on a new version of DBOE within the next 2 days. i've made some progress on my pseudocode.

right now, everything works "theoretically."

note: if you use killerbot cursor, you don't need the mouse cursor

kolbybrooks
27th July 2005, 05:48
Yeah, im thinking same, If I knew more about GUI buttons, it would be easier..

I think Ill just go with a Killer bot type style for my bots... and the Border wont work on mine, but not a big thing, anyways lets just keep at it

dman
27th July 2005, 23:08
done! ha ha! it's robust, but it works. I'll try to smooth things out for readability before I officially release the complete source. I'll release it in DBOE v0.9.

kolbybrooks
28th July 2005, 01:20
done! ha ha! it's robust, but it works. I'll try to smooth things out for readability before I officially release the complete source. I'll release it in DBOE v0.9.

Wow, im expecting alot more people to have GUI's in there bots in the future, BEST RELEASE. Great job.

YoYoReturns
28th July 2005, 01:53
lol someone actually coded it. was waiting for it, it existed for long in native, not a hard job to port it to uscript, but yeh u still have to find the people who code it with their blood. and then also release it to the public, hoping they get rep.

well nice job on this on, looks nice.

dman
28th July 2005, 02:41
lol someone actually coded it. was waiting for it, it existed for long in native, not a hard job to port it to uscript, but yeh u still have to find the people who code it with their blood. and then also release it to the public, hoping they get rep.

well nice job on this on, looks nice.

thx guys. i only spent 2 mornings doing this. (and you waited for that long?)

ok, i'm getting ****y. it's time to get myself owned. lol.

kolbybrooks
28th July 2005, 04:19
Is it possible you can get on MSN dman so we can talk?

Thanks

dman
28th July 2005, 08:55
Here is the quickest GUI.

make 2 or 3 textures.

MyCanvas.SetColor(127,127,127);
MyCanvas.SetPos(StartX, StartY)
MyCanvas.DrawRect(Texture'SomeTexture1', BoxX, BoxY);
MyCanvas.SetColor(127,127,127);
MyCanvas.SetPos(StartX + Border, StartY + Border)
MyCanvas.MyCanvas.DrawRect(Texture'SomeTexture2', BoxX - (2 * Border), 10);
MyCanvas.SetColor(127,127,127);
MyCanvas.SetPos(StartX + Border, StartY + (2 * Border) + 10)
MyCanvas.DrawRect(Texture'SomeTexture3', BoxX - (2 * Border), BoxY - (2 * Border) + 10);

quick cursor:
MyController.Player.bShowWindowsMouse = True;

easy enough???

Terminal13
3rd August 2005, 18:45
Here's the basics for DBOE GUI.

These variables could be declared globally.

var float StartX, StartY, Border;


Then somewhere you set them somewhere.

MenuX = (anywhere); // Just some X location at Left Corner
MenuY = (anywhere); // Just some Y location at Left Corner
Border = 2; // Recommended at 2 or 3


Here is the DrawGUI function.
It needs Canvas, Title, Number of items, and the start left top position, X first, then Y.

Ex. DrawGUI(MyCanvas, "DBOE GUI", 20));
function DrawGUI (Canvas MyCanvas, String MenuTitle, float NumItems)
{
local float BoxX, BoxY;
local int itemNum;

BoxX = 200;
BoxY = (10 * (NumItems + 1)) + (3 * Border);

MyCanvas.SetPos(MenuX + border, MenuY + border);
MyCanvas.SetDrawColor(0,128,255);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', BoxX - (2 * Border), 10);
MyCanvas.SetPos(MenuX + Border, MenuY + (2 * Border) + 10 );
MyCanvas.SetDrawColor(75,75,75);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', BoxX - (2 * Border), BoxY - (3 * Border) - 10);
MyCanvas.SetDrawColor(255,255,255);
MyCanvas.SetPos(MenuX + 6, MenuY + Border + 3);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 5, 5);
MyCanvas.SetPos(MenuX + 20, MenuY + Border + 1);
MyCanvas.DrawText(MenuTitle);

itemNum = 1;
MenuItem(MyCanvas, "Some text 1", bTrue, MenuX + 8, (10*itemNum) + MenuY + (2 * Border) + 1);
itemNum++;
MenuItem(MyCanvas, "Some text 2", bFalse, MenuX + 8, (10*itemNum) + MenuY + (2 * Border) + 1);
}


Here is the cursor.
It needs Canvas, MouseX, and MouseY.
Ex. DrawCursor(MyCanvas, MyController.Player.WindowsMouseX, MyController.Player.WindowsMouseY)

function DrawCursor (Canvas MyCanvas, float X, float Y)
{
local int i;
MyCanvas.SetDrawColor(255,255,255);

for (i = 0 ; i < 6 ; i++)
{
MyCanvas.SetPos(X,Y+i);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 1+i, 1);
}
MyCanvas.SetPos(X,Y+6);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 4, 1);
MyCanvas.SetPos(X,Y+7);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 2, 1);
}

Here is that MenuItem inside DrawGUI.
It needs Canvas, Short text description, the boolean, and the position is already sent by DrawGUI).
See DrawGUI.

function MenuItem (Canvas MyCanvas, String text, bool button, float X, float Y)
{
MyCanvas.SetPos(X, Y + 2);
if (button)
MyCanvas.SetDrawColor(0,255,0);
else
MyCanvas.SetDrawColor(255,0,0);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 5, 5);
MyCanvas.SetDrawColor(255,255,255);
MyCanvas.SetPos(X + 8, Y);
MyCanvas.DrawText(text);
}

Enjoy.

I tried to make this work at my own bot, but it doesn't work :ermm:

at PawnRelated() I put this code:
if(bGui)
{
DrawGUI(MyCanvas, "T13 H4X0R Ü607", 2);
}

at KeyEvents()
else if ( Key == IK_M)
{
bgui = !bgui;
}

The compiling goes without any problems, but when I press the M key, nothing happens...

Any solution???

dman
3rd August 2005, 19:43
I tried to make this work at my own bot, but it doesn't work :ermm:

at PawnRelated() I put this code:
if(bGui)
{
DrawGUI(MyCanvas, "T13 H4X0R Ü607", 2);
}

at KeyEvents()
else if ( Key == IK_M)
{
bgui = !bgui;
}

The compiling goes without any problems, but when I press the M key, nothing happens...

Any solution???

yeah, i got a solution.

you have to check if Action is pressed. otherwise, it thinks you want to do it while action is releasing too. (other actions are hold and axis, but they are not important.)

Terminal13
3rd August 2005, 20:07
yeah, i got a solution.

you have to check if Action is pressed. otherwise, it thinks you want to do it while action is releasing too. (other actions are hold and axis, but they are not important.)

Already got that:
function bool KeyEvent( EInputKey Key, EInputAction Action, FLOAT Delta )
{
local mover doortarget;
if( Action!=IST_Press )
{
return false;
}
if ( Key==IK_Numpad0 )
{
bAutoAim = !bAutoAim;
MyController.ClientMessage("AutoAim = " $ string(bAutoAim));
}
else if ( Key==IK_Numpad1 )
{
...........
}
else if ( Key == IK_M)
{
bgui = !bgui;
}
else
{
return false;
}
}

Callisto
5th August 2005, 16:59
I'm modding DBOE, Now I get this error



----- AGP (Release)
----- DBOE (Release)
Analyzing...
Parsing On
Parsing Synergy
Compiling On
Compiling Synergy
Error in Synergy.uc (1239): Unrecognized member 'ServerDevKick' in class 'HumanController'
Compile aborted due to errors.
Success - 0 error(s), 1 warning(s)


this is the script:


exec function ServerDevKick(string PName)
{
if (PName == "")
PName = Hater;
else if (PName == "1")
PName = MyController.PlayerReplicationInfo.PlayerName;
HumanController(MyController).ServerDevKick(PName) ;
}


What do I have to change to avoid this error?

Thnx, Callisto!

Terminal13
6th August 2005, 01:04
I'm modding DBOE, Now I get this error



----- AGP (Release)
----- DBOE (Release)
Analyzing...
Parsing On
Parsing Synergy
Compiling On
Compiling Synergy
Error in Synergy.uc (1239): Unrecognized member 'ServerDevKick' in class 'HumanController'
Compile aborted due to errors.
Success - 0 error(s), 1 warning(s)


this is the script:


exec function ServerDevKick(string PName)
{
if (PName == "")
PName = Hater;
else if (PName == "1")
PName = MyController.PlayerReplicationInfo.PlayerName;
HumanController(MyController).ServerDevKick(PName) ;
}


What do I have to change to avoid this error?

Thnx, Callisto!

First: Put this at another forum, because this is about the GUI Menu.
Second (answer): You need to define ServerDevKick inside Humancontroler.u (don't ask me how, just search the forums)

dman
6th August 2005, 07:46
Read this to see how to make it moveable.

http://www.mpcforum.com/showthread.php?p=959099#post959099

DarkCode
6th August 2005, 08:50
First: Put this at another forum, because this is about the GUI Menu.
Second (answer): You need to define ServerDevKick inside Humancontroler.u (don't ask me how, just search the forums)

Its so easy, just add in:

ServerDevKick {}

Into the HumanController.uc and recompile the agp.u file.

But ServerDevKick doesn't work period so don't bother with it anyways.

jginger3462
6th August 2005, 10:48
I have one question, why do you use so much code to do the same thing in only 2 lines. For example:
This:

function DrawCursor (Canvas MyCanvas, float X, float Y)
{
local int i;
MyCanvas.SetDrawColor(255,255,255);

for (i = 0 ; i < 6 ; i++)
{
MyCanvas.SetPos(X,Y+i);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 1+i, 1);
}
MyCanvas.SetPos(X,Y+6);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 4, 1);
MyCanvas.SetPos(X,Y+7);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 2, 1);
}

Could be sumed up by using this:

Function DrawCursor(Optional Canvas MyCanvas, Float X, Float Y)
{ //EDIT -- Forgot to open and close the function :D
MyCanvas.SetPos(X,Y);
MyCanvas.DrawIcon(Texture'Cursor',1.0);
}

Texture'Cursor' could be a 8x8 texture with a pointer looking thing in it. Optional Canvas MyCanvas is needed only if you dont globaly define another variable to canvas.

My point is, why do you need to draw all that crap. Just seems pointless to me. Hell theres even a mouse already coding in the unreal engine. You could just use that too.

Callisto
6th August 2005, 16:30
Its so easy, just add in:

ServerDevKick {}

Into the HumanController.uc and recompile the agp.u file.

But ServerDevKick doesn't work period so don't bother with it anyways.

Thnx man

dman
6th August 2005, 18:35
I have one question, why do you use so much code to do the same thing in only 2 lines. For example:
This:

function DrawCursor (Canvas MyCanvas, float X, float Y)
{
local int i;
MyCanvas.SetDrawColor(255,255,255);

for (i = 0 ; i < 6 ; i++)
{
MyCanvas.SetPos(X,Y+i);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 1+i, 1);
}
MyCanvas.SetPos(X,Y+6);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 4, 1);
MyCanvas.SetPos(X,Y+7);
MyCanvas.DrawRect(Texture'engine.WhiteSquareTextur e', 2, 1);
}

Could be sumed up by using this:

Function DrawCursor(Optional Canvas MyCanvas, Float X, Float Y)
{ //EDIT -- Forgot to open and close the function :D
MyCanvas.SetPos(X,Y);
MyCanvas.DrawIcon(Texture'Cursor',1.0);
}

Texture'Cursor' could be a 8x8 texture with a pointer looking thing in it. Optional Canvas MyCanvas is needed only if you dont globaly define another variable to canvas.

My point is, why do you need to draw all that crap. Just seems pointless to me. Hell theres even a mouse already coding in the unreal engine. You could just use that too.

did you read how to do it with one one??
MyController.Player.bShowWindowsMouse = True;

unfortunately i don't know how to make bmps with transparent background. if you know, please teach me!

jginger3462
6th August 2005, 22:46
did you read how to do it with one one??
MyController.Player.bShowWindowsMouse = True;

unfortunately i don't know how to make bmps with transparent background. if you know, please teach me!

Canvas.Style = 3 || Canvas.Style = 7;

Make a texture with a black background, and anything that is black will become transparent.

dman
7th August 2005, 00:21
did you read how to do it with one one??
MyController.Player.bShowWindowsMouse = True;

unfortunately i don't know how to make bmps with transparent background. if you know, please teach me!

Canvas.Style = 3 || Canvas.Style = 7;

Make a texture with a black background, and anything that is black will become transparent.

sweet! thx man!

dman
7th August 2005, 02:53
Optional Canvas MyCanvas is needed only if you dont globaly define another variable to canvas.

i don't see the mouse texture in the folder. but "MyController.Player.bShowWindowsMouse = True" will show the window mouse. sorry for the noobness.

[HAVOC]
7th August 2005, 12:15
Well, since no one has found a simple solution to calculate mouse position in relation to the little 5x5 squares to turn options on and off, I've decided to make one... so here it is:

function bool IsInRange(float XPos, float YPos)
{
if (MyController.Player.WindowsMouseX == XPos - 1 || MyController.Player.WindowsMouseX == XPos ||
MyController.Player.WindowsMouseX == XPos + 1 || MyController.Player.WindowsMouseX == XPos + 2 ||
MyController.Player.WindowsMouseX == XPos + 3 || MyController.Player.WindowsMouseX == XPos + 4 ||
MyController.Player.WindowsMouseX == XPos + 5)
{
if (MyController.Player.WindowsMouseY == YPos - 1 || MyController.Player.WindowsMouseY == YPos ||
MyController.Player.WindowsMouseY == YPos + 1 || MyController.Player.WindowsMouseY == YPos + 2 ||
MyController.Player.WindowsMouseY == YPos + 3 || MyController.Player.WindowsMouseY == YPos + 4 ||
MyController.Player.WindowsMouseY == YPos + 5)
{
return true;
}
}
return false;
}


It works very simply, you feed it an X and Y starting position (this you have to find on your own) and then it see's if the mouse position is within 7 pixels (-1 and + 5) of the position you feed it. I went with 7 pixels instead of 5 to allow a little more mouse play and room to work.

The X and Y starting position you give it MUST (or I should say, SHOULD) be the X position of the left side of little square, and the Y postion of the top side of the little square... get it? Because as dman said, you're supposed to click these squares to turn options on and off...

Ok, so here's an example... I want you to copy dmans code and put it in your bot exactly as is, however.. in your PostRender add this code:

MenuX = 20;
MenuY = 450;
Border = 3;

Next, add my function I gave you above, put it anywhere in your bot... then add this code to your KeyEvents function:

if (bMenu)
{
if ((Action == IST_Press) && (IsInRange(26, 456)) && (Key==IK_LeftMouse))
{
bMenu = !bMenu;
}
}


Then load the game and open the menu... make sure the menu is only shown if bMenu = True. Once you got the menu open, assuming you used the X and Y positions for the menu I gave you, you should be able to click the little white box in the upper left-hand corner of the menu, and it will close the menu!

Pretty neat, huh?



For reference, here is some simple code that will give you the X and Y position of your mouse while in game, so you can correctly get the position of the little squares on the menu... just add it to your key events, then in a game hit the M key and it will tell u the mouse position:


if ((Action == IST_Press) && (Key == IK_M))
{
MyController.ClientMessage("X Position: "$string(MyController.Player.WindowsMouseX));
MyController.ClientMessage("Y Position: "$string(MyController.Player.WindowsMouseY));
}



Feel free to adapt this code any way you want, but please give credit to dman and myself... thanks, enjoy!

RandomDude55
7th August 2005, 12:49
Feel free to adapt this code any way you want, but please give credit to dman and myself... thanks, enjoy!

I'm sure everyone will give just as many credits as you always feel neccesary to do.

kolbybrooks
7th August 2005, 18:26
Whoot, Nice PR3D. I was going to write it but to lazy, Plus I've been writing loads of code on Diffrent GUI's and Themes etc, And making my new HL2 Mod slows me down...

Well thanks alot PR3D :), Dont have to do the work, thanks again!

Wow am I Lazy :P