Raised This Month: $ Target: $400
 0% 

Entity Resources Replacement[ V 1.4 ]


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Gameplay       
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-20-2014 , 15:18   Entity Resources Replacement[ V 1.4 ]
Reply With Quote #1


Entity Resources Replacement 1.4
Release: 20.10.2014 | Last Update: 29.06.2016

IF YOU ARE UPDATING FROM VERSION 1.3: REMOVE YOUR OLD CONFIGURATION FILES AND DOWNLOAD NEW ONES(INSIDE ARCHIVE). THEY WERE REWRITTEN, ALSO A TYPO IN DYNAMIC REPLACEMENT FILE NAME WAS FIXED.

Table of Contents

Description top

Even if the name may be confusing, this is a very simple and easy-to-use plugin. The aim is to be the ultimate solution for changing models/sprites/sounds.

It provide two ways of replacing:
  • Complete replacement
    • Pros
      • Work in all HL mods.
      • Using better methods to accomplish the same results. The memory is patched at map start, just one time. This brings some drawbacks, you can read them below.
      • All-In-One, you can change sprites,sound and models. It's not only for weapons.
      • Easy to configure.
      • The old resources are not precached, so it won't increase the precache list, it won't over 512
    • Cons
      • The string that will replace another one must have a size lower or equal than the original one. Not a big deal, just rename it if it's too long.
      • You can't change things per player, you can't have resources for vips and another resources for normal players or stuff like that. Everything is global.
  • DynamicReplacement
    • Pros
      • Allow you to change dynamically player models, weapon models & sounds]
      • You can change them only for a player, only for a team, for admins or for all.
      • You can also replace a specific model with another one.
      • As you can see, all the cons from the complete replacement become pros here. By combining this two ways I'm sure you won't need another replacement plugin.
    • Cons
      • It will increase the precache limit

Please read the full post, if you want to be able to run this plugin properly and to take advantage of all features that it's providing.

From version 1.3 a version checker was included. This mean that the plugin will connect to http://hamletplugins.comyr.com/test.html to get the lastest version and inform you if you are running the latest one or you should update. It also gets the changelog for the next version. If you are running an older one the plugin will automatically print the changelog for latest version so you know what changes were done.

Example:
Code:
L 06/28/2015 - 10:21:10: [test2.amxx] Your version 1.2 is outdated. Last version is: 1.3
L 06/28/2015 - 10:21:10: [test2.amxx] Changelog for V 1.3:
L 06/28/2015 - 10:21:10: [test2.amxx] + Added version checker 
L 06/28/2015 - 10:21:10: [test2.amxx] + Better filtering for wrong configurations, missing models/sounds 
L 06/28/2015 - 10:21:10: [test2.amxx] + Added changelog display for suggested version 
L 06/28/2015 - 10:21:10: [test2.amxx] + Filtering mp3 files to prevent user input errors 
L 06/28/2015 - 10:21:10: [test2.amxx] + Added a new identifier for replacement - admin flags 
L 06/28/2015 - 10:21:10: [test2.amxx] + Flags are now additive for player & weapon models 
L 06/28/2015 - 10:21:10: [test2.amxx] + Code cleaned 
L 06/28/2015 - 10:21:10: [test2.amxx] + Fixed some tipos
Requirements top

This doesn't require much special things, only:
  • Orpheu module.
  • A server without dproto.
    This is not generally needed, but I won't help you if you are running an outdated server with dproto. If you are experiencing problems, update your server/ fix the erros by yourself.
Installation top[INDENT]
To install the plugin:
  1. Download the resources from this post. You need to get the source and compile it locally.
  2. Put entities_resources_replacement.amxx in addons/amxmodx/plugins
  3. Put entities_resources_dyn_replace.ini in addons/amxmodx/configs
  4. Put entities_resources_comp_replace.ini in addons/amxmodx/configs
  5. Open addons/amxmodx/configs/plugins.ini and add at the end of this file entities_resources_replacement.amxx
  6. You can put the sma file into addons/amxmodx/sources but this is not mandatory.
  7. Copy the content from orpheu folder to addons/amxmodx/configs/orpheu
  8. Restart the server/change map.

To install orpheu:
  1. Download orpheu_files-2.5.1.zip and extrat the arhive.
  2. Copy orpheu_amxx.dll/orpheu_amxx_i386.so depending on your operation system into addons/amxmodx/modules
  3. The module will be auto-loaded, you don't need to add it into modules.ini

To compile locally:
  • First way:
    1. Download AMX Mod X for windows/linux from main site
    2. Extract somewhere the arhive and remember the folder!
    3. Copy the content from include folder from the orpheu arhive into addons/amxmodx/scripting/include( in the folder created in the step 2 ).
    4. Download celltravtrie.inc that is attached to this post and put it inside include. The one from Hawk post seems to be changed and is missing a stock.
    5. Download the source of the plugin( entities_resources_replacement.sma) from this post and drag it over the compile.exe(scripting folder from the arhive created at step 2)
    6. It will create a new folder called compiled. Open it and you will find your compiled plugin( entities_resources_replacement.amxx )
  • Second way:
    1. Go to http://spider.limetech.org/
    2. Copy/paste the code from the .sma file into the website.
    3. Under the big blue Compile button you see a box which Drop .inc files here
    4. Then press Compile and Download

Configuration top


You can use complete replacement file, dynamic replacement or both at the same time! In order to switch from one to other you need to change the cvar ToggleReplacementType.
Change this value to 1 for complete replacement, to 2 for dynamic replacement or to 3 for both replacements. Note that this cvar in cached, so new values are read after map change.

To configure complete replacement file:

Open entities_resources_comp_replace.ini and you will see some instructions on how you should use the plugin.
You need to know that you can change resources in all maps, or they can be map specific. In order to acquire this:
  • Map specific: rename the file, including the map name: entities_resources_comp_replace.ini -> entities_resources_comp_replace-map_name.ini. If you want the resources to be change only in de_dust2 you would do entities_resources_comp_replace-de_dust2.ini. It's very important to write the map name correctly!
  • Global changes: just let the name as entities_resources_comp_replace.ini. There is no problem if you have a global config and some configs that are map specific. If the needed map is running it will load the map config, otherwise it will load the default one.
  • No configuration file: if no configuration file is found, the plugin will be paused in the current map.

To change resources one would do
Code:
new_resource old_resource
You can replace sprites, sound and models. A path should look like
Code:
models/sound/sprites/file_name.mdl/wav/spr
For sounds, you still need to write sound/ in path, it will be automatically removed inside the plugin.

Some examples:
  • To change models:
    Code:
    models/v_ak47.mdl models/v_m4a1.mdl
    models/p_ak47.mdl models/p_m4a1.mdl
    models/w_ak47.mdl models/w_m4a1.mdl
    This will change all the ak47 models to m4a1 models. Silly, but it's a clear example.
  • To change sounds:
    Code:
    sound/weapons/knife_hitwall1.wav sound/weapons/ak7-1.wav
    This will change knife_hitwall1.wav sound to ak47-1.wav sound. You are not allowed to use mp3 files, PLEASE only .wav sounds.
  • To change sprites:
    Code:
    sprites/old.spr sprites/new.spr
    You will do the same as for sounds and models, too lazy to write an example. This feature is very good, as you no longer need plugins as "he explosion sprite changer" and so.

To configure dynamic replacement file:

Open entites_resources_dyn_replace.ini and you'll have full instruction with examples.

You need to know that you can change resources in all maps, or they can be map specific. In order to acquire this:
  • Map specific: rename the file, including the map name: entites_resources_dyn_replace.ini -> entites_resources_dyn_replace-map_name.ini. If you want the resources to be change only in de_dust2 you would do entites_resources_dyn_replace-de_dust2.ini. It's very important to write the map name correctly!
  • Global changes: just let the name as entites_resources_dyn_replace.ini. There is no problem if you have a global config and some configs that are map specific. If the needed map is running it will load the map config, otherwise it will load the default one.
  • No configuration file: if no configuration file is found, the plugin will be paused in the current map.

As from version 1.3, some interesting things were added:
  • For both weapons & player models new type of replacement was added, by admin flags. You must write Flag_letters. If you want to give a model to all admins that have ban acces you must do Flag_d and the rest is the same, write the model as for any other replacement type(team/steam etc)
    • Example:
      Code:
      Flag_d models/v_ak47.mdl models/v_m4a1.mdl models/p_m4a1.mdl models/w_m4a1.mdl
      Flag_abcdefghijklmnopqrstu models/v_m4a1.mdl models/v_ak47.mdl models/p_ak47.mdl models/w_ak47.mdl
    • A new cvar was added: AdminFlagsReadType -> change the way in which admins flags are checked.
      • 0 means contain - the flags from file must be contained in user flags.
      • 1 means equal - flags from file must be the same as the user flags.
      • Example: in the file we have the flags abc and a user with flags abcdefghijklmnopqrstu
      • If the cvar value is 0, he will get the model, because abc is contained in abcdefghijklmnopqrstu
      • If the cvar value is 1, he won't getthe model, because abc is not equal to abcdefghijklmnopqrstu
  • The biggest and most interesting part, flags are now additive, this mean you can combine them with "+".
    • Example:
      Code:
      STEAM+TEAM_CT some_model
      STEAM+TEAM_TERRORIST some_other_model
      Flag_abcd+TEAM_CT+STEAM_ some_model

You are not limited at only two flags, you can combine as many as you want, but without ALL flag. Also, the same thing can be done for weapon models.
  • Change Weapon Models
    • Go to [WEAPON MODELS]
    • Read the instructions from file, I'm not going to repost here
    • Under ;Add your models below: add your new resources
    • Example: ALL models/v_ak47.mdl models/v_m4a1.mdl models/p_m4a1.mdl NULL
    • Use NULL in order to skip a model from the syntax.
    • Syntax:
      • STEAM_...... v_old_model v_new_model p_new_model w_new_model
      • Flag_acces v_old_model v_new_model p_new_model w_new_model
      • TEAM_TERRORIST model v_old_model v_new_model p_new_model w_new_model
      • TEAM_CT model v_old_model v_new_model p_new_model w_new_model
      • ALL model v_old_model v_new_model p_new_model w_new_model
  • Change Player Models
    • Go to [PLAYER MODELS]
    • You have full instructions, please pay attention on them.
    • Under ;Add your models below: add your custom models
    • Example: TEAM_CT antifurien
    • Use NULL in order to skip a model from the syntax.
    • Syntax:
      • STEAM_...... model
      • Flag model
      • TEAM_TERRORIST model
      • TEAM_CT model
      • ALL model
      • OldModel modell
  • Change Sounds
    • Find [SOUND SECTION]
    • Again, read the instructions from the file.
    • Under ;Add your sounds below: add your custom sounds
    • Syntax: old_sound new_sound
  • Change sprites
    • Find [SPRITE SECTION]
    • Again, read the instructions from the file.
    • Under ;Add your sprites below: add your custom sprites
    • Syntax: old_sprite new_sprite

Important:If you see that some of your resources are not replaced check server console & logs file, when some files are skipped, you will find there the full reason.

API top

What mean API ? API stands from Application Programming Interface and it's here for compatibility purpose.

INC file:
PHP Code:
#if defined _err_api_included
    #endinput
#endif
#define _err_api_included

/**
    *  This native is for compatibility purpose.
    *  You search for a default string and it will point you to the new one.
    *  Example: →  models/v_ak47.mdl(old string) models/v_m4a1.mdl(new string)
                → By searching for models/v_ak47.mdl you will get models/v_m4a1.mdl
    *
    *  @param Input            The string that you want to search for.
    *  @param Output           The buffer in which the found string will be saved.  
    *  @return                 -1 on failure, 1 otherwise
*/
native err_find_replaced_string(const Input[], const Output[])

/**
    *  Return replacement type
    *  Check replacement type before using err_find_replaced_string

    *  @return    →  -1 on failure. 
                →  1 for complete replace 
                →  2 for dynamic replace 
                →  3 for both
*/
native err_find_replace_type() 
As you can see it has two natives. The inc file is self explanatory, just read the documentation.

Plugin Example
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <err_api> //include the custom library

public plugin_init() 
{
    if(
err_find_replace_type() != 2)
    {
        new 
szString[128//this will be the buffer in which the output will be stored.
        
err_find_replaced_string("models/v_ak47.mdl"szString//find what replaced models/v_ak47.mdl string
        
server_print("Searched models/v_ak47.mdl | Found:%s"szString//print it to server console.
    
}

err_find_replaced_string native will return -1 on failure, it's up to you to check this before working with the output.
The native is usefull when you want to run other plugins that do stuffs in FM_SetModel and check for default model name. To be sure you check the right model, search with this native for the original one, if it was replaced it will point you to the other one.
Credits top
  • Arkshine: some ideeas
  • BackStabNoob: topic design
ChangeLog top
  • V 0.1:
    • Initial release
  • V 0.2:
    • Added support for sounds.
    • Removed an useless cvar.
    • Minor improvements.
  • V 0.3:
    • Fixed some stuffs.
    • Added more checks to prevent user errors.
  • V 0.4:
    • Added support for sprites.
    • Added more and more checks to prevent user errors.
  • V 0.5:
    • Removed some useless checks, plugin will be paused in that situations
    • Fixed another silly mistake
  • V 0.6:
    • Remove some useless arrays
    • Added a native for campatibility purpose
    • Code optimized, less checks.
  • V 0.7:
    • Added DefaultDeploy() hook
    • Using orpheu to hook DefaultDeploy(), some troubles with okapi
    • Added dynamic replacement way
    • Added support for dynamic changind player models, sounds and weapon models
    • Changed a bit my code style
    • Added more checks to prevent user errors
    • Fixed the encoding bug with complete replacement file
  • V 1.0:
    • Fixed some bugs.
    • Now you can use both replacement types at the same time.
  • V 1.1:
    • Fixed bugs with model setup
    • Added new option: replace a model with another one
    • Code optimized
  • V 1.2:
    • Fixed identation
    • Code cleaned a bit.
    • Removed something left here by mistake after testing.
  • V 1.3:
    • Added version checker
    • Better filtering for wrong configurations, missing models/sounds | Added changelog display for suggested version
    • Filtering mp3 files to prevent user input errors
    • Added a new identifier for replacement - admin flags
    • Flags are now additive for player & weapon models
    • Code cleaned
    • Fixed some tipos
  • V 1.4:
    • Fixed DefaultDeploy() signature, it should be more reliable now.
    • Fixed a crash with unpatching memory in certain situations.
    • Fixed a crash that happened when plugin was paused.
    • Fixed a typo in dynamic replacement file name.
    • Fixed a bug that occured while trying to get the changelog. Plugin was priting error messages when it was not the case.
    • Code was completely rewritten, now it's easier to maintain and understand. Also it makes more sense now.
    • Added sprite replacement in dynamic replacement mode.
    • Proper checks are enforced on resources.
    • Configuration files were rewritten, instructions are much more clear, for the sake of usability.
    • Probably much more things that I can't remember.
Downloads top
  • V 0.1: 23 downloads
  • V 0.2+0.3: 20 downloads
  • V 0.6: 45 downloads
  • V 1.0: 128 downloads
  • V 1.2: 64 downloads
  • V 1.3: 242 downloads
Attached Files
File Type: sma Get Plugin or Get Source (entities_resources_replacement.sma - 3155 views - 33.0 KB)
File Type: zip Entities Resources Replacement.zip (22.3 KB, 2330 views)
__________________

Last edited by HamletEagle; 07-31-2016 at 08:20.
HamletEagle is offline
Old 10-20-2014, 15:36
HamletEagle
This message has been deleted by HamletEagle.
Jhob94
AMX Mod X Moderator
Join Date: Jul 2012
Old 10-20-2014 , 16:39   Re: Weapons Model Replacement[ OKAPI ]
Reply With Quote #2

Seems nice but i think you should explain why we should use this instead of Chronic's one.
__________________
My Plugins List | My Tutorials List
Everything that i know was self-learned with the help of this community
If you want to thank me for my plugins
donate to alliedmodders
Jhob94 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-20-2014 , 16:46   Re: Weapons Model Replacement[ OKAPI ]
Reply With Quote #3

Quote:
Originally Posted by Jhob94 View Post
Seems nice but i think you should explain why we should use this instead of Chronic's one.
His old one is very inneficient speacking about coding methods:
1. He is using currentweapon for changing weapons models.
2. He is using format and not formatex.
3. So on...
4. Mine use okapi which patch the string directly into memory, just one time.
__________________

Last edited by HamletEagle; 10-20-2014 at 16:46.
HamletEagle is offline
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 10-20-2014 , 17:37   Re: Weapons Model Replacement[ OKAPI ]
Reply With Quote #4

Have you try to change string longer than original?
Example: models/v_ak47.mdl --> models/v_ak47_the_one_and_only.mdl

Because in Orpheu we can't patching string > original string.

** Edited **
Nevermind
Quote:
By default, you can put a path with the same size as the original one or lower. Safe mode allows you to disable this restriction. If you don't want to be limited, set it to 1, but I would recommend to keep it with 0 and modify the new model name to be shorter than the original one.
__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019

Last edited by yokomo; 10-20-2014 at 17:39.
yokomo is offline
Jhob94
AMX Mod X Moderator
Join Date: Jul 2012
Old 10-20-2014 , 18:42   Re: Weapons Model Replacement[ OKAPI ]
Reply With Quote #5

I don't like to test plugins in my oficial servers and i am lazy to read the code so is better to ask. If i run an external plugin for give some people private weapon skins wich are set at item deploy, would that external plugin work?
And since i am talking about this, i think it would be a nice idea to allow setting skins by user flags and also steam id (Steam ID would override flags). Would be more original and make a easy job for many people

Could be:
.Normal Replace - "models/v_knife.mdl" "models/hamlet_server/v_knife.mdl"
.Flags Replace (Example, ADMIN_BAN) - "models/v_knife.mdl" "models/admins/v_knife.mdl" "d"
.Steam ID Replace - "models/v_knife.mdl" "models/jhob/v_knife.mdl" "STEAM_0:19788919"
__________________
My Plugins List | My Tutorials List
Everything that i know was self-learned with the help of this community
If you want to thank me for my plugins
donate to alliedmodders
Jhob94 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-21-2014 , 05:29   Re: Weapons Model Replacement[ OKAPI ]
Reply With Quote #6

I don't see the point of wmr_safemode_off cvar ; as it should fuck up memory if you use a new string size > original size one (like you example..)

Quote:
Not needed, but let's make sure.
Pointless, please don't make unnecessary steps. Auto-loading is working fine, don't start to make people mixing both.
__________________

Last edited by Arkshine; 10-21-2014 at 05:33.
Arkshine is offline
Jhob94
AMX Mod X Moderator
Join Date: Jul 2012
Old 10-21-2014 , 06:39   Re: Weapons Model Replacement[ OKAPI ]
Reply With Quote #7

I believe you can use other stuff to save strings into memory, even if not only one time, there is stuff that require such few cpu consume that people won't really care. But using an external module just for this thing seems useless and many people might dont want to use it. Example, i know one owner of a big community that has the server really high ranked. He owns it for like 5 years and few weeks ago i was helping him fixing chat crashes and when i sent the sma he didnt knew what it was because there are many people who just comes and download amxx.
Since you using that module just for a few memory settings, i think its a bit useless. But at the end its your choice.
__________________
My Plugins List | My Tutorials List
Everything that i know was self-learned with the help of this community
If you want to thank me for my plugins
donate to alliedmodders
Jhob94 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-21-2014 , 10:01   Re: Weapons Model Replacement[ OKAPI ]
Reply With Quote #8

Quote:
Originally Posted by Jhob94 View Post
I don't like to test plugins in my oficial servers and i am lazy to read the code so is better to ask. If i run an external plugin for give some people private weapon skins wich are set at item deploy, would that external plugin work?
And since i am talking about this, i think it would be a nice idea to allow setting skins by user flags and also steam id (Steam ID would override flags). Would be more original and make a easy job for many people

Could be:
.Normal Replace - "models/v_knife.mdl" "models/hamlet_server/v_knife.mdl"
.Flags Replace (Example, ADMIN_BAN) - "models/v_knife.mdl" "models/admins/v_knife.mdl" "d"
.Steam ID Replace - "models/v_knife.mdl" "models/jhob/v_knife.mdl" "STEAM_0:19788919"
Your suggestion is impossible to be done with okapi, it's patch the string directly into memory one time, in plugin_precache and at this point there are no players connected + the original string is replaced by new one, the model is not simply "changed" as happen when using pev_viewmodel12 and so.

Quote:
Originally Posted by Arkshine View Post
I don't see the point of wmr_safemode_off cvar ; as it should fuck up memory if you use a new string size > original size one (like you example..)


Pointless, please don't make unnecessary steps. Auto-loading is working fine, don't start to make people mixing both.
As you say...

Quote:
Originally Posted by Jhob94 View Post
I believe you can use other stuff to save strings into memory, even if not only one time, there is stuff that require such few cpu consume that people won't really care. But using an external module just for this thing seems useless and many people might dont want to use it. Example, i know one owner of a big community that has the server really high ranked. He owns it for like 5 years and few weeks ago i was helping him fixing chat crashes and when i sent the sma he didnt knew what it was because there are many people who just comes and download amxx.
Since you using that module just for a few memory settings, i think its a bit useless. But at the end its your choice.
"I believe you can use other stuff to save strings into memory,"
No, only possible with okapi/orpheu which acts in the same way. The point of this plugin is to use the best way, it's not my problem if some owners can't read the instructions or if they are not able to use it.
__________________
HamletEagle is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-21-2014 , 10:19   Re: Weapons Model Replacement[ OKAPI ]
Reply With Quote #9

Quote:
As you say...
I don't understand why you answer that.
__________________
Arkshine is offline
Old 10-21-2014, 10:23
HamletEagle
This message has been deleted by HamletEagle.
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-21-2014 , 11:30   Re: Weapons Model Replacement[ OKAPI ]
Reply With Quote #10

Because I don't like to write much text when it's not needed. For auto-loading, in the past I experienced some problems, this is why I'm writing this in the install instructions but if you say that now it's working fine it's ok.
About safe mode cvar, I know it's a bit useless and unexperienced owners may screw up memory, I don't know what was in my mind when I've added this.

UPDATE:

V 0.2:
+ Added support for sounds
+ Removed the cvar.
__________________
HamletEagle is offline
Reply


Thread Tools
Display Modes

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 12:24.


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