Some quick questions.
by Christopher Gardner · in Torque 3D Professional · 08/06/2010 (10:36 pm) · 7 replies
1. I was making my own savefile system (upcoming tutorial :P) and I wanted to save the players inventory. I found the $Player::Inventory variable, and I was wondering can I just write that value to a savefile and then read it from it to quickly get the players inventory?
2.How do I pause the game?
3.I've got some code.
The problem with this is, whenever I fire a bullet, no sound is made, but when I reload, that sound is played. Anyone know why it isn't playing? Also, for some odd reason the preview image never appears, and the reticule only appears if I zoom in, then zoom back out.
4.How would I make a shop menu with a list of items, and if I select an item and buy it, it appears in front of me?
5. Does AiPlayer have some sort of onDeath() call?
6. How can I make a gun semi automatic (If i press the mouse button it fires one bullet, I have to release and press it again to fire another.) Also, I want this to not affect every weapon, only select ones.
7. Is there any kind of way to make a gun that doesn't hurt, and has a different consuqence, eg knockout?
8. Know where I can find some good vehicle (specifically planes and helicopters) resources and models?
9. Any way to spray some kind of gas into the air that hurts people if they aren't wearing a gas mask?
10. You can save() an object to a file. But how do oyu load?
Thanks in advance for the help.
2.How do I pause the game?
3.I've got some code.
datablock SFXProfile(AK47ReloadSound)
{
filename = "art/sound/weapon/clip-load.ogg";
description = AudioClose3d;
preload = true;
};
datablock SFXProfile(AK47EmptyShotSound)
{
filename = "art/sound/weapon/empty.ogg";
description = AudioClose3d;
preload = true;
};
datablock SFXProfile(AK47SingleShotSound)
{
filename = "art/sound/weapon/single.ogg";
description = AudioClose3d;
preload = true;
};
datablock ItemData(AK47)
{
category = "Weapon";
className = "Weapon";
shapeFile = "art/shapes/weapons/AK47/AK47.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
pickUpName = "AK47";
description = "AK47";
image = AK47Image;
previewImage = 'swarmer.png'; //Preview image, I just left the default rocket launcher one
reticle = 'reticle_rocketlauncher'; //Crosshair, this one is pretty normal.
};
datablock ShapeBaseImageData(AK47Image)
{
shapeFile = "art/shapes/weapons/AK47/AK47.dts";
ammo = AK47Ammo; //Ammo type, make common ammo types maybe?
projectile = AK47Projectile;
projectileType = Projectile;
projectileSpread = 4 / 1000.0; //Projectile Spread
emap = true;
item = AK47;
clipSize = 50; //Clip size
ammoInClip = 50; //Bullets in clip (This and above should be the same)
correctMuzzleVector = false;
eyeOffset = "0.142857 0.302857 -0.211429";
//These states and animations are from the ModMakersWeapon Pack. If you are using those models, these should work(rename sounds)
//Else, get your states. You may be able to use the SwarmGun animations, but I don't know.
stateName[0] = "Preactivate";
stateTransitionOnLoaded[0] = "Activate";
stateName[1] = "Activate";
stateTransitionOnTimeout[1] = "Carry";
stateScript[1] = "onLoad";
stateName[2] = "Carry";
stateTransitionOnTimeout[2] = "Carry";
stateTransitionOnNoAmmo[2] = "NoAmmoCarry";
stateTransitionOnTriggerDown[2] = "SingleShot";
stateAllowImageChange[2] = true;
stateSequence[2] = "Sequence_Carry";
stateName[3] = "NoAmmoCarry";
stateTransitionOnTimeout[3] = "NoAmmoCarry";
stateTransitionOnTriggerDown[3] = "EmptyShot";
stateAllowImageChange[3] = true;
stateSequence[3] = "Sequence_Carry";
stateName[4] = "Reload";
stateTransitionOnTimeout[4] = "Carry";
stateTimeoutValue[4] = 2;
stateAllowImageChange[4] = true;
stateSequence[4] = "Sequence_Reload";
stateScript[4] = "onReload";
stateSound[4] = AK47ReloadSound;
stateName[5] = "EmptyShot";
stateTransitionOnTimeout[5] = "NoAmmoCarry";
stateTransitionOnAmmo[5] = "Reload";
stateTimeoutValue[5] = 0.3;
stateAllowImageChange[5] = true;
stateSequence[5] = "Sequence_Fire";
stateScript[5] = "onEmptyShot";
stateSound[5] = AK47EmptyShotSound;
stateName[6] = "SingleShot";
stateTransitionOnTimeout[6] = "Carry";
stateTransitionOnNoAmmo[6] = "NoAmmoCarry";
stateTimeoutValue[6] = 0.3; //Decrease for faster firing, increase for more time between firing.
stateAllowImageChange[6] = true;
stateFire[6] = true;
stateSequence[6] = "Sequence_Fire";
stateScript[6] = "onFire";
stateSound[6] = AK47SingleShotSound;
};The problem with this is, whenever I fire a bullet, no sound is made, but when I reload, that sound is played. Anyone know why it isn't playing? Also, for some odd reason the preview image never appears, and the reticule only appears if I zoom in, then zoom back out.
4.How would I make a shop menu with a list of items, and if I select an item and buy it, it appears in front of me?
5. Does AiPlayer have some sort of onDeath() call?
6. How can I make a gun semi automatic (If i press the mouse button it fires one bullet, I have to release and press it again to fire another.) Also, I want this to not affect every weapon, only select ones.
7. Is there any kind of way to make a gun that doesn't hurt, and has a different consuqence, eg knockout?
8. Know where I can find some good vehicle (specifically planes and helicopters) resources and models?
9. Any way to spray some kind of gas into the air that hurts people if they aren't wearing a gas mask?
10. You can save() an object to a file. But how do oyu load?
Thanks in advance for the help.
#2
08/07/2010 (12:19 am)
Thanks Samantha. I'll work on those subjects.
#3
08/07/2010 (12:06 pm)
For pausing the game you could try $timescale = 0;but that will pause everything, literally grinds the whole of T3D to a halt, and not just the gameplay ... so it's probably not the perfect solution.
#4
3) After reading your code, everything seems right. Have you modified some outside code? client.cs?
5) Have a look at AIPlayer::onDisabled(%this, %obj, %state) note that AIPlayer is a replacement, put the datablock of the AIPlayer there
7) What Samantha said, but more specific WeaponProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal) WeaponProjectile is also an replacement
8a) Models: Umm, well, there aren't any good drop-in helicopters/planes for torque, but if you have a intermediate modeling skill, i would recommend looking at google 3D warehouse for some helicopter models. There are actually no restrictions to google warehouse models (as far as I've understood), but you might want to re-model the models due to high polycount.
8b) Resources: There is the Helicopter resource ported by Sean Rice
There is also a AIHelicopter "resource" ported by me. note: it is only path following but it can be extended
08/07/2010 (1:34 pm)
1) $Player::Inventory? When i echo that variable i get nothing. Maybe you have some custom code that list all your weapons in $Player::Inventory. If not you can try $weaponOrderIndex[%slot]. I've currently got a (inventory) system that works just perfect, might submit it as a resource.3) After reading your code, everything seems right. Have you modified some outside code? client.cs?
5) Have a look at AIPlayer::onDisabled(%this, %obj, %state) note that AIPlayer is a replacement, put the datablock of the AIPlayer there
7) What Samantha said, but more specific WeaponProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal) WeaponProjectile is also an replacement
8a) Models: Umm, well, there aren't any good drop-in helicopters/planes for torque, but if you have a intermediate modeling skill, i would recommend looking at google 3D warehouse for some helicopter models. There are actually no restrictions to google warehouse models (as far as I've understood), but you might want to re-model the models due to high polycount.
8b) Resources: There is the Helicopter resource ported by Sean Rice
There is also a AIHelicopter "resource" ported by me. note: it is only path following but it can be extended
#5
@Steve
I don't want to pause everything just gameplay and then display a menu. Do you think it's possible to do it without source changes?
08/07/2010 (1:44 pm)
Alright, thanks.@Steve
I don't want to pause everything just gameplay and then display a menu. Do you think it's possible to do it without source changes?
#6
Just as a test I froze the sim with $timescale, hit ESC, and the normal exit gui popped up. So all is good there! You should be able to pause->display menu->and then unpause ($timescale=1), after you've selected or quit.
Just as a failsafe, I have my scripts call $timescale=1; anyway when I exit a level/mission ... just incase I've fiddled with it in-game. If $timescale is set to zero, the server can't restart when you try and load a new level.
[edit]
Gamecore.cs
08/07/2010 (1:54 pm)
@ChrisJust as a test I froze the sim with $timescale, hit ESC, and the normal exit gui popped up. So all is good there! You should be able to pause->display menu->and then unpause ($timescale=1), after you've selected or quit.
Just as a failsafe, I have my scripts call $timescale=1; anyway when I exit a level/mission ... just incase I've fiddled with it in-game. If $timescale is set to zero, the server can't restart when you try and load a new level.
[edit]
Gamecore.cs
function endMission()
{
$timeScale = 1.0;//yorks
//...
#7
08/07/2010 (2:40 pm)
Alright! Thanks alot!
Torque Owner Cassy Brink
Minalien.com
2) Can't remember off the top of my head, and I've never really needed to. Gommen
3) Again, I'm not sure off the top of my head, and I'm at work.
4) Sounds like you need to do some GUI scripting. Make up the GUI with the GUI builder (I'd say follow the "Inventory Screen" GUI tutorial), then have the item spawn near the shopkeeper when purchased. I think it's usually better to directly place it in the inventory, if there's space, however - it's the standard amongst Role-Playing and Adventure games.
5) I know that there is a call for the death of the object, but I don't know what it is off the top of my head. Look at the "RTS Prototype" tutorial under the Advanced section in Scripting.
6) You'll need to drop/edit the current binding for the LMB (Left Mouse Button) on the MoveMap action map. Bind it to a command that sets or unsets a variable (in this case, it will act as a flag) saying that the mouse is or is not held. Then, create a second function that will handle subsequent firing of the weapon (for held portions only - you'll still want to include the initial shot in the portion of the function where you set the flag), and schedule it on your fire binding callback. Then, at the end of this method, do a check. If the "mouse down" flag is true (1), then have the function schedule itself again - if it's false (0), don't. Make sure that you unset the flag when the mouse button is released.
7) I believe you should just need to modify the collision event of the bullet.
8) No idea.
9) Again, this is kind of crude, but here's my suggestion: Spawn a trigger that is scripted to update with each frame. Have it apply its damage when its callback is called, and make sure that you check the player's current set of equipped items to see if she has equipped a gas mask. Drop a particle effect that looks like spraying gas, and you've got the visuals of it.
Hope that helped a little~