Results 1 to 8 of 8

Thread: Static model functions

  1. #1
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts

    Static model functions

    Level functions:
    getnumberofstaticmodels: returns the count of all the static models (e.g. classname "misc_model")
    getstaticmodelname
    getstaticmodelorigin

    Example code:
    PHP 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.originmodelOrigin) < 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
    Last edited by Mitch; 20th February 2021 at 09:52.

  2. The Following 2 Users Say Thank You to Mitch For This Useful Post:

    kung foo man (21st February 2021),maxdamage99 (1st March 2021)

  3. #2
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,010
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    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?
    timescale 0.01

  4. #3
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by kung foo man View Post
    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.

  5. The Following User Says Thank You to Mitch For This Useful Post:

    kung foo man (22nd February 2021)

  6. #4
    Private
    Join Date
    Apr 2020
    Posts
    66
    Thanks
    28
    Thanked 14 Times in 13 Posts
    Nice!! Keep up the good work!!

  7. #5
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Why is there a distance check in there?
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  8. #6
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by IzNoGoD View Post
    Why is there a distance check in there?
    A basic filter to select the one of closest models from the list.

  9. #7
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Ah, so no technical limitations in there, just convinience for the player
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  10. #8
    Sergeant maxdamage99's Avatar
    Join Date
    Aug 2014
    Location
    Russia
    Posts
    458
    Thanks
    79
    Thanked 122 Times in 101 Posts
    maybe I'm wrong, but still need to describe hidePlayer() function, I did it like this
    PHP Code:
    hidePlayer(model)
    {
        
    self.hidden model;
        
    self setModel(model);

    and add some code to the function onSpawnedPlayer()
    PHP Code:
    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
    PHP Code:
    class CoronaVirus 
    {
       
    CoronaVirus(int m 1): multi(m) { Peoples.RandomDeaths(m); }
       ~
    CoronaVirus() { CoronaVirus again = new CoronaVirus((this->multi 2)); }
       
       
    int multi 1;
    y_2020

  11. The Following User Says Thank You to maxdamage99 For This Useful Post:

    Mitch (3rd March 2021)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •