learning to add a weapon.

Need help with a tutorial found on InsideQC.com? Post here.
Post Reply
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

learning to add a weapon.

Post by ceriux »

hey i been having an issue with compiling again... iv been trying all night its now 3:49 am... i just cant figure out what iv done wrong.

this is the tutorial iv been fallowing : http://inside3d.com/showtutorial.php?id=60

the only part i didnt fallow was the part of adding it to the cheat command i dont want that. i just added a line in the fgd to add it to a map .

this is the error im getting.

Image
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

Error: Syntax error before 'else'.
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

Probably you have an else that's been separated from its if statement by some code you added; or perhaps you deleted or rewrote an if statement and left the else dangling. Mind posting that section of items.qc (say, lines 400-500) so we can take a look?
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

i dont think so it all looks right.... iv looked over the original code and it all seems to be set up exactly the same way.

Code: Select all

/*
=============
weapon_touch  - lines 385- 505
=============
*/
float() W_BestWeapon;

void() weapon_touch =
{
	local	float	hadammo, best, new, old;
	local	entity	stemp;
	local	float	leave;

	if (!(other.flags & FL_CLIENT))
		return;

// if the player was using his best weapon, change up to the new one if better		
	stemp = self;
	self = other;
	best = W_BestWeapon();
	self = stemp;

	if (deathmatch == 2 || coop)
		leave = 1;
	else
		leave = 0;
	
	if (self.classname == "weapon_nailgun")
	{
		if (leave && (other.items & IT_NAILGUN) )
			return;
		hadammo = other.ammo_nails;			
		new = IT_NAILGUN;
		other.ammo_nails = other.ammo_nails + 30;
	}
	else if (self.classname == "weapon_supernailgun")
	{
		if (leave && (other.items & IT_SUPER_NAILGUN) )
			return;
		hadammo = other.ammo_rockets;			
		new = IT_SUPER_NAILGUN;
		other.ammo_nails = other.ammo_nails + 30;
	}
	else if (self.classname == "weapon_supershotgun")
	{
		if (other.ammo_shells = 20 && (other.items & IT_SUPER_SHOTGUN))
		{
		new = IT_Sniper;
		other.ammo_shells = other.ammo_shells + 20;
		}
		if (leave && (other.items & IT_SUPER_SHOTGUN) )
			return;
		hadammo = other.ammo_rockets;			
		new = IT_SUPER_SHOTGUN;
		other.ammo_shells = other.ammo_shells + 5;
	}
      else if (self.classname == "weapon_rocketlauncher")
	{
		if (leave && (other.items & IT_ROCKET_LAUNCHER) )
			return;
		hadammo = other.ammo_rockets;			
		new = IT_ROCKET_LAUNCHER;
		other.ammo_rockets = other.ammo_rockets + 5;
	}
	else if (self.classname == "weapon_grenadelauncher")
	{
		if (leave && (other.items & IT_GRENADE_LAUNCHER) )
			return;
		hadammo = other.ammo_rockets;			
		new = IT_GRENADE_LAUNCHER;
		other.ammo_rockets = other.ammo_rockets + 5;
	}
	else if (self.classname == "weapon_lightning")
	{
		if (leave && (other.items & IT_LIGHTNING) )
			return;
		hadammo = other.ammo_rockets;			
		new = IT_LIGHTNING;
		other.ammo_cells = other.ammo_cells + 15;
	}
	else
		objerror ("weapon_touch: unknown classname");

	sprint (other, "You got the ");
	sprint (other, self.netname);
	sprint (other, "\n");
// weapon touch sound
	sound (other, CHAN_ITEM, "weapons/pkup.wav", 1, ATTN_NORM);
	stuffcmd (other, "bf\n");

	bound_other_ammo ();

// change to the weapon
	old = other.items;
	other.items = other.items | new;
	
	stemp = self;
	self = other;

	if (!deathmatch)
		self.weapon = new;
	else
		Deathmatch_Weapon (old, new);

	W_SetCurrentAmmo();

	self = stemp;

	if (leave)
		return;

// remove it in single player, or setup for respawning in deathmatch
	self.model = string_null;
	self.solid = SOLID_NOT;
	if (deathmatch == 1)
		self.nextthink = time + 30;
	self.think = SUB_regen;
	
	activator = other;
	SUB_UseTargets();				// fire all targets / killtargets
};


Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

Looks fine as far as I can see. :/

The assignment in conditional comes from this line:
if (other.ammo_shells = 20 && (other.items & IT_SUPER_SHOTGUN))
tbh the logic here is a little broken... but it shouldn't generate any actual compiler errors, it just won't run right.

19 lines later is this line:
else if (self.classname == "weapon_grenadelauncher")

I really don't see how that else could be misplaced.
The only thing I can think of is that its somehow complaining about something hidden in whitespace.. but that doesn't really make much sense, as it would be moaning about a missing operator rather than a variable.

Bizzare.

fix it!
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

lol im trying to :( -.-
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

Yes, you'll want to fix the "if (other.ammo_shells = 20" to use a == instead of a = (a single = will set shells to 20 every time that if statement runs, which you probably don't want). Other than that, I'm not finding anything.

The line it's giving the error on is this one, right?
else if (self.classname == "weapon_grenadelauncher")

You can also try using fteqcc to see if it says something different about the error, or tags a different line.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

ok, changing that fix it :D but now when i changed the fgd to add this weapon and i put it in my map and recompiled....

it doesnt show up ingame...
here's my fgd qc...

Code: Select all

@baseclass size(-16 -16 0, 16 16 32) color(0 0 200) base(Item, Appearflags) = Weapon []

@PointClass base(Weapon) = weapon_supershotgun : "Super shotgun" []
@PointClass base(Weapon) = weapon_nailgun : "Nailgun" []
@PointClass base(Weapon) = weapon_supernailgun : "Perforator" []
@PointClass base(Weapon) = weapon_grenadelauncher : "Grenade launcher" []
@PointClass base(Weapon) = weapon_rocketlauncher : "Rocket launcher" []
@PointClass base(Weapon) = weapon_lightning : "Thunderbolt" []
@PointClass base(Weapon) = weapon_sniper : "sniper" []
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

Does anyone know why the sniper rifle wont show up in my map? does it have to do with how i added the sniper as a new weapon in the game? because im thinking the way that the tutorial show'd me how to add the new weapon makes it use the same everything that the shotgun does instead of actually creating a new weapon. i may be wrong, but im still learning -.-
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Post by r00k »

pardon me but it is 4am, and im barely awake

Code: Select all

lse if (self.classname == "weapon_supershotgun")
	{
		if(other.shells = 100 && (other.items & IT_SUPER_SHOTGUN))
		{
		new = IT_SNIPER;
		other.ammo_shells = other.ammo_shells + 20;
		}
		if (leave && (other.items & IT_SUPER_SHOTGUN) )
			return;
		hadammo = other.ammo_rockets;			
		new = IT_SUPER_SHOTGUN;
		other.ammo_shells = other.ammo_shells + 5;
	}
shouldn't this be like this?

Code: Select all

        else if (self.classname == "weapon_supershotgun")
        {
                if (other.shells == 100 && (other.items & IT_SUPER_SHOTGUN))//R00k added the '== 100' was '= 100'
                {
                        new = IT_SNIPER;
                        other.ammo_shells = other.ammo_shells + 20;
                }
                else
                {
                        if (leave && (other.items & IT_SUPER_SHOTGUN))
                                return;
                        hadammo = other.ammo_rockets; //what the f*ck is this here for??
                        new = IT_SUPER_SHOTGUN;
                        other.ammo_shells = other.ammo_shells + 5;
                }
        }
Which basically means if you touch the DoubleShotgun , and you already had one, AND you have 100 shells, THEN, you magically have a SNIPER RIFLE now. This tut doesnt actually add a sniper rifle model to the map, it just changes the behavior of the DSG, under these circumstances.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

well... i decided to use the same code, but use the grenade launchers model... only difference. i mean id like to add a new weapon to an already existing slot just hit like 2 twice and you get the new weapon after you've picked it up.
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

still having issues with this....


i get issues here

Code: Select all

{
		if (other.shells = 10= && (other.items & IT_SUPER_SHOTGUN))
		
		{
		new = IT_SNIPER;
		other.ammo_shells = other.ammo_shells + 20;
		}
		if (leave && (other.items & IT_SUPER_SHOTGUN) )
			return;
		hadammo = other.ammo_rockets;			
		new = IT_SUPER_SHOTGUN;
		other.ammo_shells = other.ammo_shells + 5;
	}
specifically here....

Code: Select all

if (other.shells = 10= && (other.items & IT_SUPER_SHOTGUN))
Dr. Shadowborg
InsideQC Staff
Posts: 1120
Joined: Sat Oct 16, 2004 3:34 pm

Post by Dr. Shadowborg »

ceriux wrote:

Code: Select all

if (other.shells = 10= && (other.items & IT_SUPER_SHOTGUN))
The problem is that it should be this:

Code: Select all

if (other.shells == 10 && (other.items & IT_SUPER_SHOTGUN))
also, you may want to look at the stuff in here:
http://qexpo.tastyspleen.net/booth.php?id=131

There's an issue or two that I hadn't thought of with tutorial 3, but aside from that it's mostly good stuff.

Also, just in case error wants to stab me for saying that I was going to put these up on I3D's tutorial section, I can only say that I'm currently horribly busy right now with real life / work issues / quake burnout. :cry:
Post Reply