Blockland Forums > Modification Help
Script breaks activations?
aml:
--- Quote from: Bauklotz on November 09, 2010, 10:20:57 PM ---You might also want to "hide" the shapename by using %obj.setShapeNameDistance(10); (10 is lowest) - to make it be less buggy, you might also want to package ::setShapeNameDistance to change distance to 10 all the time if they are "invisible".
--- End quote ---
Is that the name thing above all of the players name?
If so I was planning on adding that in eventually.
Anyways, I'm working on the Energy Bar decreasing as the player is invisible.
I've added some more things to the code, btw.
--- Code: ---datablock PlayerData(PlayerNinja : PlayerStandardArmor)
{
minJetEnergy = 0;
canJet = 0;
rechargeRate = 3.0;
uiName = "Ninja Player";
showEnergyBar = 1;
};
datablock PlayerData(PlayerNinjaInvisible : PlayerStandardArmor)
{
minJetEnergy = 10;
jetEnergyDrain = 5;
canJet = 0;
maxForwardSpeed = 0;
maxBackwardSpeed = 0;
maxSideSpeed = 0;
maxForwardCrouchSpeed = 0;
maxBackwardCrouchSpeed = 0;
maxSideCrouchSpeed = 0;
canRide = 0;
showEnergyBar = 1;
uiName = "";
};
package ninjaplayer
{
function Armor::onTrigger(%this,%obj,%trigger,%val)
{
if(%obj.getEnergyLevel() > 10)
{
if(%trigger == 4)
{
if(%this.getName() $= "PlayerNinja" && %val == 1)
{
%obj.changeDatablock(PlayerNinjaInvisible);
%obj.hidenode("ALL");
}
else if(%this.getName() $= "PlayerNinjaInvisible" && %val == 0)
{
%obj.changeDatablock(PlayerNinja);
%obj.unhideNode("$Pref::Avatar");
%obj.unhideNode("headskin");
}
}
}
Parent::onTrigger(%this,%obj,%trigger,%val);
}
};
activatepackage(ninjaplayer);
--- End code ---
I'm not really sure on how I could decrease the energy bar though.
Chrono:
%obj.setEnergyLevel(%obj.getEnergyLevel()-NUMBER);
How you'd do it every few seconds?
FUNction loops! :)
aml:
I'm not really good with schedule loops, but I tried.
It gets a syntax error, probably because I did the schedule wrong.
--- Code: ---package ninjaplayer
{
function Armor::onTrigger(%this,%obj,%trigger,%val)
{
if(%obj.getEnergyLevel() > 10)
{
if(%trigger == 4)
{
if(%this.getName() $= "PlayerNinja" && %val == 1)
{
%obj.changeDatablock(PlayerNinjaInvisible);
%obj.hidenode("ALL");
%obj.setEnergyLevel(%obj.getEnergyLevel()-5);
%this.schedule(500,setEnergyLevel,%obj.getEnergyLevel()-5);
}
else if(%this.getName() $= "PlayerNinjaInvisible" && %val == 0)
{
%obj.changeDatablock(PlayerNinja);
%obj.unhideNode("$Pref::Avatar");
%obj.unhideNode("headskin");
}
}
}
Parent::onTrigger,%this,%obj,%trigger,%val);
}
};
activatepackage(ninjaplayer);
--- End code ---
Edit: I accidentelly deleted a paranthysis on the Parent part so that was causing the error.
I still can't get the schedule loop to work D:
Chrono:
That would just do it twice.
You have to make a new function and loop that.
--- Code: ---function Player::cloakDrain(%obj)
{
cancel(%obj.cloakdrainloop);
%obj.setEnergyLevel(%obj.getEnergyLevel()-5);
%obj.cloakDrainLoop = %obj.schedule(500,cloakDrain);
}
package ninjaplayer
{
function Armor::onTrigger(%this,%obj,%trigger,%val)
{
if(%obj.getEnergyLevel() > 10)
{
if(%trigger == 4)
{
if(%this.getName() $= "PlayerNinja" && %val == 1)
{
%obj.changeDatablock(PlayerNinjaInvisible);
%obj.hidenode("ALL");
%obj.cloakDrain();
}
else if(%this.getName() $= "PlayerNinjaInvisible" && %val == 0)
{
%obj.changeDatablock(PlayerNinja);
%obj.unhideNode("$Pref::Avatar");
%obj.unhideNode("headskin");
cancel(%obj.cloakdrainLoop);
}
}
}
Parent::onTrigger,%this,%obj,%trigger,%val);
}
};
activatepackage(ninjaplayer);
--- End code ---