Raised This Month: $ Target: $400
 0% 

[SOLVED] Setting health in Ham_Spawn, error come in game


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zacky
Senior Member
Join Date: Mar 2008
Location: Sweden
Old 06-05-2009 , 18:22   [SOLVED] Setting health in Ham_Spawn, error come in game
Reply With Quote #1

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
Attached Thumbnails
Click image for larger version

Name:	hahajsrjs.jpg
Views:	301
Size:	96.0 KB
ID:	43293  

Last edited by zacky; 06-06-2009 at 06:45.
zacky is offline
Send a message via Skype™ to zacky
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-05-2009 , 18:26   Re: Setting health in Ham_Spawn, error come in game
Reply With Quote #2

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.
__________________
hleV is offline
zacky
Senior Member
Join Date: Mar 2008
Location: Sweden
Old 06-05-2009 , 18:28   Re: Setting health in Ham_Spawn, error come in game
Reply With Quote #3

Quote:
Originally Posted by hleV View Post
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.
zacky is offline
Send a message via Skype™ to zacky
IneedHelp
Veteran Member
Join Date: Mar 2007
Location: Argentina
Old 06-05-2009 , 19:29   Re: Setting health in Ham_Spawn, error come in game
Reply With Quote #4

Quote:
Originally Posted by zacky View Post
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..
__________________
IneedHelp is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-05-2009 , 19:43   Re: Setting health in Ham_Spawn, error come in game
Reply With Quote #5

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);             }         }     } }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 06-06-2009 , 05:28   Re: Setting health in Ham_Spawn, error come in game
Reply With Quote #6

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] )); 
        } 
    } 

__________________
xPaw is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-06-2009 , 06:00   Re: Setting health in Ham_Spawn, error come in game
Reply With Quote #7

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
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
zacky
Senior Member
Join Date: Mar 2008
Location: Sweden
Old 06-06-2009 , 06:28   Re: Setting health in Ham_Spawn, error come in game
Reply With Quote #8

Ok, thanks, i will try all your codes.
zacky is offline
Send a message via Skype™ to zacky
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-06-2009 , 06:30   Re: Setting health in Ham_Spawn, error come in game
Reply With Quote #9

Quote:
Originally Posted by ConnorMcLeod View Post
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?
__________________
hleV is offline
zacky
Senior Member
Join Date: Mar 2008
Location: Sweden
Old 06-06-2009 , 06:44   Re: Setting health in Ham_Spawn, error come in game
Reply With Quote #10

Thanks Exolent, your way works, i just added float(iHealth)
Now it works fine, thanks
zacky is offline
Send a message via Skype™ to zacky
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 13:52.


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