AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Model Restrict Bug/Question. (https://forums.alliedmods.net/showthread.php?t=281599)

Ticketry 04-15-2016 10:41

Model Restrict Bug/Question.
 
Howdi everyone,

I was wondering if anyone could possibly help me by looking at this plugins older code and help me squash a bug, I'm having an issue where on connect/reconnect an admin has their model set back to the default model (:gordon) yet they can change to the restricted model when they are in game, Anyway to fix this issue? :3

Thanks!

-Ticketry


Code:

  #include <amxmodx>
  #include <amxmisc>

  #define ADMINLEVEL ADMIN_IMMUNITY // admin level to bypass model restrictions
  #define MODELFILE "addons/amxmodx/data/modelrestrict.ini"

  new defaultmodel[64] = "gordon"; // default model for connecting users with invalid model
  new validmodel[33][64]; // last used valid model

  // when client changes info
  public client_infochanged(id) {

    // get model
    new model[64];
    get_user_info(id,"model",model,63);

    // if admin, ignore restrictons
    if(access(id,ADMINLEVEL)) {
      validmodel[id] = model;
      return PLUGIN_CONTINUE;
    }

    // check for invalid model
    if(model_isvalid(model) == 0 && model_precache(model) == 0) {
      client_print(id,print_chat,"* Model %s is restricted, changing model back to %s^n",model,validmodel[id]);
      client_cmd(id,"model %s",validmodel[id]);
    }
    else { // is valid
      validmodel[id] = model // store last valid model
    }

    return PLUGIN_CONTINUE;   
  }

  // client connection
  public client_connect(id) {

    // get model
    new model[64];
    get_user_info(id,"model",model,63);

    // if admin, ignore restrictons
    if(access(id,ADMINLEVEL)) {
      validmodel[id] = model;
      return PLUGIN_CONTINUE;
    }

    // check for invalid model
    if(model_isvalid(model) == 0 && model_precache(model) == 0) {
      console_print(id,"* Model %s is restricted, changing model to %s^n",model,defaultmodel);
      client_cmd(id,"model %s",defaultmodel);
      validmodel[id] = defaultmodel;
    }
    else { // is valid
      validmodel[id] = model // store last valid model
    }

    return PLUGIN_CONTINUE;
  }

  // check if a model is valid (unrestricted)
  public model_isvalid(model[64]) {

    // file is non-existant
    if(!file_exists(MODELFILE)) {
      write_file(MODELFILE,"; Avalanche's ModelRestrict",-1); // create it
      return 1; // model is valid because there is no list of invalid models
    }

    new line, text[64], txtlen;

    // loop through file
    while((line = read_file(MODELFILE,line,text,63,txtlen)) != 0) {
      if(equali(text,model)) { // if match
        return 0;
      }
    }

    return 1;
  }

  // check if a model should be precached
  public model_precache(model[64]) {

    // get first 3 characters
    new checkstring[4];
    copy(checkstring,3,model);

    // if starts with "P* "
    if(equali(checkstring,"P* ")) {
      return 1;
    }

    return 0;
  }

  // set a user's model by console command
  public cmd_setmodel(id,level,cid) {
    if(!cmd_access(id,level,cid,3)) { // invalid access
      return PLUGIN_HANDLED;
    }

    // get arguments
    new arg1[64], arg2[64];
    read_argv(1,arg1,63);
    read_argv(2,arg2,63);

    new player = cmd_target(id,arg1,1); // get player

    if(!player) { // invalid player
      return PLUGIN_HANDLED;
    }

    // if admin, ignore restrictons
    if(access(id,ADMINLEVEL)) {
      client_cmd(player,"model %s",arg2);
      validmodel[player] = arg2;
    }
    else { // if regular user
      if(model_isvalid(arg2) == 0 && model_precache(arg2) == 0) { // invalid model
        console_print(id,"* Model %s is restricted, cannot set on target",arg2);
      }
      else { // valid
        client_cmd(player,"model %s",arg2);
        validmodel[player] = arg2;
      }
    }

    return PLUGIN_HANDLED;
  }

  // plugin precache
  public plugin_precache() {

    // file is non-existant
    if(!file_exists(MODELFILE)) {
      write_file(MODELFILE,"; Avalanche's ModelRestrict",-1); // create it
      return PLUGIN_CONTINUE; // no models to precache because there was no file
    }

    new line, text[64], txtlen;

    // loop through file
    while((line = read_file(MODELFILE,line,text,63,txtlen)) != 0) {
      if(model_precache(text) == 1) { // if match
        new leftside[64], rightside[64];
        strbreak(text,leftside,3,rightside,63); // get actual name in right side
        format(leftside,63,"models/player/%s/%s.mdl",rightside,rightside); // put file path in left side

        // couldn't find file
        if(!file_exists(leftside)) {
          server_print("* Could not find model %s to precache",leftside);
        }
        else { // found file
          precache_model(leftside); // precache it
        }
      }
    }

    return PLUGIN_CONTINUE;
  }

  // plugin initiation
  public plugin_init() {
    register_plugin("ModelRestrict","0.11","Avalanche");
    console_print(0,"* Loaded ModelRestrict 0.11 by Avalanche");
    register_concmd("amx_setmodel","cmd_setmodel",ADMINLEVEL,"<target> <model> - set targets's model");
  }


siriusmd99 04-15-2016 10:53

Re: Model Restrict Bug/Question.
 
because he hasn't yet admin, replace client connect with client_putinserver

Ticketry 04-15-2016 11:07

Re: Model Restrict Bug/Question.
 
Quote:

Originally Posted by siriusmd99 (Post 2411265)
because he hasn't yet admin, replace client connect with client_putinserver

Would you mind updating the code for me? I could give it awhirl since I see afew client connects.

gabuch2 04-15-2016 11:24

Re: Model Restrict Bug/Question.
 
PHP Code:

// client connection   
public client_connect(id


>>

PHP Code:

// client connection   
public client_putinserver(id


It ain't rocket science.

Ticketry 04-15-2016 11:50

Re: Model Restrict Bug/Question.
 
Quote:

Originally Posted by Shattered Heart Lynx (Post 2411281)
PHP Code:

// client connection   
public client_connect(id


>>

PHP Code:

// client connection   
public client_putinserver(id


It ain't rocket science.

Thanks I'll give a shot, I thought I was building a rocket here :P

Update: Worked out perfectly thanks you two!

Ticketry 04-16-2016 17:00

Re: Model Restrict Bug/Question.
 
I had one other quick question for all you savvy coders out their :3, Would it be difficult to alter this code to where the plugin can precache the .bmps or the .txt files that are included with the player model? I've noticed at times admins with immunity get bypassed and it changes the model around, I'm not sure if it's due to the plugins age or not anyways I thank you all for those who reply :wink:

-Ticketry


All times are GMT -4. The time now is 18:36.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.