AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] Setting health in Ham_Spawn, error come in game (https://forums.alliedmods.net/showthread.php?t=94034)

zacky 06-05-2009 18:22

[SOLVED] Setting health in Ham_Spawn, error come in game
 
1 Attachment(s)
I am using this code:
PHP Code:

public fwSpawn(id) {
    if (
is_user_alive(id)) {
        new 
iHealth pev(idpev_health);
        
        switch (
cs_get_user_team(id)) {
            case 
CS_TEAM_CTset_pev(idpev_healthiHealth gPlayerCtHealth[id]);
            case 
CS_TEAM_Tset_pev(idpev_healthiHealth gPlayerTHealth[id]);
        }
    }


It's like your dead all the time but still alive.

Watch the picture.

It worked before, but when i coded abit more (not this health stuff), this happened, then i removed what i made, and its still there :S

gPlayerCtHealth[id] and gPlayerTHealth[id] can only be those values: 0, 10, 20, 30, 40, 50.

Thanks
-zacky

hleV 06-05-2009 18:26

Re: Setting health in Ham_Spawn, error come in game
 
Code:
public fwSpawn(id)         if (is_user_alive(id))         {                 new Float:fHealth;                 pev(id, pev_health, fHealth);                   switch (cs_get_user_team(id))                 {                         case CS_TEAM_CT: set_pev(id, pev_health, fHealth + gPlayerCtHealth[id]);                         case CS_TEAM_T: set_pev(id, pev_health, fHealth + gPlayerTHealth[id]);                 }         }
If this still doesn't work, that means the problem is in gPlayer[Ct|T]Health[]. That bug happens when player's health is 0 or below.

zacky 06-05-2009 18:28

Re: Setting health in Ham_Spawn, error come in game
 
Quote:

Originally Posted by hleV (Post 842559)
Code:
public fwSpawn(id)         if (is_user_alive(id))         {                 new Float:fHealth;                 pev(id, pev_health, fHealth);                   switch (cs_get_user_team(id))                 {                         case CS_TEAM_CT: set_pev(id, pev_health, fHealth + gPlayerCtHealth[id]);                         case CS_TEAM_T: set_pev(id, pev_health, fHealth + gPlayerTHealth[id]);                 }         }
If this still doesn't work, that means the problem is in gPlayer[Ct|T]Health[]. That bug happens when player's health is 0 or below.

Health is not a float

And gPlayerCtHealth[id] and gPlayerTHealth[id] can only be those values: 0, 10, 20, 30, 40, 50.

IneedHelp 06-05-2009 19:29

Re: Setting health in Ham_Spawn, error come in game
 
Quote:

Originally Posted by zacky (Post 842560)
Health is not a float

And gPlayerCtHealth[id] and gPlayerTHealth[id] can only be those values: 0, 10, 20, 30, 40, 50.

Health IS a float and you should make those 2 variables floats..

Exolent[jNr] 06-05-2009 19:43

Re: Setting health in Ham_Spawn, error come in game
 
You don't have to set a float value.
And, you don't have to retrieve it as a float.
It will work just like his code should.

@zacky
1. Did you register it as a POST hook?
Code:
RegisterHam(Ham_Spawn, "player", "fwSpawn", 1)

2. If you did register post, add some debug messages:
Code:
public fwSpawn(id) {     if (is_user_alive(id)) {         new iHealth = pev(id, pev_health);         client_print(id, print_chat, "Current Health: %i", iHealth);         switch (cs_get_user_team(id)) {             case CS_TEAM_CT: {                 iHealth += gPlayerCtHealth[id];                 client_print(id, print_chat, "New Health: %i", iHealth);                 set_pev(id, pev_health, iHealth);             }             case CS_TEAM_T: {                 iHealth += gPlayerTHealth[id];                 client_print(id, print_chat, "New Health: %i", iHealth);                 set_pev(id, pev_health, iHealth);             }         }     } }

xPaw 06-06-2009 05:28

Re: Setting health in Ham_Spawn, error come in game
 
They need to be float owerthise it always will set 0.
PHP Code:

public fwSpawn(id) { 
    if (
is_user_alive(id)) { 
        new 
iHealth pev(idpev_health); 
         
        switch (
cs_get_user_team(id)) { 
            case 
CS_TEAM_CTset_pev(idpev_healthfloat(iHealth gPlayerCtHealth[id] )); 
            case 
CS_TEAM_Tset_pev(idpev_healthfloatiHealth gPlayerTHealth[id] )); 
        } 
    } 



ConnorMcLeod 06-06-2009 06:00

Re: Setting health in Ham_Spawn, error come in game
 
Better code is #2 by Hev.
Retrieve actual health as a float is fine.
Then add to it interger or float, it will still be a float.

100.0 + 10 will pass 110.0

zacky 06-06-2009 06:28

Re: Setting health in Ham_Spawn, error come in game
 
Ok, thanks, i will try all your codes.

hleV 06-06-2009 06:30

Re: Setting health in Ham_Spawn, error come in game
 
Quote:

Originally Posted by ConnorMcLeod (Post 842889)
Better code is #2 by Hev.
Retrieve actual health as a float is fine.
Then add to it interger or float, it will still be a float.

100.0 + 10 will pass 110.0

Who's Hev?

zacky 06-06-2009 06:44

Re: Setting health in Ham_Spawn, error come in game
 
Thanks Exolent, your way works, i just added float(iHealth)
Now it works fine, thanks :P


All times are GMT -4. The time now is 13:52.

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