Author Topic: mouse aiming and shooting script  (Read 13935 times)

mccool

  • Regular
  • **
  • Posts: 48
  • That's like trying to eat a burrito with no fork!
    • View Profile
mouse aiming and shooting script
« 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!! :) :) :) :)
Old Skool!

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: mouse aiming and shooting script
« Reply #1 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()
Edward Dassmesser

ragingmime

  • Visitor
  • *
  • Posts: 11
    • View Profile
Re: mouse aiming and shooting script
« Reply #2 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 that I started when I had some problems with a Megaman Fangame that I'd been working on.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2745
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: mouse aiming and shooting script
« Reply #3 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.

mccool

  • Regular
  • **
  • Posts: 48
  • That's like trying to eat a burrito with no fork!
    • View Profile
Re: mouse aiming and shooting script
« Reply #4 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. :)
Old Skool!

mccool

  • Regular
  • **
  • Posts: 48
  • That's like trying to eat a burrito with no fork!
    • View Profile
Re: mouse aiming and shooting script
« Reply #5 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?
Old Skool!

mccool

  • Regular
  • **
  • Posts: 48
  • That's like trying to eat a burrito with no fork!
    • View Profile
Re: mouse aiming and shooting script
« Reply #6 on: 2006-07-18, 03:51:11 PM »
also are there and sgdk games that have mouse aiming and shooting that i can play?
Old Skool!

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2745
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: mouse aiming and shooting script
« Reply #7 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.  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.

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: mouse aiming and shooting script
« Reply #8 on: 2006-07-18, 07:44:47 PM »
Outback Attack, one of the games on gamedevprj.sf.net, has mouse aiming.
Edward Dassmesser

mccool

  • Regular
  • **
  • Posts: 48
  • That's like trying to eat a burrito with no fork!
    • View Profile
Re: mouse aiming and shooting script
« Reply #9 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.
Old Skool!

mccool

  • Regular
  • **
  • Posts: 48
  • That's like trying to eat a burrito with no fork!
    • View Profile
Re: mouse aiming and shooting script
« Reply #10 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?
Old Skool!

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: mouse aiming and shooting script
« Reply #11 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.
Edward Dassmesser

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: mouse aiming and shooting script
« Reply #12 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.
Edward Dassmesser

mccool

  • Regular
  • **
  • Posts: 48
  • That's like trying to eat a burrito with no fork!
    • View Profile
Re: mouse aiming and shooting script
« Reply #13 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.
Old Skool!

mccool

  • Regular
  • **
  • Posts: 48
  • That's like trying to eat a burrito with no fork!
    • View Profile
Re: mouse aiming and shooting script
« Reply #14 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)
Old Skool!