PDA

View Full Version : Static model functions



Mitch
19th February 2021, 16: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

kung foo man
21st February 2021, 07:23
Wow, nice work! Was a bit confused what type "direction" is... until I saw it treated like an integer. Do you still work on the docs aswell?

Mitch
21st February 2021, 11:43
Wow, nice work! Was a bit confused what type "direction" is... until I saw it treated like an integer. Do you still work on the docs aswell?

Yes, I work sometimes on the docs when I got the time for it.
Currently there are quite a few libcod functions missing, but first I want to check and remove stock functions from CoD4 and add the missing CoD2 functions.

agribilos
21st February 2021, 15:24
Nice!! Keep up the good work!!

IzNoGoD
21st February 2021, 17:31
Why is there a distance check in there?

Mitch
21st February 2021, 18:03
Why is there a distance check in there?

A basic filter to select the one of closest models from the list.

IzNoGoD
21st February 2021, 20:12
Ah, so no technical limitations in there, just convinience for the player

maxdamage99
1st March 2021, 06:59
maybe I'm wrong, but still need to describe hidePlayer() function, I did it like this


hidePlayer(model)
{
self.hidden = model;
self setModel(model);
}

and add some code to the function onSpawnedPlayer()


onSpawnedPlayer()
{
if (self.pers["team"] == "allies")
{
if (!isDefined(self.hidden))
self.hidden = "null";

self thread monitorKeysHiders();
}
}

it works for me, but I'm not sure what is correct :)