Game Development Community

Join game with a weapon already equipped?

by Happy Gnome · in Technical Issues · 10/18/2007 (6:38 pm) · 9 replies

I've been toying with and exploiting the Torque Demo and basically "testing it to the limits" over the past few days and the thought popped into my head that it should be possible to implement a new weapon type ( for testing purposes ) without having to buy the full version.

Basically, my idea is that a player who joins a server will automatically be assigned a weapon. That way he/she can start running around blasting other players without having to find the weapon spawn first.

Also, the weapon would be a plasma-type weapon that needs no ammo, but instead it would have cooldown times etc.

I've been exploring the scripts too, so I have a basic idea of how the weapon structure works, but not enough to write a whole new one. I modified a copy of the crossbow weapon ( just a little bit ) but I have no clue how to implement the modified script much less make a working weapon with it...

Any pointers?

TIA, Happy Gnome

#1
10/18/2007 (6:51 pm)
Server/scripts/game.cs is your friend here.
Exec your scripts here and set the players starting equipment as well.
Scroll down to find the player spawn code and look closely at that.
#2
10/18/2007 (7:05 pm)
Thanks! That's nice to know. I hope you don't mind my noob factor, but I'm still very new here. I personally have no clue whatsoever how one would set the player's starting equipment. Could you please elaborate? Thanks again!
#3
10/19/2007 (7:34 am)
OK, I found the demo "scene.cs" file and copied a few commands to the game.cs file into the GameConnection::createPlayer function:

%player.mountImage(CrossbowImage,1);

%player.setInventory(Crossbow,1);
%player.setInventory(CrossbowAmmo,1000);

Ok, now I start with a crossbow and ammo, but it will not let me fire the crossbow. I cannot pick up a new crossbow because I already have one, but that is simply normal. It also will not let me pick up my test weapon, which is simply a modified crossbow ATM. I had been getting a compilation syntax error ( a period on the end of a decimal value by mistake: "0.8." ) but I fixed that...
#4
10/19/2007 (7:55 am)
Just a quick glance here, but one problem I see is that you've got your crossbow mounted on slot 1 rather than slot 0.

From a binary math perspective, slot 0 is the first mount point for weapons and slot 1 is the second mount point.

So in place of (crossbow, 1) try (crossbow, 0).

Of course this could be something else, but that's the first strategy I would attempt.
#5
10/19/2007 (8:05 am)
That's better! I thought the mountImage function worked like setInventory where the second variable is the amount of items. Thanks a ton!
#6
10/19/2007 (9:19 am)
Glad to help out.
#7
10/19/2007 (2:39 pm)
There's still the problem of modified weapons being non-pickupable. Is there some assigned slot number that I need to change somewhere?
#8
10/19/2007 (4:46 pm)
Hmm. When you say that you can't pick up modified weapons, I can't help but wonder what the base scripts you used and what modifications were made. If you feel comfortable posting your script here, maybe one of us can spot the problem.

If not, then it could be that you have two items sharing the same name. I've had weirdness like that happen before. In the world editor, click on the weapon that's not pickupable and look at the name value for it. If it's crossbow, try adding an extra letter to that name, apply the changes, save, exit and reload the map. Again, that's an example from something that I ran into once.
#9
10/19/2007 (6:00 pm)
Changing the names had no effect, sorry...

I used the Crossbow.cs script as my base, and I tried to modify it so that it shoots a fireball. On top of that, I want the weapon itself to be invisible. In effect, a magic fireball out of thin air! Customized sound effects too... Sounded easy enough, but I think I tried to do too many things at once. I probably made so many errors that it will be almost unreadable. I think I'll try a clean start over, and work on the weapon one step at a time.

Uh, the script is too long to post normally... How exactly do I attach it to my post?