Blockland Forums > Modification Help
Making hats? (New feature idea)
<< < (5/7) > >>
Mawpius:

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

edit: also using
--- Quote from: infiniteLoop ---%obj.playThread(3,"shiftAway");
--- End quote ---
for taking on/off the hat looks fine.
infiniteLoop:

--- Quote from: Mawpius on October 11, 2011, 01:28:25 PM ---edit: also using %obj.schedule(0,"playThread",3,shiftAway); for taking on/off the hat looks fine.

--- End quote ---

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

--- Quote from: Mawpius on October 11, 2011, 01:28:25 PM ---
--- Code: ---function IM_hatItem::onMount(%this, %obj, %slot)
{
if(%obj.HatWear)
{
%obj.unMountImage(0);
%obj.mountimage(IM_hatEmpty,0);
}
}
--- End code ---
Adding that bit to the end of the code should work.

--- End quote ---
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.
Demian:
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: ---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);
}
}
--- End code ---
Mawpius:
I'm sure there's a better way than this, but it works:

--- Code: ---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);
--- End code ---
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
Navigation
Message Index
Next page
Previous page

Go to full version