Scrolling Game Development Kit Forum

SGDK Version 1 => Script => Topic started by: mccool on 2006-06-16, 11:00:19 AM

Title: mouse aiming and shooting script
Post by: mccool on 2006-06-16, 11:00:19 AM
im new to scripting so be simple :). How do i get the code into my game? do i copy and paste it? do i still have to costomize it to make it fit my game? wouldnt a script act different in every game? (sorry for all the questions, im confused.)

All i want to do is make a game that when u aim the mouse the players gun will move too. and when u click the player will shoot!

Thanks for the help!! :) :) :) :)
Title: Re: mouse aiming and shooting script
Post by: durnurd on 2006-06-16, 03:17:46 PM
Any code you wish to use should be saved as a .vbs file.  Putting it in the same directory as your .gdp file is a good idea.  Once you've created the script, connect it to the game from the settings dialog accessed by pressing the "Key" button in the toolbar at the top and browsing for your script in the Script box.

You will, of course, have to customize almost any script to point to the objects (maps, sprites, etc.) that you are using.  Here's a script to get you started (found elsewhere on the forum).  This will take the first sprite defined on the first layer of the current map and move it with the mouse.  Change MapLayer(0) to MapLayer(X) where X is the numerical index of the layer your targeting reticle is on counting from 0, from the top down, and change Sprite(0) to Sprite(X) where X is the numerical index of the targeting reticle sprite on that layer.  If it's the first or only one, leave it at 0.

Code: [Select]
Sub Display_MouseMove(Button, Shift, X, Y)
With ProjectObj.GamePlayer
  .rMap.MapLayer(0).Sprite(0).X = X + .MapScrollX - .rMap.ViewLeft
  .rMap.MapLayer(0).Sprite(0).Y = Y + .MapScrollY - .rMap.ViewTop
End With
End Sub

HostObj.SinkObjectEvents CurrentDisplay, "Display"
HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
Title: Re: mouse aiming and shooting script
Post by: ragingmime on 2006-06-20, 09:29:20 PM
If you need more of the gory details on how to get mouse aiming/shooting working, check out this thread (http://gamedev.comdel.net/index.php?topic=725.0) that I started when I had some problems with a Megaman Fangame (http://http://s15.invisionfree.com/Rockman_Nova) that I'd been working on.
Title: Re: mouse aiming and shooting script
Post by: bluemonkmn on 2006-06-21, 05:27:57 AM
So, off topic a bit, is the game you refer to a GameDev Game or a Game Maker game?  Did you switch engines part way through?  It looks like the current discussion on your forum is about Game Maker.
Title: Re: mouse aiming and shooting script
Post by: mccool on 2006-06-26, 01:07:17 PM
my game is a gamedev project. i actually tried gamemaker but didn't like it as much. :)
Title: Re: mouse aiming and shooting script
Post by: mccool on 2006-07-18, 03:47:55 PM
Just give me the script id need and tell me how to customize it.
Also do u know any good books or websites where i can learn how to write scripts that wud work 4 this program?
Title: Re: mouse aiming and shooting script
Post by: mccool on 2006-07-18, 03:51:11 PM
also are there and sgdk games that have mouse aiming and shooting that i can play?
Title: Re: mouse aiming and shooting script
Post by: bluemonkmn on 2006-07-18, 05:03:24 PM
Well, I have a test project that's not really worth playing, but it can show you how to implement mouse aiming and shooting.  It's at http://gamedevprj.sourceforge.net/files/Asteroid.zip (http://gamedevprj.sourceforge.net/files/Asteroid.zip).  As soon as you drive the car into the little thing at the beginning or into the large ship at the end of the initial map, you will be teleported to a level where you can move and click the mouse to shoot asteroids.
Title: Re: mouse aiming and shooting script
Post by: durnurd on 2006-07-18, 07:44:47 PM
Outback Attack, one of the games on gamedevprj.sf.net, has mouse aiming.
Title: Re: mouse aiming and shooting script
Post by: mccool on 2006-09-04, 03:43:44 PM
i tried to download the odd sample game with the car , and it works except for the mouse doesnt control the aimer.
Title: Re: mouse aiming and shooting script
Post by: mccool on 2006-09-04, 04:36:34 PM
refering to the 2nd post in this topic)  how do i save the scripts shown on this webside (in the blue boxes) as vbs files?
Title: Re: mouse aiming and shooting script
Post by: durnurd on 2006-09-04, 07:31:21 PM
You have to select them and copy them manually (with the mouse / keyboard ([CTRL]+C to copy) and paste it in to notepad and save it as a VBS file.
Title: Re: mouse aiming and shooting script
Post by: durnurd on 2006-09-04, 07:34:28 PM
i tried to download the odd sample game with the car , and it works except for the mouse doesnt control the aimer.

Make sure you run the game as a shortcut from the desktop rather than from within GameDev.  Scripts don't run unless you run it externally.
Title: Re: mouse aiming and shooting script
Post by: mccool on 2006-09-05, 01:50:11 PM
ok thanks ill try that. im so happy that you guys are so helpful. it make the entire SGDK system so much more enjoyable.
Title: Re: mouse aiming and shooting script
Post by: mccool on 2006-12-18, 07:49:38 PM
(wow, i'm bad at this) how do i save it as a .vbs file? if i copy and paste it onto microsoft word, they dont let me save it as a .vbs file. (i cant believe i asked that)
Title: Re: mouse aiming and shooting script
Post by: eric22222 on 2006-12-18, 08:22:51 PM
Did you manually type the extension ".vbs" into the save box? I know for notepad, you have to actually save it as something like "script.vbs".

If that doesn't work, just CTRL-A, CTRL-C, and then CTRL-V into notepad and save it from there.
Title: Re: mouse aiming and shooting script
Post by: durnurd on 2006-12-18, 08:47:38 PM
Yeah, never, ever use MS word as a text editor for script files such as .vbs files.  It really screws things up.  Just use Notepad if you're running windows, and use the Save As command.  When the Save As window comes up, from the "Save as type" dropdown list, select "All Files" then as the file name, type "[whatever].vbs" (no quotes) and hit save
Title: Re: mouse aiming and shooting script
Post by: bluemonkmn on 2006-12-19, 06:28:57 AM
... and let me re-emphasize the part where you select "All Files".  This is important in Windows' default configuration because if you don't do that, Notepad will add the .TXT extension after the .VBS extension, and in Windows' default configuration, you won't see that it did that because it hides extensions for all known file types.  I don't know why they ever did that.  It just made things worse in my mind (it's even a security risk).  It's always the first thing I turn off when I come to a new Windows installation.
Title: Re: mouse aiming and shooting script
Post by: bat on 2006-12-21, 01:09:01 AM
hey, i don't get VBS, even though im a hardcore Ti-basic and Dark-basic fan, but i think you can just rename the extention...?
Title: Re: mouse aiming and shooting script
Post by: bluemonkmn on 2006-12-21, 06:58:35 AM
Yes, after the file is saved, if it has the wrong extension, you can correct it, but only if you can see it (if Windows is showing extensions for all files).  But that also only works properly if the file was saved in the correct format.  If it was saved by Notepad it's surely in the correct format, but if it was saved by Word or Wordpad, there's a good chance it was saved in something that's going to look like garbage to Notepad and GameDev.
Title: Re: mouse aiming and shooting script
Post by: bat on 2007-01-27, 12:43:10 AM
don't worry MCCOOL, even the most highly respected people have to start as a noob...(don't take that wrong...im a noob!) one thing i really like about this forum and the SGDK is that the flamers are very minimal and theres not really any dumb Q's
Title: Re: mouse aiming and shooting script
Post by: bat on 2007-01-27, 12:46:49 AM
ooo ooo!
to turn off the "hide extentions thing"
just open mycomputer, click tools-> folder options-> and uncheak "hide known extentions"
Title: Re: mouse aiming and shooting script
Post by: SmartBoy16 on 2007-08-15, 10:39:18 AM
you can also while youre saving a file from notepad, where it says "Save as type: (combo box)Text Document" Select all files and put the ".vbs" after the filename. Hope this helps.

ooo ooo!
to turn off the "hide extentions thing"
just open mycomputer, click tools-> folder options-> and uncheak "hide known extentions"

this only works for Windows Me and above. for windows 95/98/98se you need to go to View->Folder Options...