Mitch
19th February 2021, 15:27
Level functions:
getnumberofstaticmodels: returns the count of all the static models (e.g. classname "misc_model")
getstaticmodelname
getstaticmodelorigin
Example code:
onSpawnedPlayer()
{
if (self.pers["team"] == "allies")
{
self thread monitorKeysHiders();
}
}
monitorKeysHiders()
{
self endon("disconnect");
self endon("killed_player");
pressedUpdateModelLeft = false;
pressedUpdateModelRight = false;
for (;;)
{
if (isDefined(self.hidden) && self leanleftButtonPressed() && !pressedUpdateModelLeft) {
pressedUpdateModelLeft = true;
if (self useButtonPressed()) {
self updatePlayerModelInRange(-1);
self iprintlnbold("Switching to previous object in range.");
} else {
self updatePlayerModel(-1);
self iprintlnbold("Switching to previous object.");
}
} else if (!self leanleftButtonPressed()) {
pressedUpdateModelLeft = false;
}
if (isDefined(self.hidden) && self leanrightButtonPressed() && !pressedUpdateModelRight) {
pressedUpdateModelRight = true;
if (self useButtonPressed()) {
self updatePlayerModelInRange(1);
self iprintlnbold("Switching to next object in range.");
} else {
self updatePlayerModel(1);
self iprintlnbold("Switching to next object.");
}
} else if (!self leanrightButtonPressed()) {
pressedUpdateModelRight = false;
}
wait 0.05;
}
}
updatePlayerModelInRange(direction)
{
countdown = getNumberOfStaticModels();
nextModel = getNextPlayerModel(direction);
while (isDefined(nextModel) && isDefined(self.hidden) && countdown >= 0)
{
modelOrigin = getStaticModelOrigin(self.selectedmodel);
if (isDefined(nextModel) && DistanceSquared(self.origin, modelOrigin) < 20000 && self.hidden != "xmodel/" + nextModel)
{
break;
}
nextModel = getNextPlayerModel(direction);
countdown--;
}
if (countdown < 0) {
self iprintlnbold("Unable to find an object in range.");
} else if (isDefined(nextModel)) {
self hidePlayer("xmodel/" + nextModel);
}
}
updatePlayerModel(direction)
{
nextModel = getNextPlayerModel(direction);
while (isDefined(nextModel) && isDefined(self.hidden) && self.hidden == "xmodel/" + nextModel)
{
nextModel = self getNextPlayerModel(direction);
}
if (isDefined(nextModel))
self hidePlayer("xmodel/" + nextModel);
}
getNextPlayerModel(direction)
{
models = getNumberOfStaticModels();
if (models > 0) {
if (!isDefined(self.selectedmodel)) {
self.selectedmodel = 0;
} else {
self.selectedmodel += direction;
}
if (self.selectedmodel < 0) {
self.selectedmodel = models - 1;
} else if (self.selectedmodel >= models) {
self.selectedmodel = 0;
}
return getStaticModelName(self.selectedmodel);
} else {
return undefined;
}
}
Video: https://youtu.be/gkB3LH9YU-M
Supported libcod: https://github.com/voron00/libcod
getnumberofstaticmodels: returns the count of all the static models (e.g. classname "misc_model")
getstaticmodelname
getstaticmodelorigin
Example code:
onSpawnedPlayer()
{
if (self.pers["team"] == "allies")
{
self thread monitorKeysHiders();
}
}
monitorKeysHiders()
{
self endon("disconnect");
self endon("killed_player");
pressedUpdateModelLeft = false;
pressedUpdateModelRight = false;
for (;;)
{
if (isDefined(self.hidden) && self leanleftButtonPressed() && !pressedUpdateModelLeft) {
pressedUpdateModelLeft = true;
if (self useButtonPressed()) {
self updatePlayerModelInRange(-1);
self iprintlnbold("Switching to previous object in range.");
} else {
self updatePlayerModel(-1);
self iprintlnbold("Switching to previous object.");
}
} else if (!self leanleftButtonPressed()) {
pressedUpdateModelLeft = false;
}
if (isDefined(self.hidden) && self leanrightButtonPressed() && !pressedUpdateModelRight) {
pressedUpdateModelRight = true;
if (self useButtonPressed()) {
self updatePlayerModelInRange(1);
self iprintlnbold("Switching to next object in range.");
} else {
self updatePlayerModel(1);
self iprintlnbold("Switching to next object.");
}
} else if (!self leanrightButtonPressed()) {
pressedUpdateModelRight = false;
}
wait 0.05;
}
}
updatePlayerModelInRange(direction)
{
countdown = getNumberOfStaticModels();
nextModel = getNextPlayerModel(direction);
while (isDefined(nextModel) && isDefined(self.hidden) && countdown >= 0)
{
modelOrigin = getStaticModelOrigin(self.selectedmodel);
if (isDefined(nextModel) && DistanceSquared(self.origin, modelOrigin) < 20000 && self.hidden != "xmodel/" + nextModel)
{
break;
}
nextModel = getNextPlayerModel(direction);
countdown--;
}
if (countdown < 0) {
self iprintlnbold("Unable to find an object in range.");
} else if (isDefined(nextModel)) {
self hidePlayer("xmodel/" + nextModel);
}
}
updatePlayerModel(direction)
{
nextModel = getNextPlayerModel(direction);
while (isDefined(nextModel) && isDefined(self.hidden) && self.hidden == "xmodel/" + nextModel)
{
nextModel = self getNextPlayerModel(direction);
}
if (isDefined(nextModel))
self hidePlayer("xmodel/" + nextModel);
}
getNextPlayerModel(direction)
{
models = getNumberOfStaticModels();
if (models > 0) {
if (!isDefined(self.selectedmodel)) {
self.selectedmodel = 0;
} else {
self.selectedmodel += direction;
}
if (self.selectedmodel < 0) {
self.selectedmodel = models - 1;
} else if (self.selectedmodel >= models) {
self.selectedmodel = 0;
}
return getStaticModelName(self.selectedmodel);
} else {
return undefined;
}
}
Video: https://youtu.be/gkB3LH9YU-M
Supported libcod: https://github.com/voron00/libcod