Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / weapon arrays in DBPro

Author
Message
Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 21st Oct 2005 07:45 Edited at: 21st Oct 2005 07:51
I am adding multiple weapons in my FPS and I was wondering how I could make it so that when you begin the game, you are unarmed. When you are unarmed, a limb is created close to you and you have to be close to the enemy to hurt him. When you pick up a crate containing a weapon (sniper rifle for example) your limb is placed extremely further than from when you were unarmed. You can then shoot the enemy from a distance. You will also have the ability to toggle between weapons (unarmed and sniper rifle).
My question is, can I store each weapon in an array, and set the program to place your limb for enemy intersection at a certain distance based on which weapon is currently equipped, then delete it when you change weapons, and then recreate it again? I'm not exactly sure how to do this though. I was thinking, putting something like this:

define weapons
DIM weapon_type(4)
weapon_type(1)=Unarmed
weapon_type(2)=SniperRifle
weapon_type(3)=Shotgun
weapon_type(4)=TommyGun

by default weapon_type=Unarmed so:

MAKE OBJECT SPHERE 9999,10
MAKE MESH FROM OBJECT 1,9999
DELETE OBJECT 9999
ADD LIMB 1,1,1
OFFSET LIMB 1,1,0,0,10
HIDE LIMB 1,1
DELETE OBJECT 5
ENDIF
ENDIF

IF OBJECT EXIST(5)***sniper rifle***=1
IF *****not already equipped***** and INTERSECT OBJECT (5, LIMB POSITION X(1,2), LIMB POSITION Y(1,2), LIMB POSITION Z(1,2), Play_x#,Play_y#, Play_z#)>0: then weapon_type=SniperRifle ****meaning****

delete current limb
MAKE OBJECT SPHERE 9999,10
MAKE MESH FROM OBJECT 1,9999
DELETE OBJECT 9999
ADD LIMB 1,1,1
OFFSET LIMB 1,1,0,0,10000
HIDE LIMB 1,1
DELETE OBJECT 5
ENDIF
ENDIF



I was thinking just give the limb the same name each time so that this my mouse click shooting code will not need be altered and not having to have multiple limbs at once.


`Mouseclick Shooting
IF KEYSTATE(19)=0 AND MOUSECLICK()=1
IF Ammo>0 THEN DEC Ammo,1
IF OBJECT EXIST(2)=1
IF Ammo>0 AND INTERSECT OBJECT (2, LIMB POSITION X(1,1), LIMB POSITION Y(1,1), LIMB POSITION Z(1,1), Play_x#,Play_y#, Play_z#)>0 THEN DEC EnemyHP,1
ENDIF
ENDIF

Hope this isn't confusing. I am new to programming and I am trying to think for myself a bit. noobs tend to make things harder than they should be, and sometimes, they try to make things easier than what they have to be.
The admiral
22
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 21st Oct 2005 07:47
I check for what type of weapon im holding and offset the limb depending.

The admiral
Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 21st Oct 2005 07:56
that's what i am saying, it is just that i am not sure how to do it.
The admiral
22
Years of Service
User Offline
Joined: 29th Aug 2002
Location:
Posted: 21st Oct 2005 12:02
If your familiar with types then it would look something like....
`pesudo code
if weapon(1).using=1
if weapon(1).type=1 then offset limb obj#,0,0,500
if weapon(1).type=2 then offset limb obj#,0,0,1000
if weapon(1).type=3 then offset limb obj#,0,0,250
endif

Hopefully that helps its not in arrays but im sure you get the idea and can adapt it to your idea.

The admiral
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 21st Oct 2005 23:17
I would use select/case. Anything that has to do with the weapons like the max ammo for each weapon could also be included.

Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 22nd Oct 2005 10:06
@The Admiral

no i am not familiar with types. i tried to look them up but i get confused. i read what others have posted about them and they keep saying something as something and i'm not sure of as means = or what.
Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 22nd Oct 2005 17:09 Edited at: 22nd Oct 2005 19:08
alrighty, this is what i have gotten so far as far as a type/endtype array-thingy. What I am not sure of declaring is the range, which will be how far the limb is offset, and how to let the program know when each weapon is currently in use. I wonder if I can use Grog Grueslayer's SetWeapon() function in conjunction with my type weapon array-thingy.



I am thinking maybe I can assign each weapon a 'case number' and just put the range (offsetting the limb) in each case. Proximity mines will be a little difference, because their range will be my ground-check limb. you will click the firing button, and drop a square wherever your ground-check limb was, and when an enemy comes within a certain distance, it is deleted and the enemy is killed instantly. I'm thinking of doing a:

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 22nd Oct 2005 20:45
You got the use of types right. You just need to add an "m" to weapon(3).maxamo=500 and weapon(4).maxamo=500 (maxamo should be maxammo). And there is also a weapon(0) array. When arrays are defined (not just types) an array goes from 0 to whatever number you use (in this case 0 to 4). Many first person shooters use 0 as the weapon you start with and can never loose (a knife or fists).

Quote: "I am thinking maybe I can assign each weapon a 'case number' and just put the range (offsetting the limb) in each case. Proximity mines will be a little difference, because their range will be my ground-check limb. you will click the firing button, and drop a square wherever your ground-check limb was, and when an enemy comes within a certain distance, it is deleted and the enemy is killed instantly. I'm thinking of doing a:

if case number = (ProximityMines #) then gosub ProximityMines or ProximityMines() function"


Yes and no. You can use case but not the way you typed in your code snip. In my snip CWeapon is the current weapon selected. Using your type if you did this:



It would print out:


And if you included my function it will do this (because CWeapon = 3):

Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 22nd Oct 2005 21:58 Edited at: 22nd Oct 2005 22:07
so how could i make it so that when i pick up object 5, the name is weapon (1).name = Sniper Rifle and the case number is case 1? here's my source:
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 23rd Oct 2005 02:21
Quote: "so how could i make it so that when i pick up object 5, the name is weapon (1).name = Sniper Rifle and the case number is case 1? here's my source:"


Pretty much the same way your doing it... only add the CWeapon=whatever and call the function to set the offset.



Or if you want to save having to call SetWeapon within the if/then statement you can add this before the weapon if's:



Remove the SetWeapon() from the if/then statement and have this after all the weapon if's:



Of course in the long run you're going to want to put all object information in an array, one for/next loop to check each object (to get rid of all the separate if/then statements for each object intersection) and a select/case to do something based on which object was ran over.
Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 23rd Oct 2005 04:41 Edited at: 23rd Oct 2005 05:08
it's not working chief. did you run the program with your changes? the only thing that happens is when i pick up the sniper rifle crate, it is deleted.



I think my problem is in the fact that I don't know how to refer to all of the gun's ammo in 1 variable. that information is stored in the type-endtype/array-thingy (weapon(5).ammo = 100). would i have to make an if/then statement for each and every single weapon(x).ammo, or is their a way to refer to them all in one single variable; exaclty how I just did?
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 23rd Oct 2005 09:31
Quote: "it's not working chief. did you run the program with your changes? the only thing that happens is when i pick up the sniper rifle crate, it is deleted. "


CWeapon needs to be global to work inside a function. Add the following line in the same area you define the other stuff.



Quote: "I think my problem is in the fact that I don't know how to refer to all of the gun's ammo in 1 variable. that information is stored in the type-endtype/array-thingy (weapon(5).ammo = 100). would i have to make an if/then statement for each and every single weapon(x).ammo, or is their a way to refer to them all in one single variable; exaclty how I just did? "


You're SO close. Since CWeapon=the current weapon... replace the x in "weapon(x).ammo" with CWeapon... "weapon(CWeapon).ammo"
Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 23rd Oct 2005 23:17
aww, man thanks for everything chief!!!
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 23rd Oct 2005 23:19
Quote: "aww, man thanks for everything chief!!! "


Np.

Login to post a reply

Server time is: 2024-09-24 07:34:08
Your offset time is: 2024-09-24 07:34:08