Tutorial: Flower Baricade

 

 

Level: Easy

 

Author: Ninja of Comp

 

I was trying to make a weapon that would shoot a seed of some sort and this seed would embed itself in its victim and after some time, it would germinate and explode its victim leaving a flower in its place.

 

Well, I haven’t finished that weapon yet but based on the research I did, I was able to make what I call a Flower Baricade. This is just a way to spawn a model, put dimentions on it so when a player tries to go trough it, he can’t, thus becoming a barricade. But also, after 10 seconds, it will explode and cause some damage to any player nearby.

 

Good too block doorways for a quick getaway.

 

Here we go! First create a file or incorporate the following code into you project file:

 

 

// ******************************************************

// * JMR: Flower Explode

// ******************************************************

void Flower_Explode(edict_t *flower)

{

       flower->owner->client->flower = 0;

 

       // Destroy the FLOWER in a big fireball.

       G_Spawn_Explosion(TE_EXPLOSION2, flower->s.origin, flower->s.origin);

 

       // Throw flower debris all over the place...

       ThrowDebris(flower, "models/objects/debris2/tris.md2", 3.50, flower->s.origin);

       ThrowDebris(flower, "models/objects/debris2/tris.md2", 2.50, flower->s.origin);

       ThrowDebris(flower, "models/objects/debris2/tris.md2", 1.50, flower->s.origin);

       ThrowDebris(flower, "models/objects/debris2/tris.md2", 4.50, flower->s.origin);

       ThrowDebris(flower, "models/objects/debris2/tris.md2", 3.75, flower->s.origin);

       ThrowDebris(flower, "models/objects/debris2/tris.md2", 2.30, flower->s.origin);

       ThrowDebris(flower, "models/objects/debris2/tris.md2", 1.00, flower->s.origin);

 

       // Assign any Radius Damage frags to the FLOWER's owner..

T_RadiusDamage(flower, flower->owner, 40, NULL, 400, MOD_SPLASH);

 

       // Free the flower entity

       G_FreeEdict(flower);

}

 

// ******************************************************

// * JMR: Create Flower

// ******************************************************

void Create_Flower (edict_t *ent)

{

 

       if (ent->client->flower == 1)    // if flower still exists, don't create again

       {

             return;

       }

       else                             // otherwise....

       {

             ent->client->flower = 1;

       }

 

       edict_t *flower;           // define flower as an entity

       vec3_t forward;            // define foward as vector

 

       flower=G_Spawn();

       flower->s.modelindex       = gi.modelindex ("models/objects/flower/tris.md2"); // The model

       flower->owner              = ent;              // who's your dady?

       flower->takedamage         = DAMAGE_NO;        // can't damage it

       flower->movetype           = MOVETYPE_TOSS;    // throw this flower and it falls to ground

       flower->solid              = SOLID_BBOX;       // the flower is solid

       flower->nextthink          = level.time + 5;   // When to execute the think function (5 sec)

       flower->think              = Flower_Explode;   // and this (Flower_Explode) is that function

 

       VectorClear(flower->s.angles);                           // clear flower angles

       AngleVectors(ent->client->v_angle, forward, NULL, NULL); // copy owners angles to flower

       VectorMA(ent->s.origin, 100, forward, flower->s.origin); // Put the model in front of us

 

       flower->s.origin[2] += 64; // a little higher please

 

       // This should set the bounderies for our flower

 

       VectorSet (flower->mins, -18, -18, -28);       //  a, b. c

       VectorSet (flower->maxs, 18, 18, 18);          //  e, f, g

/*

        o---------o

        |\        |\  f

        | \       | \  \

      c |  \   e- |  \

      | |   o---------o <- maxs         // might be wrong on a,b,e & f

        |   |     |   |                 // but i'm sure on c & g

mins -> o---|-----o   | |

         \  | -a   \  | g

        \ \ |       \ |

         b \|        \|

            o---------o

*/

 

       gi.linkentity (flower);

}

 

 

Now go to g_local.h and add the the following lines at the end:

 

 

void Flower_Explode(edict_t *flower);

void Create_Flower (edict_t *ent);

 

 

Also go to g_cmds.c and add the following lines near the end of ClientCommands:

 

 

else if (Q_stricmp(cmd, "playerlist") == 0)

             Cmd_PlayerList_f(ent);

// ******************************************************

// * JMR: Create Flower

// ******************************************************

else if (Q_stricmp (cmd, "flower") == 0)

             Create_Flower (ent);

// *************************************************

       else   // anything that doesn't match a command will be a chat

             Cmd_Say_f (ent, false, true);

 

 

Now you only have to bind that command to a key (example: bind f “flower”) and your set.

 

Explanation:

 

Everything should be easy to follow. Take note on that little box I made. It should give you an idea of how to set up bouderies for your models.

 

Final remarks:

 

You can do more than just a barricade. You can also create item models to lure out campers or other players. If you play around a little, you can even add a think function for proximity. That way, when the player gets close to the “item” he’ll receive some damage.

 

Have fun.