Page 1 of 1

Scripting-Using if then

Posted: Mon Jun 25, 2007 9:04 pm
by Jaguar_jwg
Two things I would like to know.
1.
How do I use the ‘if’ ‘then’ where there are two statements in the ‘if’?
For example, I want to be able to left click the mouse and select “Zen” only when the mouse is over him.
I tried
if(self.lbutton_pressed) and NAME = "Zen"
{
for I = 1 to 5
{ RemoveText(4); }
ShowText(4, "Zen", "", "Zen Hit", FONT, "", -90, -90, "center", 255);
}
The script works if I remove ‘and NAME = "Zen”’, but you can left click anywhere on the screen.
Is there anyone out there who knows scripts well, that can help me with this please?
2.
Is there a way I can have the user input his name at the beginning of the game, so that that becomes the player’s name?

Posted: Mon Jun 25, 2007 11:03 pm
by QuestOfDreams
1.

Code: Select all

string MouseSelect(bool HighlightOnCollision);
string MouseSelect(bool HighlightOnCollision, bool PlayerIsSelectable);
string MouseSelect(bool HighlightOnCollision, bool PlayerIsSelectable, float FillColorR, float FillColorG, float FillColorB);
string MouseSelect(bool HighlightOnCollision, bool PlayerIsSelectable, float FillColorR, float FillColorG, float FillColorB, float AmbientColorR, float AmbientColorG, float AmbientColorB); 
When the mouse pointer is moved over the bounding box of an actor, this command returns the EntityName of that actor. If HighlightOnCollision is true, then the color of the pawn changes when the mouse is over the bounding box of the pawn. If PlayerIsSelectable is true, then also the player is selectable. The default value is false. FillColorR, FillColorG, FillColorB, AmbientColorR, AmbientColorG, AmbientColorB define the highlight color. This color is by default set to white (R, G, B, each between 0 ... 255)

for example

Code: Select all

NAME = MouseSelect(true, true, 200,0,0, 200,0,0);
if((self.lbutton_pressed) and (NAME = "Zen"))
{
    // your code here
}
2.
Umm, yes, you can see this in the RF default menu ... :roll:
(In the realityfactory.ini file UseNameSelect must be set to true)
You can display this name in message and conversation text by using <Player>

Posted: Tue Jun 26, 2007 3:39 am
by Jaguar_jwg
Thanks for replying so quickly. I'll check them out right away.

I am glad you responded, since my last question on scripts remain unanswered.
There is something else I wanted to know.
In the rfscriptingv1demo there is a point where the player can move the mouse to the top of the screen to display a hud with four buttons, which when pressed does something. I want to personalize this bar.
I already made my own buttons, and placed them in the hud folder, and I altered the hud .ini to recognize those buttons. However, I don't see where I can change the position or text display of the buttons.
Where do I go to alter these? Thanks

Posted: Wed Jun 27, 2007 5:48 am
by Jaguar_jwg
Thanks for the info on the previous questions. I got them working.
Can someone help me with the last question?

Posted: Thu Jun 28, 2007 12:04 am
by Spyrewolf
Question
Is there a way I can have the user input his name at the beginning of the game, so that that becomes the player’s name?
Answer
Umm, yes, you can see this in the RF default menu ...
(In the realityfactory.ini file UseNameSelect must be set to true)
You can display this name in message and conversation text by using <Player>
Ithnk quest has already answered your question dude.

Posted: Thu Jun 28, 2007 5:54 am
by Jaguar_jwg
:lol: I wasn't refering to that question.
In the rfscriptingv1demo there is a point where the player can move the mouse to the top of the screen to display a hud with four buttons, which when pressed does something. I want to personalize this bar.
I already made my own buttons, and placed them in the hud folder, and I altered the hud .ini to recognize those buttons. However, I don't see where I can change the position or text display of the buttons.
Where do I go to alter these? Thanks

Posted: Mon Jul 02, 2007 8:56 am
by Juutis
Jaguar_jwg wrote:I already made my own buttons, and placed them in the hud folder, and I altered the hud .ini to recognize those buttons. However, I don't see where I can change the position or text display of the buttons.
Where do I go to alter these? Thanks
You'll have to modify the script that handles the menu bar. It's called 'scripting_reply.s' and should be located in your 'scripts' folder.

Posted: Wed Jul 04, 2007 7:08 pm
by Jaguar_jwg
Thats it! I didn't even look there.
A Billion thanks. I was just about to directly ask the moderator for help, since I thought no one would address this. You just helped me with my big time. Thanks again.

Posted: Fri Jul 06, 2007 9:37 pm
by Jaguar_jwg
OK. I got my images in the right position, but I ran into a problem which I can't seem to get fixed.
This is the code in the scripting_reply.s:

{

// This script creates the menu bar at the top of the screen
POSX [0] // Left top corner X value where the background starts
WIDTH [32] // width of pictures used to build the inventory
NUMPICX [4] // Max number of pictures in the X direction
SPACINGX [0] // spacing between 2 pictures or from the backgound border in the X direction
SPACINGY [0] // spacing between boarder and the pictures in the Y direction
TPOSX [280] // X_Position of the menu text string
TPOSY [10] // Y_Position of the menu text string
FONT [10]

// ----------------------------------------------------------------------
// Do not touch the settings for the variables below
MPOSX [0.0] // temporary variable
IPOSX [0] // temporary variable
CHOICE [0] // the number of the selected item

// ----------------------------------------------------------------------
// Do not touch the settings for the variables below
M [8] // temporary variable
I [8] // temporary variable
K [0] // temporary variable
L [1] // temporary variable
SW [0] // ScreenWidth
SH [0] // ScreenHeight
MEM [0] //used to make a toggle button

Spawn[()
{
// Console(true);
MouseControlledPlayer(false);
LowLevel("InitMenu");
}]


InitMenu[()
{
ShowMouse(true);
self.think = "ShowMenu";
}]

ShowMenu[()
{
//Check if we need to activate the top-menu
if((GetMousePosY()<65) and (GetMousePosY()>0))
{
//Remove all buttons
for MYPIC=1 to NUMPICX+1
{ ShowHudPicture(MYPIC, false); }

//Show Menu background
ShowHudPicture(0, true, "", 0, 0, 0);

//Calculate the active button
MPOSX = ((GetMousePosX()-POSX)/(SPACINGX+WIDTH));
IPOSX = Integer(MPOSX);

if((MPOSX-IPOSX)>(SPACINGX/(SPACINGX+WIDTH)) and (IPOSX<NUMPICX) and (IPOSX>-1))
{
ShowHudPicture((IPOSX+1), true, "", POSX+SPACINGX+IPOSX*(SPACINGX+WIDTH), 0, 0);
self.think="MenuOption" # IPOSX;
}
else
{
//remove text
RemoveText(0);
self.think="ShowMenu";
}
}
else
{
//remove pictures + text
for MYPIC=0 to NUMPICX+1
{ ShowHudPicture(MYPIC, false); }

RemoveText(0);
self.think="ShowMenu";
}
}]

MenuOption0[()
{
// Check if mouse button pressed
if(self.lbutton_pressed)
{
ShowText(0, "", "", "Demo of the FillScreenArea command", FONT, "", TPOSX, TPOSY, "", 255);

if(K<201)
{
SW = GetScreenWidth();
SH = GetScreenHeight();
FillScreenArea(1, true, 255, 0, 255, 0, 0, 0, 2*K, K);
FillScreenArea(2, true, 128, 255, 0, 0, 0, SH, 2*K, SH-K);
FillScreenArea(3, true, 64, 0, 255, 255, SW-(2*K), K, SW, 0);
FillScreenArea(4, true, 255, 0, 0, 255, SW-(2*K), SH-K, SW, SH);
K=K+8;
}
}
else
{
ShowText(0, "", "", "FillScreenArea: Mouse is on Menu Option 1<CR>Press the left mouse button", FONT, "", TPOSX, TPOSY, "", 255);
for K=1 to 5
{ RemoveScreenArea(K); }

K = 0;
}

self.think="ShowMenu";
}]

MenuOption1[()
{
if(self.rbutton_pressed)
{
ShowText(0, "", "", "Right Mouse button pressed while on Menu Option 2", FONT, "", TPOSX, TPOSY, "", 255);
}
else
{
if(self.lbutton_pressed)
{
ShowText(0, "", "", "Left Mouse button pressed while on Menu Option 2", FONT, "", TPOSX, TPOSY, "", 255);
}
else
{
ShowText(0, "", "", "Press Left/Right Mouse button", FONT, "", TPOSX, TPOSY, "", 255);
}
}

self.think="ShowMenu";
}]

MenuOption2[()
{
if(self.lbutton_pressed)
{
ShowText(0, "", "", "HUD Activated", FONT, "", TPOSX, TPOSY, "", 255);
SetHudDraw(true);
}
else
{
ShowText(0, "", "", "Click left mouse button<CR>to activate the HUD", FONT, "", TPOSX, TPOSY, "", 255);
}
self.think="ShowMenu";
}]

MenuOption3[()
{
if(self.lbutton_pressed)
{
ShowText(0, "", "", "HUD Deactivated", FONT, "", TPOSX, TPOSY, "", 255);
SetHudDraw(false);
}
else
{
ShowText(0, "", "", "Click left mouse button<CR>to deactivate the HUD", FONT, "", TPOSX, TPOSY, "", 255);
}
self.think="ShowMenu";
}]

}

When I increase the the [4] in NUMPICX, the menu does not close when I move the mouse away, and I can't activate afterward. Is there another part of the code I need to alter?

Posted: Tue Jul 10, 2007 4:24 am
by Jaguar_jwg
Hmmmm... I guess I'll have to try a different method than planned.

Posted: Thu Jul 12, 2007 6:08 am
by Jaguar_jwg
:( The other method is not working out.
Could someone PLEASE HELP ME solve this problem.
It's preventing me from getting further with my plans.
I just want to increase the the [4] in NUMPICX and get it working.
PLEASE HELP.

Posted: Thu Jul 12, 2007 9:18 am
by Juutis
I'm sorry for not helping you out sooner. I just don't like debugging scripts for other people, because usually it involves testing the script in a fresh RF install. :?

Anyway, this part
if((MPOSX-IPOSX)>(SPACINGX/(SPACINGX+WIDTH)) and (IPOSX<NUMPICX) and (IPOSX>-1))
{
ShowHudPicture((IPOSX+1), true, "", POSX+SPACINGX+IPOSX*(SPACINGX+WIDTH), 0, 0);
self.think="MenuOption" # IPOSX;
}
means that there should be an order called MenuOption4 in the script, since you have 4 slots. However, there are only MenuOption1, MenuOption2 and MenuOption3 in the script. Try adding the fourth one.

Also, if you run into a problem with a script in the future, first try enabling the console (Console(true); in the first order) and see what it says.

Posted: Sat Jul 14, 2007 6:14 am
by Jaguar_jwg
Thanks. I haven't tried it yet, but that look like the solution. I really appreciate you taking the time out to help. That says a lot. I'll remember to apply what you said. Thanks Thank Thanks :D

Edit:
Yes! It's working. I just have one final question on this topic. I am trying to work it out, but having no success.
I have an hud with two rows of pictures. All the pictures on the top row are fine. However, I can't get any pictures on the second row. Could you help me do it? I think if I can get this done, I can close this chapter. Thanks

Posted: Sat Jul 14, 2007 8:23 pm
by darksmaster923
what do you mean not on the second row? like not showing up? post ur hud.ini file

Posted: Sun Jul 15, 2007 5:05 am
by Jaguar_jwg
The hud ini wouldn't help you see what I mean.
I have lets say 50 pictures 32 pixel wide and high.
I want my menu to be divided in half - 25 pictures at the top, and 25 at the bottom.
So far I have 25 positioned at the top and can select them.
Now I want to alter the script so that I have the other 25 below the other 25.
I altered parts of the script, but I think it's still missing something.

I know that I need to alter this part:
//Calculate the active button
MPOSX = ((GetMousePosX()-POSX)/(SPACINGX+WIDTH));
IPOSX = Integer(MPOSX);

if((MPOSX-IPOSX)>(SPACINGX/(SPACINGX+WIDTH)) and (IPOSX<NUMPICX) and (IPOSX>-1))
{
ShowHudPicture((IPOSX+1), true, "", POSX+SPACINGX+IPOSX*(SPACINGX+WIDTH), 0, 0);
self.think="MenuOption" # IPOSX;

...but I don't know how to do it. Can you help?