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 08: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,011
    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