Adding another weapon
by Jonas · in Torque 3D Beginner · 06/08/2010 (9:03 pm) · 9 replies
Hey again everyone!
Last post i asked about weapons in torque regarding switching to other weapons now im at another stage in my learning and i find myself stuck again..
Ok so here is what i wanna do:
Basically i wanna duplicate the rocketlauncher so i can switch from the RL to the RL just to get it down exactly how many and which files i need to duplicate and change for a working weapon.
So my question is exactly which files do i need to make to make a working weapon taking the rocketlauncher as a example i can find files called 'RL' and so on but i am more then sure that there is many more files having information needed for the 'RL' to work.
If someone can point me in that direction and i will handle it from there.
Note: I am still very noob when it comes to torque and i do know that when a question like this appears many often refer to read the manual please don't i have read it but i find this way better since i apply everything "in the field"
Best regards
/Jonas
Last post i asked about weapons in torque regarding switching to other weapons now im at another stage in my learning and i find myself stuck again..
Ok so here is what i wanna do:
Basically i wanna duplicate the rocketlauncher so i can switch from the RL to the RL just to get it down exactly how many and which files i need to duplicate and change for a working weapon.
So my question is exactly which files do i need to make to make a working weapon taking the rocketlauncher as a example i can find files called 'RL' and so on but i am more then sure that there is many more files having information needed for the 'RL' to work.
If someone can point me in that direction and i will handle it from there.
Note: I am still very noob when it comes to torque and i do know that when a question like this appears many often refer to read the manual please don't i have read it but i find this way better since i apply everything "in the field"
Best regards
/Jonas
About the author
Freelance 3D artist at day scripter/coder on Enduring Life at night. Lover of all things TorqueScript.
#2
Note: i was referring to the online documentation
06/09/2010 (10:05 am)
Thank you once again Steve i will check this out.Note: i was referring to the online documentation
#3
Then i added my new file to the exec list:
exec("./weapons/Sawed_of_shotgun.cs");
I did the same with scripts/server/rocketlauncher.cs and once again i added it to the exec list:
exec("./Sawed_of_shotgun.cs");
After that i created a new inventory max to handle my weapon and ammunition in the player.cs:
maxInv[Sawed_of_shotgun] = 1;
maxInv[Sawed_of_shotgun_Ammo] = 32
After i added that i went onto equipping my character with the weapon:
function GameCore::loadOut(%game, %player)
{
//echo (%game @"\c4 -> "@ %game.class @" -> GameCore::loadOut");
%player.setInventory(RocketLauncher, 1);
%player.setInventory(RocketLauncherAmmo, %player.maxInventory(RocketLauncherAmmo));
%player.setInventory(Sawed_of_shotgun, 1);
%player.setInventory(Sawed_of_shotgun_Ammo, %player.maxInventory(Sawed_of_shotgun_Ammo));
%player.mountImage(RocketLauncherImage, 0);
}
After this was done i went on to adding a keybind for it:
moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"RocketLauncher\");", "");
moveMap.bindCmd(keyboard, "2", "commandToServer('use',\"Sawed_of_shotgun\");","");
Also i checked scripts/client/config.cs and added:
moveMap.bindCmd(keyboard, "2", "commandToServer('use',\"Sawed_of_shotgun\");","");
at the end of the file.
But i don't get the desired function, or well no function at all when i try to change weapon it does not give me a response at all.
So my question is there a easy way to find out where i made probably a spelling misstake? or a good way to look for failed code? like first check player.cs then weapon and so on.
Best regards Jonas.
06/09/2010 (10:46 am)
Ok so what i have done is made a version of art/datablocks/weapons/rocketlauncher.cs i copied the original rocketlauncher.cs file and went through it and changed all the function names/target locations to my own.Then i added my new file to the exec list:
exec("./weapons/Sawed_of_shotgun.cs");
I did the same with scripts/server/rocketlauncher.cs and once again i added it to the exec list:
exec("./Sawed_of_shotgun.cs");
After that i created a new inventory max to handle my weapon and ammunition in the player.cs:
maxInv[Sawed_of_shotgun] = 1;
maxInv[Sawed_of_shotgun_Ammo] = 32
After i added that i went onto equipping my character with the weapon:
function GameCore::loadOut(%game, %player)
{
//echo (%game @"\c4 -> "@ %game.class @" -> GameCore::loadOut");
%player.setInventory(RocketLauncher, 1);
%player.setInventory(RocketLauncherAmmo, %player.maxInventory(RocketLauncherAmmo));
%player.setInventory(Sawed_of_shotgun, 1);
%player.setInventory(Sawed_of_shotgun_Ammo, %player.maxInventory(Sawed_of_shotgun_Ammo));
%player.mountImage(RocketLauncherImage, 0);
}
After this was done i went on to adding a keybind for it:
moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"RocketLauncher\");", "");
moveMap.bindCmd(keyboard, "2", "commandToServer('use',\"Sawed_of_shotgun\");","");
Also i checked scripts/client/config.cs and added:
moveMap.bindCmd(keyboard, "2", "commandToServer('use',\"Sawed_of_shotgun\");","");
at the end of the file.
But i don't get the desired function, or well no function at all when i try to change weapon it does not give me a response at all.
So my question is there a easy way to find out where i made probably a spelling misstake? or a good way to look for failed code? like first check player.cs then weapon and so on.
Best regards Jonas.
#4
Remember that you'll have to change the datablocks too, and swap every instance of rocketlauncher for in the sawn_off_shotgun.cs files - except for maybe the shapefile if you're using the same model.
Always check your console log for related errors when things don't work.
06/09/2010 (10:52 am)
Non related grammatical, spelling mistake would be "sawn_off_shotgun".Remember that you'll have to change the datablocks too, and swap every instance of rocketlauncher for in the sawn_off_shotgun.cs files - except for maybe the shapefile if you're using the same model.
Always check your console log for related errors when things don't work.
#5
Ok ill have another look at it and well see how it goess.
06/09/2010 (11:32 am)
Ok, thanks for correcting me.Ok ill have another look at it and well see how it goess.
#6
scripts/server/inventory.cs (113): Unable to find objects: 'Sawed_of_shotgun' attempting to call function 'get name'
scripts/server/inventory.cs (174): Unable to find objects: 'Sawed_of_shotgun' attempting to call function 'get name'
scripts/server/inventory.cs (113): Unable to find objects: 'Sawed_of_shotgun_Ammo' attempting to call function 'get name'
scripts/server/inventory.cs (113): Unable to find objects: 'Sawed_of_shotgun_Ammo' attempting to call function 'get name'
scripts/server/inventory.cs (174): Unable to find objects: 'Sawed_of_shotgun_Ammo' attempting to call function 'get name'
Note: they do repeat in this manor as i wrote them. And after a while of succesfull things running i get 2 more lines of this:
scripts/server/inventory.cs (155): Unable to find objects: 'Sawed_of_shotgun' attempting to call function 'get name'
scripts/server/inventory.cs (155): Unable to find objects: 'Sawed_of_shotgun' attempting to call function 'get name'
Any ideas on where to look? i have checked mostly everything related to the actually items named Sawed_of_shot gun and the Ammo.
Best regards
/Jonas
06/09/2010 (1:39 pm)
Ok i have been looking at it for some time now and battled the console for a while but i still receive this errors:scripts/server/inventory.cs (113): Unable to find objects: 'Sawed_of_shotgun' attempting to call function 'get name'
scripts/server/inventory.cs (174): Unable to find objects: 'Sawed_of_shotgun' attempting to call function 'get name'
scripts/server/inventory.cs (113): Unable to find objects: 'Sawed_of_shotgun_Ammo' attempting to call function 'get name'
scripts/server/inventory.cs (113): Unable to find objects: 'Sawed_of_shotgun_Ammo' attempting to call function 'get name'
scripts/server/inventory.cs (174): Unable to find objects: 'Sawed_of_shotgun_Ammo' attempting to call function 'get name'
Note: they do repeat in this manor as i wrote them. And after a while of succesfull things running i get 2 more lines of this:
scripts/server/inventory.cs (155): Unable to find objects: 'Sawed_of_shotgun' attempting to call function 'get name'
scripts/server/inventory.cs (155): Unable to find objects: 'Sawed_of_shotgun' attempting to call function 'get name'
Any ideas on where to look? i have checked mostly everything related to the actually items named Sawed_of_shot gun and the Ammo.
Best regards
/Jonas
#7
06/09/2010 (1:43 pm)
Problem solved was related to datablock naming.
#8
eg:
datablock ItemData(sawed_of_shotgunAmmo)
datablock ItemData(sawed_of_shotgun)
datablock ShapeBaseImageData(sawed_of_shotgunImage) - and all relations in this one
You shouldn't have rocketlauncher anywhere (save for shapename if you're still using the model)
edit: gotcha
06/09/2010 (1:48 pm)
Check you've renamed all item/ammo/image/datablocks and corresponding links in both sawed_of_shotgun.cseg:
datablock ItemData(sawed_of_shotgunAmmo)
datablock ItemData(sawed_of_shotgun)
datablock ShapeBaseImageData(sawed_of_shotgunImage) - and all relations in this one
You shouldn't have rocketlauncher anywhere (save for shapename if you're still using the model)
edit: gotcha
#9
In theory all that is needed for a new weapon would be the necessary datablocks. Unless a onfire script is created for the new weapon it will simply use the general purpose weaponImage::onfire() method. Add keybinds and weaponCycle order (optional) and you're good to go.
And like Steve mentioned don't duplicate datablock names, make sure all are unique.
06/10/2010 (12:34 pm)
Sometimes code comments are better than a 'manual' ;)// RocketLauncher weapon. // This script file contains all of the necessary datablocks needed for the // RocketLauncher. These datablocks include sound profiles, light descriptions, // particle effects, explosions, projectiles, items (weapon and ammo), shell // casings (if any), and finally the weapon image which contains the state // machine that determines how the weapon operates. // The main "fire" method/mode is handled in "../scripts/server/weapons.cs" // through a "WeaponImage" namespace function. This reduces duplicated code, // although a unique fire method could still be implemented for this weapon. // The "alt-fire" method/mode is handled in "../scripts/server/rocketlaucner.cs".
In theory all that is needed for a new weapon would be the necessary datablocks. Unless a onfire script is created for the new weapon it will simply use the general purpose weaponImage::onfire() method. Add keybinds and weaponCycle order (optional) and you're good to go.
And like Steve mentioned don't duplicate datablock names, make sure all are unique.
Associate Steve Acaster
[YorkshireRifles.com]
You need versions of the following:
You also need to add a maximum inventory for weapon and ammunition in art/datablock/player.cs
And then equip the player when it spawns via function loadout() out in scripts/server/gamecore.cs
If you're not reusing the stock model and have a new one, place it in art/shapes/weapons/swarmgun. Or you could make a new folder and put it in there, just make sure that the shapefile destination of art/datablocks/weapons/rocketlauncher.cs points to it.
Finally you need a keybind to allow the player to select it in-game.
Add a new keybind for the weapon, with a different key obviously or they'll clash.
scripts/client/default.bind.cs moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"RocketLauncher\");", "");and very finally check if there is a config file - scripts/client/config.cs - and list that with the other keybinds ---> though I think this might not be required any longer.