Star Trek Transporter

Started by DarkMasterOz, Thu 10/08/2006 17:22:15

Previous topic - Next topic

DarkMasterOz

My game has 5 controllable characters with weird random plots and scenes, but i was wondering if its possible to do a transporter type room where 1 character has to activate a button to transport any characters that are stood on a certain hotspot? I'll break it up to bullet points again to let you know what i want doing if possible ;)
I'll make names up for characters:
Character 1: Bob
Character 2: Barry
Character 3: Ben
Character 4: Barney
Character 5: Brian

* Bob or any of ther other characters stands at a button ready to press to transport the other(s)
* Whoever is stood on the hotspot which will act as the bit they stand on, gets transported to a certain location.

Thats what i want to know how to do if possible, a bonus would be if i could have a GUI pop up when i press the button to show an icon of different places to choose, to send the characters to.

SSH

That's all very easy. To detect if a character is standing on a hotspot, you need the script function Hotspot.GetAtScreenXY., e.g.

if (cBob.Room=player.Room && Hotspot.GetAtScreenXY(cBob.x, cBob.y)==hYourHotspot) {
  cBob.Room=whatever
}

which would go in the click function of your GUI's buttons, then make whatever action it is that makes the GUI come up do: gChooseLocation.Visible=1 to make your gui visible
12

DarkMasterOz

yeh how do i add the script function "Hotspot.GetAtScreenXY" I looked in manual and it just says:

if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) == hDoor)
Ã,  Display("Mouse on the door");
else if (Hotspot.GetAtScreenXY(mouse.x, mouse.y) != hotspot[0])
Ã,  Display("Mouse is on something (but not the door)!");
else
Ã,  Display("Mouse not on a hotspot");


Which im guessing for me is changed to this, but i don't know where to put it:

if (Hotspot.GetAtScreenXY(215, 209) == hTransporter)
Ã,  Display("Mouse on the Transporter");
else if (Hotspot.GetAtScreenXY(215, 209) != hotspot[0])
Ã,  Display("Mouse is on something (but not the transporter)!");
else
Ã,  Display("Mouse not on a hotspot");



215,209 = Where my hotspot is
hTransporter = Name of my hotspot for Transporter


My hotspot where i want them to stand on to teleport is called "Transporter"
Button that one of the characters has to press to activate it is called "Transport"
Room is called "StarTrekTransporter"

I should have said i have no coding experiance too, sorry

Khris

#3
Hotspot.GetAtScreenXY(x, y) returns the hotspot at the given coordinates. It doesn't make sense to use static numbers for x and y, since you'd simply look in the room editor to find out which hotspot is at e.g. 215, 209.

First, what you want to do is the following:
-As soon as a character interacts with a certain hotspot, bring up the transporter-GUI.
-When one of the location buttons is pressed, move every character on the hotspot to that location.

The first part is easy, add a RunScript action to the hotspot's "Interact with" interaction and enter gTransporterconsole.Visible=true;
This GUI, called Transporterconsole, should be set to "popup modal".
On the GUI you'd have some buttons for the different locations and probably a cancel button.

Scriptname the buttons, then double-click them on the GUI in the editor. AGS will then add a [button's scriptname]_Click function to the global script and take you to the editor.
For each button the code entered inside the function should be something like
Code: ags
Ã,  gTransporterconsole.Visible=false;
Ã,  transport(12);
, where the number is the room's number they get beamed to.
The cancel button's function should hold only gTransporterconsole.Visible=false; to make it turn off the GUI.

Then add a function to the beginning of the global script:
Code: ags
// global script

function transport(int roomnumber) {
Ã,  int c=3;Ã,  Ã, // replace 3 with the number of the first crew char
Ã,  Character*chr;

Ã,  while(c<=8) {Ã,  Ã, // replace 8 with the number of the last crew char
Ã,  Ã,  chr=character[c];
Ã,  Ã,  if (chr.Room==player.Room && Hotspot.GetAtScreenXY(chr.x, chr.y)==hTransporter) {
Ã,  Ã,  Ã,  chr.ChangeRoom(roomnumber);
Ã,  Ã,  }
Ã,  Ã,  c++;
Ã,  }
}


When a button is pressed, this function is called and the while loop goes through all crew chars, checks whether they are in the same room and standing on the hotspot, then sends them to the other room if they do.

DarkMasterOz

I did all that, now when i go to save it says this:

Error (line 19): undefined symbol 'hTransporter'

It sends me to this line when i click fix:

if (chr.Room==player.Room && Hotspot.GetAtScreenXY(chr.x, chr.y)==hTransporter) {

I fixed the GUI bug though, "Transporterconsole" was too long, i had to rename it with other bits of code to "Transportercon"

I'm using v2.72 of AGS the latest version.

Khris

Make sure that it says "Transporter" at the hotspot's script-o-name, too.
The name will be visible in-game, the script-o-name is what's to be used by the game's creator.

AGS's auto-complete feature should pop open a small window where it says "hTransporter" as soon as you've typed "htr".

strazer

Yes. Remember, the hotspot must be called "Transporter", not "hTransporter". The h is prepended automatically by AGS.

DarkMasterOz

I did all that, it still says same error, i'll tell you everything i've done to make sure:

1) Made a GUI called "TRANSPORTERCON" and the Script O-Name says: "gTransportercon"
2) I changed the it to "Popup Modal" and where it says "On Click" its called "gTransportercon_Cli" by default
3) I double clicked the GUI and added this to the script when it popped up:

function gTransportercon_Cli(GUI *theGui, MouseButton button) {
Ã,  gTransportercon.Visible=false;
Ã,  transport(7);
}


3) I made a button with the script name "Earth" and where it says "Click" i named it "Earth_Click"
4) I double clicked the button and entered this to the script:

function Earth_Click(GUIControl *control, MouseButton button) {
}


5) I then went to Room 10 which is where my Transporter room is and made 2 hotspots
* 1) hotspot where the characters stand on to transport
* 2) hotspot where one of the characters use the machine to activate the transporter hotspot to move them to a different room.

6) Hotspot number one i typed "Transporter" in both "Name" and "Script-O-Name" <-- This is the hotspot the characters need to stand on.
7) Hotspot number two i typed "Transport" in both "Name" and "Script-O-Name" <-- This is the machine which one of the characters needs to use to bring up the GUI to pick the room to transport to.
8.) Then i clicked "Interaction..." for Hotspot 2 and made a "Run Script" for when the player "Interacts" with the hotspot. Then i put this inside the script:

gTransportercon.Visible=true;

9) Then i went to "Script" menu and selected "Edit Global Script..." and entered this:

function transport(int roomnumber) {
Ã,  int c=3;Ã,  Ã, // replace 3 with the number of the first crew char
Ã,  Character*chr;

Ã,  while(c<=8) {Ã,  Ã, // replace 8 with the number of the last crew char
Ã,  Ã,  chr=character[c];
Ã,  Ã,  if (chr.Room==player.Room && Hotspot.GetAtScreenXY(chr.x, chr.y)==hTransporter) {
Ã,  Ã,  Ã,  chr.ChangeRoom(roomnumber);
Ã,  Ã,  }
Ã,  Ã,  c++;
Ã,  }
}


Then when i go to save it, i get this error:

Error (line 19): undefined symbol 'hTransporter'

I'm obviously doing something wrong, but i can't see what.

Khris

#8
1. Remove the two lines from
function gTransportercon_Cli(GUI *theGui, MouseButton button) {
Ã,  gTransportercon.Visible=false;Ã,  // <- remove this line
Ã,  transport(7);Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, // <- and this one
}
(You don't want anything to happen if you click on the GUI, just the buttons)

2. This function
function Earth_Click(GUIControl *control, MouseButton button) {
}
should contain the two lines you've removed, because this is the function that is executed if you click on the Earth button.
Like this:
function Earth_Click(GUIControl *control, MouseButton button) {
Ã,  gTransportercon.Visible=false;
Ã,  transport(7);
}


EDIT:
Sorry, my bad.
hTransporter would only work in the room's script.
    if (chr.Room==player.Room && Hotspot.GetAtScreenXY(chr.x, chr.y)==hotspot[1]) {

DarkMasterOz

Thanks, that's got it working. Cheers for coping with my problems, now ive got it working i can add more replay value to my game plus i have a chance to link a plot together now.
Thanks  :)

SMF spam blocked by CleanTalk