Jump to content

FPS script


megigames
 Share

Recommended Posts

how would i go about making a first person shooter script with weapon pickup and interchangeable models for guns

oh and if anyone knows how to make a reload that would be great :o

 

also if you want to share a script so i can learn that'd be nice

 

i also am willing to pay for scripts :)

Link to comment
Share on other sites

Are you talking about a lua script or c++ code?

Tools:

AC3D | 3D Canvas(pro) | Texture Maker(pro) | Genetica(basic) | 3D World Studio | Fragmotion |Leadwerks 2 | XNA 4 | Visual Studio 2010 Professional | XCode 5.x |UU3D Pro

 

Programing & Scripting Languages:

C |C++ | C# | Obj-C | LUA | Javascript | PHP | Ruby

Link to comment
Share on other sites

Leadweks comes with a lua script that dose some of the things you want; you should start there it is located in the ledwerks folder under scripts then games.

 

reload is resonably simple you could do somthing like this:

int iAmmoInClip = 20;
int iClip = 2;
int iAmmoPerClip = 20;



//main loop
while( !KeyHit(KEY_ESCAPE) ){

	//Checking if we hit the Left mouse button and making sure we have ammo.
	if(MouseHit(1) && iAmmoInClip > 0){
		//Place Shooting code Here
		iAmmoInClip --;

	}	

	//if we are out of ammo in our clip auto reload
	if(iAmmoInClip <= 0 && iClip > 0 ){
		iClip --;
		iAmmoInClip = iAmmoPerClip;
	} 

	//if we Hit the R key and have a xtra clip reload 
	if(KeyHit(KEY_R) && iClip > 0 ){
		iClip --;
		iAmmoInClip = iAmmoPerClip;
	} 



}

Tools:

AC3D | 3D Canvas(pro) | Texture Maker(pro) | Genetica(basic) | 3D World Studio | Fragmotion |Leadwerks 2 | XNA 4 | Visual Studio 2010 Professional | XCode 5.x |UU3D Pro

 

Programing & Scripting Languages:

C |C++ | C# | Obj-C | LUA | Javascript | PHP | Ruby

Link to comment
Share on other sites

Well.. I haven't done it before in leadwerks myself but the concept is the same for any engine.

 

Sorry if none of this makes sense. I'm tired.

 

Player:

1. Player Controller

2. Attach camera to controller

3. code the mouse movement to for rotating the camera

4. code the wasd to move the controller foreward /back left /right

 

Shooting:

 

2-ways:

 

-Raycasting <-- personally I don't like this way

 

-Bullet Body

1. On click -> create bullet with a body at the gun nozel

2. Apply velocity to the bullet body in the same direction as the camera is facing (or gun)

 

Reloading: <--

On press 'R'

2. Check that ammo is not full

3. If not check how much ammo you need to fill the magazine (eg. cartridge size of 8 with only 3 bullets left = 8-3 = 5 bullets needed)

4. If the ammo you have in your 'pocket' is greater than 5 (what you need to fill the magazine.

: Play Reload animation |||| cartridge ammo = 8, ||| ammo = ammo -5 |||

5. else if the ammo you have in your pocket is less than 5 but more than 0 (say 3 )

: Play Reload animation |||cartridge ammo = cartridge ammo + ammo ||| ammo =0 (resulting in cartridge ammo being 6 and total ammo 0

6. else if the ammo you have in your pocket is 0

: notify the player that they cannot reload .

simple

 

Ammo Pickups:/u]

These are really simple you just detect a collision between ammo box and player, get the entity from that and add the ammo to your stash according to what you collided with.

 

Interchangable Weapons

IDK how everyone else does it but I figured out a way in the last engine I was using. The idea should still work here.

 

first I made a bunch of arrays that held all the stats for all of the weapons. It looked something like this. (This is just psuedo btw)

 

std::string WeaponName["Colt 45", "Socom", "FAMAS", "12 Guage"];

std::string WeaponModel["Colt.gmf", "Socom.gmf", "FAMAS.gmf", "12 Guage.gmf"];

int WeaponRange[ 45, 50, 200, 25 ];

std::string WeaponDamage etc

etc

etc

etc

etc

etc

 

Then I made an integer variable called 'currentWeapon' which started at 0. When you press the button to switch weapon the currentWeapon variable changes and and loads the stats of the corresponding gun in the array. EG. currentWeapon = 2 would be the FAMAS & currentWeapon = 0 would be the Colt 45.

 

Anyway this was just some stupid method I came up with dunno if its technically the correct way to do it but it works.

 

 

 

Everything here can be found in the existing tutorials on the wiki.

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

How do you tell the bullet to go in the direction the camera is facing?

 

Anyway you want. Line pick raycast comes to mind. Then just get the position of the collision and move the bullet from the guns to the position that the raycast hit.

 

Yeh the way I said the camera facing direction wasn't technically correct but I wrote that In a rush so yeh :) rather get the position of to propell towards using a raycast.

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Thre is the "LESoldierEntityAndGame" script that you can find in the asset store, that contains lot of usefull stuff.

 

I just found it today, and it really contains all Lua stuff for begin some gameplay and entities management !

 

For FPS and all stuff i don't have any idea unfortunately !

Stop toying and make games

Link to comment
Share on other sites

  • 4 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...