AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   even the odds mod can't compile. find my bugs please (https://forums.alliedmods.net/showthread.php?t=94941)

timian 06-17-2009 13:58

even the odds mod can't compile. find my bugs please
 
try to rewirte my code, with a little help from sylwesters code.


try compile it but get some erros, please tell me the bugs.

cs don't "load" my plugins i tryed to compile sylvesters version, but cs still won't load it, why not?

PHP Code:

//Even the Odds
//V 0.2 rewrite

#include <amxmodx>
#include <fun>
#include <hamsandwich>

#define MAX_PLAYERS 32
#define MAX_LEVEL = 30

new gPlayerLevel[MAX_PLAYERS 1//player level and ID
new gCalcHealth gPlayerLevel[id]

public 
plugin_init() {
    
register_plugin("Even The Odds""0.2""Beancake12")
    
RegisterHam(Ham_Spawn"player""player_spawn"1)
    
register_event("HLTV""event_new_round""a""1=0""2=0")
}

public 
player_spawn(id) {
    if(
is_user_alive(id))
        
set_level(id)
        new 
gCalcHealth 310
        set_user_health
(idgCalcHealth-(10*gPlayerLevel[id]))
}

public 
set_level(id) {
    if(!
is_user_connected(id))
        return
    
gPlayerLevel[id] = (get_user_frags(id) - get_user_deaths(id))
    if(
gPlayerLevel[id] < 1)
        
gPlayerLevel[id] = 1
    
if(gPlayerLevel[id] > MAX_LEVEL)
        
gPlayerLevel[id] = MAX_LEVEL



Arkshine 06-17-2009 14:02

Re: even the odds mod can't compile. find my bugs please
 
You need to define 'get_max_players', use a var and save into 'get_maxplayers()', and gModIsOn = 1 shoud be ==.

Since you're new, this thread can be useful for you : http://forums.alliedmods.net/showthread.php?t=94381 and http://forums.alliedmods.net/showthread.php?t=91207

timian 06-17-2009 14:10

Re: even the odds mod can't compile. find my bugs please
 
thanks! i try it now, compile is done!

//after trying

fail!!! my cs don't do my plugin!?

think it don't load my plugin?

why not!?

P i x e L 06-17-2009 14:38

Re: even the odds mod can't compile. find my bugs please
 
post your new one?

timian 06-17-2009 14:44

Re: even the odds mod can't compile. find my bugs please
 
okay, look at top for my new code.

P i x e L 06-17-2009 19:18

Re: even the odds mod can't compile. find my bugs please
 
You don't have:
register_event("HLTV", "event_new_round","a", "1=0", "2=0")
in plugin_init
I think you'll need that :)

Sylwester 06-17-2009 21:34

Re: even the odds mod can't compile. find my bugs please
 
Even if he add this line, nothing will change since players are not spawned yet when new round is called.

I would do it like this:
PHP Code:

#include <amxmodx>
#include <fun>
#include <hamsandwich>

#define MAX_LVLS 10
#define DIFF 5  // level = 4 + (kills-deaths)/DIFF
#define MAX_PLAYERS 32

new bool:g_freezetime
new g_max_hp[MAX_LVLS] =  {2502001501251008060403020}
new 
Float:g_speed_bonus[MAX_LVLS] = { 50.035.020.010.00.0, -10.0, -20.0, -30.0, -40.0, -50.0}
new 
Float:g_weap_speed[32] = {0.0250.00.0260.0250.0240.0250.0250.0240.0,
250.0250.0250.0250.0210.0240.0240.0250.0250.0210.0250.0220.0230.0,
230.0250.0210.0250.0250.0235.0221.0250.0245.00.0}
new 
g_p_lvl[MAX_PLAYERS 1]


public 
plugin_init() {
    
register_plugin("Even The Odds""1.0""Sylwester")
    
RegisterHam(Ham_Spawn"player""player_spawn"1)
    
register_event("CurWeapon""reset_player_speed""be""1=1")
    
register_event("HLTV""event_new_round""a""1=0""2=0")
    
register_logevent("logevent_round_start"2"1=Round_Start")
}


public 
reset_player_speed(id){
    if(
g_freezetime)
        return
    
set_user_maxspeed(idg_weap_speed[get_user_weapon(id)] + g_speed_bonus[g_p_lvl[id]])
}


public 
player_spawn(id){
    if(
is_user_alive(id)){
        
set_lvl(id)
        
set_user_health(idg_max_hp[g_p_lvl[id]])
    }
}


public 
set_lvl(id){
    if(!
is_user_connected(id))
        return
    
g_p_lvl[id] = (get_user_frags(id) - get_user_deaths(id))/DIFF 4
    
if(g_p_lvl[id] < 0)
        
g_p_lvl[id] = 0
    
if(g_p_lvl[id] > MAX_LVLS-1)
        
g_p_lvl[id] = MAX_LVLS-1
}


public 
event_new_round(){
    
g_freezetime true
}


public 
logevent_round_start(){
    
g_freezetime false


Store max hps and speed bonuses in some arrays. Update odds and set health on player spawn and set max speed on curweapon.

timian 06-18-2009 05:11

Re: even the odds mod can't compile. find my bugs please
 
Sylwester - i think you're right... but the big problem is: if you just make the total answer, and don't tell very much i don't learn anything... so thanks for your answer, and it is really much more simple than mine. but i don't get any exp by this.

can you explain it?

note: i want to change movement speed, not weapon speed.

Sylwester 06-18-2009 07:03

Re: even the odds mod can't compile. find my bugs please
 
Trying to write some random stuff won't work for you. You lack amxx basics, your "rewrite" does not even compile. Read tutorials and start with some more simple plugins. I recommend:
http://wiki.amxmodx.org/Introduction_to_Pawn
http://wiki.amxmodx.org/Pawn_Tutorial
Debugging Plugins
http://wiki.amxmodx.org/Intro_to_AMX_Mod_X_Scripting

Once you are done with tutorials read this (info about my code):
Instead of using switch with many cases, it's better to store bonus values in arrays and create formula, so you can use it to retrieve proper bonus value for player in 1 line:
Code:

bonus = some_array[formula_return_value]
So, if you want bonus for player change every 5 (user_frags - user_deaths) then you start make formula like this:
Code:

formula_return_value = (get_user_frags(player_id) - get_user_deaths(player_id))/5
Since you want to retrieve bonus from array also for players who have more deaths than frags (formula returns negative value) and arrays are indexed starting from 0 then you need to enlarge returned value by adding some number. In the end it looks like this:
Code:

formula_return_value = 4 + (get_user_frags(player_id) - get_user_deaths(player_id))/5
After this you must add code that checks if the value returned is a proper index in array (otherwise you will get index out of bounds runtime error).

Now when you can properly get bonus value from array for any player, you can start thinking about setting player speed and health.

You can set player health only when he is alive, so the best moment to do it is just after player has spawned. To detect that moment you need to hook player spawn (in other words tell plugin what is the name of the function that should be called when player was spawned).

Trying to set player health on New Round is totally wrong because players are not spawned yet. Round Start is not the best because some players may spawn after Round Start has been called. You can find a lot info about these events and how to hook them here:
http://forums.alliedmods.net/showthread.php?t=42159

About player max speed: It is reseted to weapon speed very often (example: when player switch weapon), so changing it only 1 time after player spawn will not work. To make sure that player speed will not change to default value, you must detect every max speed reset and change it back to value you want. To detect speed reset you need to hook CurWeapon event:
Code:

register_event("CurWeapon", "reset_player_speed", "be", "1=1")
When using CurWeapon, your function can be also called during freezetime, but we don't want players to be able to move when they are not supposed to, so you need to check if you can set player speed or not. To do that you need to hook New Round and Round Start and store boolean value (is now freezetime ? ) in some global variable.

Quote:

Originally Posted by timian (Post 851441)
note: i want to change movement speed, not weapon speed.

My code changes movement speed. I used weapon speed as a base, so players with same (frags - deaths)/5 will move with different speeds if they have different weapons. Otherwise player with awp could move with same speed as player with knife (if they have same (frags-deaths)/5 ).

timian 06-18-2009 07:34

Re: even the odds mod can't compile. find my bugs please
 
thanks i would look at all your links!

i looked at your code, and under stand it a way better now. i tried to make the mod more simpel (look at the 2nd code at top).

i have fixed some erroes. but there is still 2, cant find them. thanks sylwester.


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

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