AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] (https://forums.alliedmods.net/showthread.php?t=94000)

zacky 06-05-2009 10:03

[SOLVED]
 
[SOLVED] Thanks to xPaw :P

[X]-RayCat 06-05-2009 10:34

Re: help with setting users health
 
Quote:

Originally Posted by zacky (Post 842212)
Hi, i've been making my own point plugin.
But i have 1 problem, you can buy extra hp as ct/t, but, when it is new round you dont get the health you bought :/.

Heres some code for you to see whats wrong :/
PHP Code:

public cmdNewRound() {
    for (new 
1<= gMaxPlayersi++) {
        if (
is_user_alive(i)) {
            new 
iHealth get_user_health(i);
            
            switch (
cs_get_user_team(i)) {
                case 
CS_TEAM_CTset_user_health(iiHealth gPlayerCtHealth[i]);
                case 
CS_TEAM_Tset_user_health(iiHealth gPlayerTHealth[i]);
            }
        }
    }



First don't declare new varibles inside loop. And post some more code.:wink:

zacky 06-05-2009 10:34

Re: help with setting users health
 
Theres no need to post more code, all other codes works fine, and its pretty much code

[X]-RayCat 06-05-2009 10:43

Re: help with setting users health
 
Quote:

Originally Posted by zacky (Post 842236)
Theres no need to post more code, all other codes works fine, and its pretty much code

There is probably something wrong with your event registering.

zacky 06-05-2009 12:20

Re: help with setting users health
 
[SOLVED]

Sylwester 06-05-2009 15:24

Re: help with setting users health
 
In my opinion your code looks horrible and you made many mistakes and I'm not talking about indentation or about if it works fine or not, but the whole idea.

Why do you divide players into ts and cts? You could get the same effect by displaying only 2 items in menu (increase health when in ct, increase health when in t). You should store costs and health bonuses in some global arrays so you can use them to check everything in 2 lines of code instead of making very long switch with 10 cases. In other words: your menu handler could be like 10 times shorter and much easier to read.

When you are coding xp/points mod you should do it step by step and make sure it all works fine after each step. Before you code saving and loading from database, you should check if health adding works by doing this:
PHP Code:

client_authorized(id){
    
gPlayerPoints[id] = 100000
    
//disable loading from database


Then you go in game and make tests. After that you can play around with saving and loading points.

Recently I started to code RPG mod and this is how my handler for buy upgrades menu with multiple pages looks like:
PHP Code:

public hnd_menu_buy_upg(id,key){
    static 
upg

    
if(key<8){
        
upg g_enabled_list[g_p_menu_page[id]*8+key]
        
g_p_credits[id] -= g_upg_sp[upg] + g_upg_ip[upg]*g_p_upg[id][upg]
        
g_p_upg[id][upg]++
        
upgrade_change(idupgUPGC_AP)
        
menu_buy_upg(idg_p_menu_page[id])
    }else if(
key==8){
        
menu_buy_upg(idg_p_menu_page[id]+1)
    }else{
        
menu_main(id)
    }

    return 
PLUGIN_HANDLED


well, I check if you can buy it in function that creates menu, but still it's just few lines in for loop...

zacky 06-05-2009 16:10

Re: help with setting users health
 
@Sylwester: Am i done with this plugin yet? No.
First i make it, then i make it better.

EDIT: I make all first to see if it works, then i make it better...

xPaw 06-05-2009 16:23

Re: [SOLVED]
 
The problem was what he was registering pre spawn forward, and in that moment player wasnt alive, so putting it as post forward solved problem.

Arkshine 06-05-2009 16:24

Re: [SOLVED]
 
zacky, why did you remove your problem in the first post, it's really stupid. Back your changes, please.

zacky 06-05-2009 16:25

Re: [SOLVED]
 
Quote:

Originally Posted by arkshine (Post 842480)
zacky, why did you remove your problem in the first post, it's really stupid. Back your changes, please.

Because its solved now...


All times are GMT -4. The time now is 23:33.

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