AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   New Plugin Submissions (https://forums.alliedmods.net/forumdisplay.php?f=26)
-   -   HomeFree v0.7 (https://forums.alliedmods.net/showthread.php?t=87132)

Nur56 03-07-2009 10:03

HomeFree v0.7
 
11 Attachment(s)
HomeFree



Description

HomeFree is a plugin played on popular HnS maps where the CT's are supposed to eliminate the T's with a knife.
The T's get 1 HE grenade and the ability to fall slowly. After using SlowFall their health will be set to a number according
to their Death count and HP and it will get disabled for a period of time as well as get an extra Death in their count.

The CT's have a special knife which grants them SPRINT which lets them run at high speeds in order
to catch up. While sprinting, the CT's health will be set to 1HP. After that, they will be frozen in place and their health set to 15HP for a period of time. When they're unfrozen their health will be set to a number according to their Death count and HP. They will also get 1 additional Death. As a reward, when any player gets a kill he will get a bonus of 10HP.



cVars

home_enabled
<1/0> Enables or disables the plugin.
home_fspeed
<n> Fall speed for SlowFall, defaults 150.
home_mspeed
<n> Sprint Speed, this changes sv_maxspeed as well, defaults 340.
home_freeze
<n> How long CT freezes for after sprint, defaults 5.
home_stimer
<n> How long until T can use SlowFall after using, defaults 10.

Includes
Code:

amxmodx
amxmisc
cstrike
engine
fun
fakemeta
hamsandwich

Changes


Code:

v0.5: -Complete recode.


v0.6: -Removed PreThink for most things except parachute added +homefree
      -Used Ham_Spawn

v0.7: -Optimized code
      -Changed how CT's freeze
      -Changed how T's SlowFall
      -Added timer


Known Bugs
Code:

None!

Credits

Code:

Maker of ColorChat Module.
The maker of PARACHUTE for his velocity algorithm[re-wrote some of it but same idea].
Arkshine for directing me to optimize my code


Arkshine 03-07-2009 10:21

Re: HomeFree
 
Code:
forward_return( FMV_STRING, "Awesome")


By the way :

- Use Pcvars
- Use get_players()
- You should remove GameDesc because for such small and common plugin...
- Use some white space it doesn't hurt.

anakin_cstrike 03-07-2009 10:23

Re: HomeFree
 
You could you ony FM.

Bugsy 03-07-2009 10:45

Re: HomeFree
 
How about an explanation of what the plugin actually does. Or is it just me? :-B

DruGzOG 03-07-2009 10:46

Re: HomeFree
 
Just a question, what is "Home Free" ?

BOYSplayCS 03-07-2009 10:46

Re: HomeFree
 
Quote:

Originally Posted by Bugsy (Post 775757)
How about an explanation of what the plugin actually does. Or is it just me? :-B

I'm with you :D

anakin_cstrike 03-07-2009 11:00

Re: HomeFree
 
Quote:

Originally Posted by Bugsy (Post 775757)
How about an explanation of what the plugin actually does. Or is it just me? :-B

Or me :|

Bugsy 03-07-2009 11:02

Re: HomeFree
 
You should neaten up your original post if you plan on approval. Look through the approved plugins section and follow a similar format. The more info you provide about the functionality of your plugin the better.

White space is just empty spaces. Use it to space out your code a bit to make it more readable. It will not affect your code size at compile as the compiler ignores it.

ie.
PHP Code:

if(a==3)
       
set_task(0.1,"function",id)

//would be

if ( == )
        
set_task 0.1 "function" ,  id 


letgoofmyeggs 03-07-2009 14:13

Re: HomeFree
 
yu dont need the parachute model?

Nextra 03-07-2009 17:49

Re: HomeFree
 
Nice idea but there are still some things that you should rework a bit.

Firstly I would suggest to include the colorchat stuff directly into your plugins base code rather than including it. This way people are able to use the online compiler, generally a nice thing to have. You should also credit the authors of the colorchat function I suppose.

You also have to convert all cvars to pcvars. You could use get_cvar_pointer to apply this for the sv_maxspeed cvar, too.

Another thing I see is that you hook the DeathMsg event but do not provide the appropriate function. I believe it will therefore throw an error in plugin_init and maybe even stops it from registering the GameDesc forward.

Lastly, as previously mentioned, it would be neat if you could do the entire thing with fakemeta only to get rid of the fun and engine require.


Hope this helped :up:

Nextra 03-08-2009 15:24

Re: HomeFree
 
Nice but you need to do

PHP Code:

svSpeed get_cvar_pointer("sv_maxspeed"

instead of

PHP Code:

svSpeed get_cvar_num("sv_maxspeed"

and then use

PHP Code:

[s|g]et_pcvar_numsvSpeed 

throughout the plugin.


You errorneously begin the loop at RoundStart with id zero but the players ids start with one. Also it is better if you store get_maxplayers() earlier or even globally.

Also, you redundantly set the players' money to zero twice. You only need to do that once.

Another little thing is that is_user_alive( id ) already includes the check for is_user_connected( id ) which you therefore don't need anymore (as you are checking this in one single if clause).

Nextra 03-09-2009 14:39

Re: HomeFree
 
Your previous hook of the round start was entirely correct. You have to do the player spawn hook seperately to catch late connecting players. Then you obviously have to leave out the loop so the other players do not receive the message again.

A nice tutorial on how to hook round start and player spawn correctly can be found here: http://forums.alliedmods.net/showthread.php?t=42159

There is still a second money reset when the players' team is 2, this is not necessary.:up:

Exolent[jNr] 03-29-2009 16:07

Re: HomeFree
 
There are several errors within this plugin.
If you wish to know how to fix them, reply back.

Unapproved.

ConnorMcLeod 08-22-2009 04:32

Re: HomeFree
 
Your use of client_PreThink is not justified, use proper events/forwards instead.

Nur56 09-29-2011 09:47

Re: HomeFree
 
Sweet 2 year bump, COMPLETE re-code, edited first post, uploaded new sma(15kb up from 5kb). Contacted an approver to move this to new submissions.

a bit late, I know :)

Arkshine 09-29-2011 11:05

Re: HomeFree
 
re-submit it on author's request.

ConnorMcLeod 09-30-2011 01:57

Re: HomeFree
 
* cache msg indexes into global variables
* cache maxplayers value into global variables
* don't change/supercede GameDescription if cvar is disabled
* use cvars pointers even for extra cvars (use get_cvar_pointer in plugin_init)
* don't use fm_ converted natives, use propers natives that are more efficient
* don't hook ResetHUD event for spawn, hook Ham_Spawn instead
* PreThink usage is not worth for lot of features such as Money set, maxspeed change, also, would be better to use engine prethink global forward for code extracted from parachute plugin

Consider this if you want your plugin to be reviewed.

Nur56 09-30-2011 05:43

Re: HomeFree
 
Quote:

Originally Posted by ConnorMcLeod (Post 1565710)
* cache msg indexes into global variables
* cache maxplayers value into global variables
* don't change/supercede GameDescription if cvar is disabled
* use cvars pointers even for extra cvars (use get_cvar_pointer in plugin_init)
* don't use fm_ converted natives, use propers natives that are more efficient
* don't hook ResetHUD event for spawn, hook Ham_Spawn instead
* PreThink usage is not worth for lot of features such as Money set, maxspeed change, also, would be better to use engine prethink global forward for code extracted from parachute plugin

Consider this if you want your plugin to be reviewed.

* Done :mrgreen:
* I don't use get_maxplayers() (ColorChat does, though)
* It doesn't change it if it's disabled, it has the gEnabled pcvar check
* I don't use any cvars other than the ones registered in plugin_init, as POINTERS
* No real alternative unless I use fun module. Changed a few to set_pev(id, pev_health) but changing ALL of them to float didn't work so I removed some. can't find any other alternative to strip weapons or give item, either.
* Done :mrgreen:
* Engine would use more resources, SlowFall works fine as it is and there is no forward to hook pressing buttons. or money :(

If you could tell me some alternatives to the fun natives, or the forwards, I'd be more than happy to use them!

(updated new src)

Arkshine 09-30-2011 06:58

Re: HomeFree
 
- The messages are still not cached.
- About get_maxplayers(), It doesn't change the fact it has to be cached.
- About GameDesc(), you still supercede all the time...
- To retrieve pointer from external cvars, use get_cvar_pointer, something you should cache also.
- fm_* functions are for most of them conversions of fun functions. So include fun, and remove fm_ and you have your functions. fm_ functions are less efficient then the ones from the fun modules. Remember : the less natives you call the more efficient your plugin will be.
- About get_players. You do something wrong. mPlayers will contain a list of player's index, and since it's stored in an array, index starts to 0. So your loop should look : for(i = 0; i < mCount; i++ ), then you can remove your "fix". Also, cache the player's index, i.e: id = mPlayers[i]
- Setting all the time the money to 0 is really a poor way. If you want to disable the ability to buy, use info_map_parameters entity.

Probably others things to say, start to fix what it has been said.

Nur56 09-30-2011 08:33

Re: HomeFree
 
Quote:

Originally Posted by Arkshine (Post 1565771)
- The messages are still not cached.
- About get_maxplayers(), It doesn't change the fact it has to be cached.
- About GameDesc(), you still supercede all the time...
- To retrieve pointer from external cvars, use get_cvar_pointer, something you should cache also.
- fm_* functions are for most of them conversions of fun functions. So include fun, and remove fm_ and you have your functions. fm_ functions are less efficient then the ones from the fun modules. Remember : the less natives you call the more efficient your plugin will be.
- About get_players. You do something wrong. mPlayers will contain a list of player's index, and since it's stored in an array, index starts to 0. So your loop should look : for(i = 0; i < mCount; i++ ), then you can remove your "fix". Also, cache the player's index, i.e: id = mPlayers[i]
- Setting all the time the money to 0 is really a poor way. If you want to disable the ability to buy, use info_map_parameters entity.

Probably others things to say, start to fix what it has been said.

-
PHP Code:

new gHF[] = "^x04[HomeFree]" //msg index

ColorChatid[0],BLUE,"^%s^x01 Type ^x03/help ^x01if you need help!",gHF 

But if that isn't caching then tell me because I don't know what it is :|
-Cached maxplayers in the function ColorChat uses
-FMRES_IGNORED now
-Done for sv_maxspeed & mp_freezetime( gSvMSpeed and gFrzTime )
-Removed all fm_ funcs, added fun module funcs instead
-Did that and it gave me a player out of range error, obviously because cs_get_user_team won't work with ID 0, id = mPlayers[i] is there now
-Thought about that when I removed PreThink, now I simply blocked buy function.


Added 2 commands, +sprint/-sprint and +slowfall/-slowfall
SlowFall is a bit more realistic now, you fall faster.
figured it's the only way to get rid of using PreThink(looking at you, connor)

updated src:mrgreen:

Arkshine 09-30-2011 12:08

Re: HomeFree
 
- I was talking about the events : SayText, TeamInfo. Such message index are static and won't change in-game, therefore that's something you could cache one time.
- You still keep mPlayers[i] == 0 check. It doesn't make sense and can't happen.
- The blocking of "buy" is wrong. You can buy with others ways. So... again, see info_map_paramters entity. Easy and efficient way.
- Why you don't hook SendAudio or TextMsg to know what team has won ?
- AFAIK changing the return of a FM forward, you need to supercede. I did not say you to remove this return, but to move it in the check, which should be logic.

I have others things to say, but for now, fix again your plugin.
I'm starting to wonder if you can really support this plugin.

Nur56 09-30-2011 13:33

Re: HomeFree
 
Quote:

Originally Posted by Arkshine (Post 1565904)
- I was talking about the events : SayText, TeamInfo. Such message index are static and won't change in-game, therefore that's something you could cache one time.
- You still keep mPlayers[i] == 0 check. It doesn't make sense and can't happen.
- The blocking of "buy" is wrong. You can buy with others ways. So... again, see info_map_paramters entity. Easy and efficient way.
- Why you don't hook SendAudio or TextMsg to know what team has won ?
- AFAIK changing the return of a FM forward, you need to supercede. I did not say you to remove this return, but to move it in the check, which should be logic.

I have others things to say, but for now, fix again your plugin.
I'm starting to wonder if you can really support this plugin.

-Done( I think? )
-Removed and doing i = 0 actually worked this time :mrgreen:
-Done that, had to include engine but oh well
-Hooked using TextMsg
-Didn't understand you in the beginning, fixed now with an IGNORE outside the check

I've worked hard for this plugin, I would hate for it to go to waste :(

(updated src, removed +/-sprint and +/-slowfall and replaced them with +/-homefree)

Arkshine 09-30-2011 14:05

Re: HomeFree
 
- You don't understand the caching thing.
That : get_user_msgid("SayText"), it returns an unique number which won't change in-game. Since static, and since it will be called more than one time, it would be appropriate to cache its value into a global variable one time, in plugin_init for example.
- Same for get_maxplayers(). You save the value before, it's better, but it will still be called each time the function will be run, and the returns value won't change in-game.
- Why are you using register_message for TxtMsg ? There is not reason to hook the message as pre, you don't want to modify its params, right ? You can simply use 2 register_event. It will be more efficient.
- What are you trying to delete the entity in the player's spawn ? How you can expect you find such entity when Ham_Spawn is registered with "player" ? Really doesn't make sense what you do. Search you will find snippet for that.

It does not really matter you have worked hard. Look, each time there are many things to say, it proves simply you need to learn more. Nothing wrong with that, you should just aware of your own limit. That's not the scripting section. You are supposed to know what you're doing. That's why I've said I was wondering if you can support really your plugin. You have some potential for sure, but you will understand it starts to be boring to correct you each time because our job is not to teach you how to code.

Anyway for now, it seems you can follow, fix your plugin, and really please, test your plugin before releasing.

Nur56 09-30-2011 16:31

Re: HomeFree
 
Quote:

Originally Posted by Arkshine (Post 1565962)
- You don't understand the caching thing.
That : get_user_msgid("SayText"), it returns an unique number which won't change in-game. Since static, and since it will be called more than one time, it would be appropriate to cache its value into a global variable one time, in plugin_init for example.
- Same for get_maxplayers(). You save the value before, it's better, but it will still be called each time the function will be run, and the returns value won't change in-game.
- Why are you using register_message for TxtMsg ? There is not reason to hook the message as pre, you don't want to modify its params, right ? You can simply use 2 register_event. It will be more efficient.
- What are you trying to delete the entity in the player's spawn ? How you can expect you find such entity when Ham_Spawn is registered with "player" ? Really doesn't make sense what you do. Search you will find snippet for that.

It does not really matter you have worked hard. Look, each time there are many things to say, it proves simply you need to learn more. Nothing wrong with that, you should just aware of your own limit. That's not the scripting section. You are supposed to know what you're doing. That's why I've said I was wondering if you can support really your plugin. You have some potential for sure, but you will understand it starts to be boring to correct you each time because our job is not to teach you how to code.

Anyway for now, it seems you can follow, fix your plugin, and really please, test your plugin before releasing.


-Cached vars in plugin_init(), including getmaxplayers
-registered 2 events, 1 for CT win and 1 for T win, using TextMsg
-It worked fine for me but I agree, it wasn't really effective. changed to use only fakemeta.


I really hope I did it right this time, I do know what I'm doing I just didn't find this amount of optimization really necessary(until now).

and I really do test my plugin before I release it :P

Arkshine 09-30-2011 17:49

Re: HomeFree
 
Quote:

changed to use only fakemeta.
That's not an optimization... Look, because of that now, instead of DispatchKeyValue (one native), you call SetKeyValue (5 natives!). Guess what is the most efficient ? Of course here, it would be called one time, but it won't always the case. You should use intelligently the existing natives/forwards whatever the modules. Remember calling a native cost cpu, that's why there is no reason to use the fakemeta version here.

- You create the entity info_map_parameters, but you forget the situation where the map has already such entity. Since you create in precache time, the entity of the map is not created yet, that's why you need to hook FM_Spawn after creating your entity to block its spawn (the entity integrated to the map). Again, there is snippet about that.
- You call 2 times cs_get_user_team( id ). You should cache the value and you should understand checking 2 times the team is quite pointless. Use simply a switch.
- Oh inside the switch, instead of writting 1 and 2, some defines exist for that, CS_TEAM_CT and CS_TEAM_T, just use them.
- When you do checks, you should make testing first the variables. Like gNewR should be check before get_pcvar_num. You filter better to avoid to check natives.
- You should avoid to make multiple if() when you could do if( condition1 && condition2 && etc.. ). The compiler is idiot and won't optimize. By doing that you will generate less code.
- Your motd is static, therefore it would be appropriate to generate it one time.
- In the player's spawn, is a task really need ? 0.2 is fairly unnoticeable and I'm not how it would be useful.
- I see you use a var to pass the player's id, but as tip, you can pass directly the player's id as the task id. And it will avoid each you use id[0] (where here that's something you should cache from the start hehe)

- A word about readability : please avoid to glue all together. It won't hurt to make some white-spaces. People who will read your code will be happy. For example logevent_round_start, you can make make a new line after the var, cvar, colorchat.
- Just for your information. I see most of time your explicit the return of a function (PLUGIN_CONTINUE, etc..). When no specific value has to be returned, the value by default is anyway the PLUGIN_CONTINUE, or FMRES_IGNORED, etc.., therefore you don't need to explicit the return. It's fine if you do too and it won't matter if you want to keep it, but personally I see no point to explicit, it eats one line for nothing.

ConnorMcLeod 10-01-2011 02:09

Re: HomeFree
 
Please change that horrible FindPlayer stock with :
Code:

FindPlayer()
{
        static iPlayers[32], iNum
        get_players(iPlayers, iNum, "h")
        return iNum ? iPlayers[0] : -1
}


Nur56 10-01-2011 07:12

Re: HomeFree
 
Updated source did everything you said except for the player spawn tasks, if I do it directly in the event it will give me some errors( tried 100 times, same thing ), so a task worked perfectly. motd now in plugin_init, no more multiple if conditionals, switch( cs_get_user_team( id ) ) for team, and removed buyzone with engine and FM_Spawn.

also removed ColorChat's find player and added Connor's stock.

Arkshine 10-01-2011 07:13

Re: HomeFree
 
what errors?

Nur56 10-01-2011 07:30

Re: HomeFree
 
Some index related errors, but since you insisted I installed a fresh copy of AMXX and it worked, so I'm guessing it was one of the plugins I had. still, with the task there were no such errors but if it's necessary I could remove the spawn tasks

Arkshine 10-01-2011 07:34

Re: HomeFree
 
There is no reason to use tasks here. I would remove them.

In tTaskT, there is 2 cs_set_user_money.

ConnorMcLeod 10-01-2011 07:41

Re: HomeFree
 
PHP Code:

    if( gNewR ) {
        if( ( 
get_pcvar_numgEnabled ) ) && ( is_user_aliveid ) ) && ( cs_get_user_teamid ) == CS_TEAM_T ) && ( gSF[id] == ) ) { 

You can merge those 2 checks.


Code:
            new Float:fallspeed = get_pcvar_float( gfSpeed ) * ( -1.0 )             new Float:velocity[3]                                     pev( id, pev_velocity, velocity )                         if( velocity[2] < 0 ) {                 velocity[2] = ( velocity[2] + 40.0 < fallspeed ) ? velocity[2] + 40.0 : fallspeed                 set_pev( id, pev_velocity, velocity )             }

you should put the highlighted line into if( velocity[2] < 0 ) { block.

Nur56 10-01-2011 07:46

Re: HomeFree
 
Fixed, hopefully nobody complains about index errors :D

Nur56 05-18-2012 10:37

Re: HomeFree v0.7
 
bump


All times are GMT -4. The time now is 05:58.

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