Making hats? (New feature idea)

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

How do you play multiple animations one after another? Like right hand shift away and root after that.
« Last Edit: October 10, 2011, 02:49:46 PM by Demian »

You could do something like..
Code: [Select]
%obj.schedule(0,"playthread",0,sit);
%obj.schedule(500,"playthread",1,activate2);
%obj.schedule(1000,"playthread",0,root);

Not my style but this situation calls for it: http://www.youtube.com/watch?v=P3ALwKeSEYs

Thank you for the fast help! I'll fiddle a bit more with the states and animation timings, but otherwise it is perfect.



Here's the script. The animation timings are off.
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 = true;
colorShiftColor = "1 1 0.949 1";
};

datablock ShapeBaseImageData(IM_Skull)
{
shapeFile = "./skull.dts";
emap = true;
mountPoint = $HeadSlot;
offset = "0 0 0";
eyeOffset = "0 0 10 1";
rotation = eulerToMatrix("0 0 0");
scale = "1 1 1";
doColorShift = true;
colorShiftColor = "1 1 0.949 1";
};

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

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

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

mountPoint = 0;
offset = "0 0 0";
rotation = eulerToMatrix("0 0 0");
eyeOffset = "0 0 0 0";
eyeRotation = "0 0 0 0";
correctMuzzleVector = false;

doColorShift = true;
colorShiftColor = "1 1 0.949 1";

stateName[0] = "Ready";
stateAllowImageChange[0] = true;
stateWaitForTimeout[0] = true;
stateTimeoutValue[0] = 0.1;
stateTransitionOnTriggerDown[0] = "Equip";

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

function IM_SkullHead::onFire(%this, %obj, %slot)
{
%client=%obj.client;
if(!%obj.HatWear)
{
%obj.HatWear = 1;

for(%i = 0;$hat[%i] !$= "";%i++)
{
%obj.hideNode($hat[%i]);
%obj.hideNode("headskin");
}
%obj.unMountImage(1);
%obj.mountimage(IM_Skull, 1);
%obj.unMountImage(0);
%obj.mountimage(IM_SkullHeadEmpty,0);
%obj.schedule(0,"playThread",1,shiftAway);
%obj.schedule(1000,"playThread",1,root);
//%obj.playThread(1, root);
}
}

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

shapeFile = "base/data/shapes/empty.dts";
Item = "IT_SkullHead";

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

mountPoint = 0;
offset = "0 0 0";
rotation = eulerToMatrix("0 0 0");
eyeOffset = "0 0 0 0";
eyeRotation = "0 0 0 0";
correctMuzzleVector = false;

doColorShift = true;
colorShiftColor = "1 1 0.949 1";

stateName[0] = "Ready";
stateAllowImageChange[0] = true;
stateWaitForTimeout[0] = true;
stateTimeoutValue[0] = 0.1;
stateTransitionOnTriggerDown[0] = "Equip";

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

function IM_SkullHeadEmpty::onFire(%this, %obj, %slot)
{
%client=%obj.client;
if(%obj.HatWear)
{
%obj.HatWear = 0;

%obj.unMountImage(1);
%obj.unHideNode("headskin");
%obj.unMountImage(0);
%obj.mountimage(IM_SkullHead,0);
%obj.schedule(0,"playThread",1,shiftAway);
%obj.schedule(1000,"playThread",1,armreadyright);

%client.applyBodyParts();
%client.applyBodyColors();
}
}
« Last Edit: October 10, 2011, 03:08:52 PM by Demian »

I'm glad it worked out :p

I would really like to release the finished script as a resource for others who would fancy making a hat of their own. This is why I need to make sure the script works perfectly without bugs. Here's the template hat add-on.

http://mirror.dataorb.net/Item_HatItem.zip

I'll finish the work on animations later. Now, there's a bug. I equip the hat, close inventory, open inventory and select the hat again. This causes another hat to appear in my hand making it impossible to remove the already equipped hat. I do not know how to fix this. Help please.
« Last Edit: October 12, 2011, 09:35:51 AM by Demian »

Code: [Select]
function IM_hatItem::onMount(%this, %obj, %slot)
{
if(%obj.HatWear)
{
%obj.unMountImage(0);
%obj.mountimage(IM_hatEmpty,0);
}
}
Adding that bit to the end of the code should work.

edit: also using
Quote from: infiniteLoop
%obj.playThread(3,"shiftAway");
for taking on/off the hat looks fine.
« Last Edit: October 11, 2011, 01:26:27 PM by Mawpius »

edit: also using %obj.schedule(0,"playThread",3,shiftAway); for taking on/off the hat looks fine.

%obj.playThread(3,"shiftAway");

Code: [Select]
function IM_hatItem::onMount(%this, %obj, %slot)
{
if(%obj.HatWear)
{
%obj.unMountImage(0);
%obj.mountimage(IM_hatEmpty,0);
}
}
Adding that bit to the end of the code should work.
Indeed it does. Thank you. I'll keep working with the hat and ask help if I find more bugs I can't fix. So far it seems like the script is done. Time to work on the animations.

New bug. I attempted to create a separate item for the "empty" hat that you could not drop. This is to prevent people from getting their hats stuck to their heads. For some reason this doesn't work. The "empty" image uses the new item but I can still drop it.

After I've dropped the item I can still click to un/equip the hat even though the item itself isn't in my inventory. How to fix this bug and make the non-droppable item work?

Code: [Select]
datablock ItemData(IT_hatItem)
{
shapeFile = "./hat.dts"; //Hat model, when spawned.
image = "IM_hatItem";
rotate = false;

uiName = "Hat Item"; //Hat name.
iconName = "Add-Ons/Weapon_Gun/icon_gun"; //Hat inventory icon.
canDrop = true;

mass = 1;
drag = 0.5;
density = 0.2;
friction = 0.6;
elasticity = 0.2;
gravityMod = 1;

doColorShift = true;
colorShiftColor = "1 1 0.949 1"; //Color of the hat icon and item when spawned.
};

datablock ItemData(IT_hatEmpty : IT_hatItem)
{
shapeFile = "./hat.dts"; //Hat model, when spawned.
image = "IM_hatEmpty";
rotate = false;

uiName = ""; //Hat name.
iconName = "Add-Ons/Weapon_Gun/icon_gun"; //Hat inventory icon.
canDrop = false;

mass = 1;
drag = 0.5;
density = 0.2;
friction = 0.6;
elasticity = 0.2;
gravityMod = 1;

doColorShift = true;
colorShiftColor = "1 1 0.949 1"; //Color of the hat icon and item when spawned.
};

datablock ShapeBaseImageData(IM_hatHead)
{
shapeFile = "./hat.dts";
emap = true;
mountPoint = $HeadSlot;
offset = "0 0 0";
eyeOffset = "0 0 10 1";
rotation = eulerToMatrix("0 0 0");
scale = "1 1 1";
doColorShift = true;
colorShiftColor = "1 1 0.949 1"; //Color of the hat when worn.
};

datablock ShapeBaseImageData(IM_hatItem)
{
shapeFile = "./hat.dts";
Item = "IT_hatItem";

firstPersonParticles = true;
armReady = true;

mountPoint = 0;
offset = "0 0 0";
rotation = eulerToMatrix("0 0 0");
eyeOffset = "0 0 0 0";
eyeRotation = "0 0 0 0";

doColorShift = true;
colorShiftColor = "1 1 0.949 1"; //Color of the hat on hand.

stateName[0] = "Active";
stateWaitForTimeout[0] = true;
stateTimeoutValue[0] = 0.03;
stateTransitionOnTriggerDown[0] = "Ready";

stateName[1]   = "Ready";
stateAllowImageChange[1]   = false;
stateWaitForTimeout[1]   = true;
stateTimeoutValue[1]   = 0.03;
stateTransitionOnTriggerUp[1] = "Equip";

stateName[2] = "Equip";
stateAllowImageChange[2] = true;
stateScript[2] = "onFire";
stateWaitForTimeout[2] = true;
stateTimeoutValue[2] = 0.03;
stateTransitionOnTimeout[2] = "Ready";
};

function IM_hatItem::onFire(%this, %obj, %slot)
{
%client=%obj.client;
if(!%obj.Wear)
{
%obj.Wear = 1;

for(%i = 0;$hat[%i] !$= "";%i++)
{
%obj.hideNode($hat[%i]);
//%obj.hideNode("headskin"); //Hides player's head.
}
%obj.unMountImage(1);
%obj.mountimage(IM_hatHead, 1);
%obj.unMountImage(0);
%obj.mountimage(IM_hatEmpty,0);
%obj.schedule(0,"playThread",2,shiftAway);
%obj.schedule(190,"playThread",1,root);
}
}

datablock ShapeBaseImageData(IM_hatEmpty)
{
shapeFile = "base/data/shapes/empty.dts";
Item = "IT_hatEmpty";

firstPersonParticles = true;
armReady = true;

mountPoint = 0;
offset = "0 0 0";
rotation = eulerToMatrix("0 0 0");
eyeOffset = "0 0 0 0";
eyeRotation = "0 0 0 0";

doColorShift = true;
colorShiftColor = "1 1 0.949 1"; //Color of the hat icon.

stateName[0] = "Active";
stateWaitForTimeout[0] = true;
stateTimeoutValue[0] = 0.03;
stateTransitionOnTriggerDown[0] = "Ready";

stateName[1]   = "Ready";
stateAllowImageChange[1]   = false;
stateWaitForTimeout[1]   = true;
stateTimeoutValue[1]   = 0.03;
stateTransitionOnTriggerUp[1] = "Equip";

stateName[2] = "Equip";
stateAllowImageChange[2] = true;
stateScript[2] = "onFire";
stateWaitForTimeout[2] = true;
stateTimeoutValue[2] = 0.03;
stateTransitionOnTimeout[2] = "Ready";
};

function IM_hatEmpty::onFire(%this, %obj, %slot)
{
%client=%obj.client;
if(%obj.Wear)
{
%obj.Wear = 0;

%obj.unMountImage(1);
//%obj.unHideNode("headskin"); //Unhides player's head.
%obj.unMountImage(0);
%obj.mountimage(IM_hatItem,0);
%obj.playThread(2, shiftAway);
%obj.playThread(1, armReadyRight);

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

function IM_hatItem::onMount(%this, %obj, %slot)
{
if(%obj.Wear)
{
%obj.unMountImage(0);
%obj.mountimage(IM_hatEmpty,0);
}
}

I'm sure there's a better way than this, but it works:
Code: [Select]
datablock ShapeBaseImageData(IM_hatHead)
{
shapeFile = "./hat.dts";
emap = true;
mountPoint = $HeadSlot;
offset = "0 0 0";
eyeOffset = "0 0 10 1";
rotation = eulerToMatrix("0 0 0");
scale = "1 1 1";
doColorShift = true;
colorShiftColor = "1 1 0.949 1"; //Color of the hat when worn.
};

datablock ShapeBaseImageData(IM_hatItem)
{
shapeFile = "./hat.dts";
Item = "IT_hatItem";

firstPersonParticles = true;
armReady = true;

mountPoint = 0;
offset = "0 0 0";
rotation = eulerToMatrix("0 0 0");
eyeOffset = "0 0 0 0";
eyeRotation = "0 0 0 0";

doColorShift = true;
colorShiftColor = IM_hatHead.colorShiftColor; //Color of the hat on hand.

stateName[0] = "Active";
stateWaitForTimeout[0] = true;
stateTimeoutValue[0] = 0.03;
stateTransitionOnTriggerDown[0] = "Ready";

stateName[1]   = "Ready";
stateAllowImageChange[1]   = false;
stateWaitForTimeout[1]   = true;
stateTimeoutValue[1]   = 0.03;
stateTransitionOnTriggerUp[1] = "Equip";

stateName[2] = "Equip";
stateAllowImageChange[2] = true;
stateScript[2] = "onFire";
stateWaitForTimeout[2] = true;
stateTimeoutValue[2] = 0.03;
stateTransitionOnTimeout[2] = "Ready";
};

datablock ItemData(IT_hatItem)
{
shapeFile = "./hat.dts"; //Hat model, when spawned.
image = "IM_hatItem";
rotate = false;

hatItem = true;

uiName = "Hat Item"; //Hat name.
iconName = "Add-Ons/Weapon_Gun/icon_gun"; //Hat inventory icon.
canDrop = true;

mass = 1;
drag = 0.5;
density = 0.2;
friction = 0.6;
elasticity = 0.2;
gravityMod = 1;

doColorShift = true;
colorShiftColor = IM_hatHead.colorShiftColor; //Color of the hat icon and item when spawned.
};

function IM_hatItem::onFire(%this, %obj, %slot)
{
%client=%obj.client;
if(!%obj.Wear)
{
%obj.Wear = 1;

for(%i = 0;$hat[%i] !$= "";%i++)
{
%obj.hideNode($hat[%i]);
//%obj.hideNode("headskin"); //Hides player's head.
}
%obj.unMountImage(1);
%obj.mountimage(IM_hatHead, 1);
%obj.unMountImage(0);
%obj.mountimage(IM_hatEmpty,0);
%obj.schedule(0,"playThread",2,shiftAway);
%obj.schedule(190,"playThread",1,root);
}
}

datablock ShapeBaseImageData(IM_hatEmpty : IM_HatItem)
{
shapeFile = "base/data/shapes/empty.dts";
};

function IM_hatEmpty::onFire(%this, %obj, %slot)
{
%client=%obj.client;
if(%obj.Wear)
{
%obj.Wear = 0;

%obj.unMountImage(1);
//%obj.unHideNode("headskin"); //Unhides player's head.
%obj.unMountImage(0);
%obj.mountimage(IM_hatItem,0);
%obj.playThread(2, shiftAway);
%obj.playThread(1, armReadyRight);

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

function IM_hatItem::onMount(%this, %obj, %slot)
{
if(%obj.Wear)
{
%obj.unMountImage(0);
%obj.mountimage(IM_hatEmpty,0);
}
}

package hatitempackage
{
function serverCmdDropTool(%client,%slot)
{
if(nameToID(%client.player.tool[%slot]).hatItem)
{
if(%client.player.Wear)
{
%client.player.Wear = 0;
%client.player.unMountImage(0);
%client.player.unMountImage(1);
%client.applyBodyParts();
%client.applyBodyColors();
}
}
parent::serverCmdDropTool(%client,%slot);
}
};
activatePackage(hatitempackage);
Packaged serverCmdDropTool to check if the player is wearing the hat (and is dropping the hat item), if so it'll unMount. I also cleaned up a bit, and the colorShiftColor for the spawn item and the item in hand will be the same as the actual hat images colorShiftColor now.

edit: oops had to fix something, sorry
« Last Edit: October 12, 2011, 01:24:33 PM by Mawpius »

Oh wow. That is even better than I wanted. You're amazing! Still messing around with it.

Download Heedicalkings body armor script.
Syntax is a little messy, but it does what demian wants.
Just try to remove the damage reduction part of the script.

Oh wow. That is even better than I wanted. You're amazing! Still messing around with it.
This is awesome
I suppose you could put some of GearMod into th pack

This is awesome
I suppose you could put some of GearMod into th pack
I'm releasing the script as resource when I have time.

New idea. How about being able to wear multiple hats at once? Mawpius?

I'm releasing the script as resource when I have time.

New idea. How about being able to wear multiple hats at once? Mawpius?
Good finally multiple hats