if you want to call something when a player spawns as a particular datablock, you can define a function as
SomePlayerArmor::onAdd(%datablock, %obj) (replace
SomePlayerArmor with your datablock's name)
there's also
SomePlayerArmor::onNewDatablock(%datablock, %obj) it seems and i'm not sure what the practical difference between the two is, or if there is one, i'm just looking at some old code i made and for some reason i used both so i figured i'd mention this one too. i feel like onAdd should catch all cases tho
edit:
onNewDatablock is called when you change datablocks, while onAdd is just a callback for when an object is created with that datablock. when you use onNewDatablock make sure to call the parent tho (ie
parent::onNewDatablock(%datablock, %obj); ) since
Armor::onNewDatablock actually has default functionality
Here's an example player loop:
function Player::moveloop(%this)
{
announce(%this.getVelocity());
%this.moveloop = %this.schedule(1000,moveloop);
}
if you want to cancel it type cancel(findclientbyname(yourname).player.moveloop); in console
to add onto this, it's generally good practice to cancel the loop at the beginning of the loop function:
function Player::moveloop(%this)
{
if(isEventPending(%this.moveloop)) //not sure if this if statement is really considered necessary, just force of habit for me
cancel(%this.moveloop);
announce(%this.getVelocity());
%this.moveloop = %this.schedule(1000,moveloop);
} that way you can only ever be running one loop at a time. without this, if moveloop were called a second time, it would begin another loop, and if called again, a third loop, and so on, and you would only ever be able to keep track of one of these loops at a time. as you might imagine, this can cause unexpected and wrong behavior and really make things generally difficult to deal with