Raised This Month: $ Target: $400
 0% 

Model Restrict Bug/Question.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Ticketry
Member
Join Date: Mar 2016
Location: Sacramento, CA
Old 04-15-2016 , 10:41   Model Restrict Bug/Question.
Reply With Quote #1

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?

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");
  }
Ticketry is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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