Author Topic: Making hats? (New feature idea)  (Read 3413 times)

How would I make a hat of my own without using those hat mods?
« Last Edit: October 19, 2011, 02:31:14 PM by Demian »

-Create a model
-Create a script
  
Code: [Select]
datablock ShapeBaseImageData(HatImage)
{
shapeFile = "./Hat.dts";
emap = true;
mountPoint = $HeadSlot;
offset = "0 -0.05 0.1";
eyeOffset = "0 0 10 1";
rotation = eulerToMatrix("0 0 0");
scale = "1 1 1";
doColorShift = false;
//colorShiftColor = "0.392 0.196 0.0 1.000";
};

function servercmdHat(%client)
{
  if(isObject(%client.player))
  {
   %client.player.hideNode($hat[%i]);
   %client.player.mountimage(Hatimage, 1);
  }
}
something along the lines of this I'm not exactly sure if it works though
Hope I helped also on a side note its fun to add emmiters to the hat image so you can have flaming hats
« Last Edit: October 09, 2011, 12:45:41 PM by swollow »

Commands are gay. I want it to be a regular item in your inv that you activate to wear and take off.

Commands are gay. I want it to be a regular item in your inv that you activate to wear and take off.
You could probably just make a weapon, and use image::onFire to toggle the hat.
« Last Edit: October 10, 2011, 02:07:42 PM by Mawpius »

Code: [Select]
datablock ItemData(HatItem)
{
category = "Item";  // Mission editor category

equipment = true;

//its already a member of item namespace so dont break it
//className = "Item"; // For inventory system

// Basic Item Properties
shapeFile = "./Hat.dts";
mass = 1;
density = 0.2;
elasticity = 0.2;
friction = 0.6;
emap = true;

//gui stuff
uiName = "Demian's Hat";
iconName = "./HatIcon";
doColorShift = false;
//colorShiftColor = "0.200 0.200 0.200 1.000";

// Dynamic properties defined by the scripts
image = HatImage;
canDrop = true;
};

//Images
datablock ShapeBaseImageData(HatImage)
{
shapeFile = "./Hat.dts";
emap = true;
mountPoint = $HeadSlot;
offset = "0 -0.05 0.1";
eyeOffset = "0 0 10 1";
rotation = eulerToMatrix("0 0 0");
scale = "1 1 1";
doColorShift = false;
//colorShiftColor = "0.392 0.196 0.0 1.000";
};
datablock ShapeBaseImageData(HatImage)
{
   // Basic Item properties
   shapeFile = "base/data/shapes/empty.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0.13 0.2 -0.8";
   rotation = eulerToMatrix("0 0 0");
   eyeOffset = "0.13 0.2 -0.8";
   eyeRotation = eulerToMatrix("0 0 0");

   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off. 
   correctMuzzleVector = false;

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "ToolImage";

   // Projectile && Ammo.
   item =HatItem;

   //melee particles shoot from eye node for consistancy
   melee = true;
   //raise your arm up or not
   armReady = false;

   doColorShift = true;
   colorShiftColor = HatItem.colorShiftColor; //"0.200 0.200 0.200 1.000";

   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.

   // Initial start up state
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.5;
stateTransitionOnTimeout[0]       = "Ready";


stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "Fire";
stateAllowImageChange[1]         = true;


stateName[2]                    = "Fire";
stateTransitionOnTriggerUp[2] = "Ready";
stateScript[2]                  = "onFire";
stateSound[2]       = "HatEquipsound";
};

function HatImage::onFire(%this, %obj, %slot)
{
%client=%obj.client;
if(!%obj.Hatison)
{
%obj.Hatison = 1;
%client.centerPrint("\c6You put on the hat.",3);

for(%i = 0;$hat[%i] !$= "";%i++)
{
%obj.hideNode($hat[%i]);
}
%obj.unmountimage(1);
%obj.mountimage(Hatimage, 1);
serverPlay3d(HatEquipSound,%pos);
}else{
%obj.Hatison = 0;
%client.centerPrint("\c6You took off the hat.",3);

%obj.unmountimage(1);

%client.applyBodyParts();
%client.applyBodyColors();
serverPlay3d(HatUnequipSound,%pos);
}
}
Hopefully this should work but i haven't tested it sorry that you didn't want commands

Does the model needs some special armatures and/or empties apart from the usual Shape and Detail32. Also how would I hide the player's head node when the hat is equipped?

By the way, two image datablocks with the same name? The script doesn't work.

Wait, I get this error: Error: cannot change namespace parent linkage for Item from ShapeBase to ItemData.

Code: [Select]
datablock ItemData(IT_SkullHead)
{
category = "Item";
className = "Item";

shapeFile = "./skull.dts";
image = "IM_SkullHead";
rotate = false;
emap = true;

uiName = "Skull Head";
iconName = "Add-Ons/Weapon_Gun/icon_gun";
canDrop = true;

mass = 1;
drag = 0.1;
density = 0.1;
friction = 0.5;
elasticity = 0.1;

sticky = 0;
gravityMod = 1;
maxVelocity = -1;
dynamicType = 0;

doColorShift = false;
colorShiftColor = "0 0 0 0";
};

datablock ShapeBaseImageData(IM_SkullHead)
{
className = "ItemImage";

shapeFile = "./skull.dts";
Item = "IT_SkullHead";

emap = true;
firstPersonParticles = true;
armReady = false;
melee = false;

mountPoint = $HeadSlot;
offset = "0 -0.05 0.1";
rotation = eulerToMatrix("0 0 0");
eyeOffset = "0 0 10 1";
eyeRotation = "0 0 0 0";
correctMuzzleVector = false;

doColorShift = false;
colorShiftColor = "0 0 0 0";

stateName[0] = "Activate";
stateWaitForTimeout[2] = false;
stateTimeoutValue[0] = 0.1;
stateTransitionOnTimeout[0] = "Ready";

stateName[1] = "Ready";
stateAllowImageChange[1] = true;
stateTransitionOnTriggerDown[1] = "Equip";

stateName[2]   = "Equip";
stateScript[2]   = "onFire";
stateTransitionOnTriggerUp[1] = "Ready";
};


function IM_SkullHead::onFire(%this, %obj, %slot)
{
%client=%obj.client;
if(!%obj.HatWear)
{
%obj.HatWear = 1;
%client.centerPrint("\c6You put on the hat.",3);

for(%i = 0;$hat[%i] !$= "";%i++)
{
%obj.hideNode($hat[%i]);
}
%obj.unmountimage(1);
%obj.mountimage(IM_SkullHead, 1);
}else{
%obj.HatWear = 0;
%client.centerPrint("\c6You took off the hat.",3);

%obj.unmountimage(1);

%client.applyBodyParts();
%client.applyBodyColors();
}
}
« Last Edit: October 10, 2011, 11:28:24 AM by Demian »

I'd like to see some player-made default hats for once. Can someone please help Demian with this.

I'd like to see some player-made default hats for once. Can someone please help Demian with this.
Does not compute

TBH I'm not too sure about that error, but it should work if you change the mountpoint to 0 instead of $Headslot (you can't activate an item from your head).
Also, some of your state numbers are wrong.

Okay a lot better now. It displays the messages and the model is visible but the hat mounts my right hand. It is visible after the inventory is closed or another item is selected so that works too.

What is the mount point for the head? How do I hide the player's head node when the hat is equipped?

You'd have to make a new shape for the hat (like the one posted by swollow) and mount that to the player instead, using $Headslot as its mountpoint.

edit: to hide the head you could just do %obj.hideNode("headskin");

You'd have to make a new shape for the hat (like the one posted by swollow) and mount that to the player instead, using $Headslot as its mountpoint.

edit: to hide the head you could just do %obj.hideNode("headskin");
I can see the two ShapeBaseImageData datablocks in swollow's script but I do not know how to use them in the script. How do they differ from eachother? Why do they have the same name?

They shouldn't have the same name.

Just add this:
Code: [Select]
datablock ShapeBaseImageData(SkullHat)
{
shapeFile = "./skull.dts";
emap = true;
mountPoint = $HeadSlot;
offset = "0 -0.05 0.1";
eyeOffset = "0 0 10 1";
rotation = eulerToMatrix("0 0 0");
scale = "1 1 1";
doColorShift = false;
colorShiftColor = "0.392 0.196 0.0 1.000";
};

And change %obj.mountimage(IM_SkullHead, 1); in IM_SkullHead::onFire to %obj.mountimage(SkullHat, 1);

Okay now this is purely cosmetic fine tuning. How would I remove the image (not item) from my hand when I equip the hat and then put the image back when unequipping? So it looks like you actually put on the hat and took it off.

This is the way I did it:
Code: [Select]
datablock ItemData(IT_SkullHead)
{
category = "Item";
className = "Item";

shapeFile = "./skull.dts";
image = "IM_SkullHead";
rotate = false;
emap = true;

uiName = "Skull Head";
iconName = "Add-Ons/Weapon_Gun/icon_gun";
canDrop = true;

mass = 1;
drag = 0.1;
density = 0.1;
friction = 0.5;
elasticity = 0.1;

sticky = 0;
gravityMod = 1;
maxVelocity = -1;
dynamicType = 0;

doColorShift = false;
colorShiftColor = "0 0 0 0";
};

datablock ShapeBaseImageData(IM_SkullHead)
{
className = "ItemImage";

shapeFile = "./skull.dts";
item = "IT_SkullHead";

emap = true;
firstPersonParticles = true;
armReady = false;
melee = false;

mountPoint = 0;
offset = "0 -0.05 0.1";
rotation = eulerToMatrix("0 0 0");
eyeOffset = "0 0 10 1";
eyeRotation = "0 0 0 0";
correctMuzzleVector = false;

doColorShift = false;
colorShiftColor = "0 0 0 0";

stateName[0] = "Activate";
stateWaitForTimeout[0] = false;
stateTimeoutValue[0] = 0.1;
stateTransitionOnTimeout[0] = "Ready";

stateName[1] = "Ready";
stateAllowImageChange[1] = true;
stateTransitionOnTriggerDown[1] = "Equip";

stateName[2]  = "Equip";
stateScript[2]  = "onFire";
stateTransitionOnTriggerUp[2] = "Ready";
};

datablock ShapeBaseImageData(IM_SkullHeadEmpty)
{
className = "ItemImage";

shapeFile = "./skull.dts";
item = "IT_SkullHead";

emap = true;
firstPersonParticles = true;
armReady = false;
melee = false;

mountPoint = 0;
offset = "0 -0.05 0.1";
rotation = eulerToMatrix("0 0 0");
eyeOffset = "0 0 10 1";
eyeRotation = "0 0 0 0";
correctMuzzleVector = false;

doColorShift = false;
colorShiftColor = "0 0 0 0";

stateName[0] = "Activate";
stateWaitForTimeout[0] = false;
stateTimeoutValue[0] = 0.1;
stateTransitionOnTimeout[0] = "Ready";

stateName[1] = "Ready";
stateAllowImageChange[1] = true;
stateTransitionOnTriggerDown[1] = "Equip";

stateName[2]  = "Equip";
stateScript[2]  = "onFire";
stateTransitionOnTriggerUp[2] = "Ready";
};


function IM_SkullHead::onFire(%this, %obj, %slot)
{
%client=%obj.client;
if(!%obj.HatWear)
{
%obj.HatWear = 1;
%client.centerPrint("\c6You put on the hat.",3);

for(%i = 0;$hat[%i] !$= "";%i++)
{
%obj.hideNode($hat[%i]);
}
%obj.unmountimage(1);
%obj.mountimage(SkullHat, 1);
%obj.mountimage(IM_SkullHeadEmpty,0);
}
}

function IM_SkullHeadEmpty::onFire(%this, %obj, %slot)
{
%client=%obj.client;
if(%obj.HatWear)
{
%obj.HatWear = 0;
%client.centerPrint("\c6You took off the hat.",3);

%obj.unmountimage(1);
%obj.mountImage(IM_SkullHead,0);

%client.applyBodyParts();
%client.applyBodyColors();
}
}

function IM_SkullHead::onMount(%this,%obj,%slot)
{
if(%obj.HatWear)
{
%obj.unMountImage(0);
%obj.mountImage(IM_SkullHeadEmpty,0);
}
}

datablock ShapeBaseImageData(SkullHat)
{
shapeFile = "./skull.dts";
emap = true;
mountPoint = $HeadSlot;
offset = "0 -0.05 0.1";
eyeOffset = "0 0 10 1";
rotation = eulerToMatrix("0 0 0");
scale = "1 1 1";
doColorShift = false;
colorShiftColor = "0.392 0.196 0.0 1.000";
};

The only problem is holding down your mouse button will constantly change your hat. I'm sure this is because of how the states are set up, but I have a hard time understanding those.

edit: oops, forgot to change one of the shapefiles back since I was testing it on another model.
« Last Edit: October 10, 2011, 03:13:15 PM by Mawpius »