AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_gametime mismatch (https://forums.alliedmods.net/showthread.php?t=126270)

HLM 05-07-2010 18:08

get_gametime mismatch
 
PHP Code:

public Health_Regen(id)
{
    switch(
LEVELS[id])
    {
        case 
1:
        {
            
g_healthtime[id] = (get_gametime() + 5.0)
            while(
g_healthtime[id] == get_gametime())
            {
                new 
health get_user_health(id)
                
set_user_health(id, (health +3) )
            }
            
        }
        case 
2:
        {
            
g_healthtime[id] = (get_gametime() + 3.0)
            while( 
g_healthtime[id] == get_gametime() )
            {
                new 
health get_user_health(id)
                
set_user_health(id, (health +5) )
            }
        }
    }    


tag mismatch on the
PHP Code:

g_healthtime[id] = (get_gametime() + 5.0)
g_healthtime[id] = (get_gametime() + 3.0

do I need to define the 3.0 and 5.0 as floats somewhere??

Arkshine 05-07-2010 18:41

Re: get_gametime mismatch
 
is g_healthtime a float ?

HLM 05-07-2010 18:45

Re: get_gametime mismatch
 
yeah, I went wrong there.. I fixed it, but it says it isnt working "as expected"

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <engine>
#include <fun>
#include <fvault>
#include <hamsandwich>

#define PLUGIN "TFC XP Mod"
#define VERSION "1.0"
#define AUTHOR "Master"

#define VAULTNAME "tfc_xp_mod"

new PlayerXP[33], PlayerLevel[33]
new 
amx_xp_hsbonusamx_xp_killreward

new const LEVELS[2] = {
    
100,
    
200
}

new 
Float:g_healthtime[33]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_event("DeathMsg""deathmsg""a")
    
amx_xp_hsbonus register_cvar("amx_xp_hsbonus","20")
    
amx_xp_killreward register_cvar("amx_xp_killreward","60")
    
RegisterHam(Ham_Spawn,"player","Player_Spawn",1)
    
register_clcmd("say /xp","DisplayHud")
    
register_clcmd("say_team /xp","DisplayHud")
    
register_clcmd("say !time","DisplayTime")
}

public 
client_connect(id)
{
    if( !
is_user_bot(id) )
    {
        
LoadData(id)
    }
}

public 
client_disconnect(id)
{
    new 
steamid[33]
    
get_user_authid(id,steamid,32)
    if( !
is_user_bot(id) )
    {
        new 
savedxp[65]
        
num_to_str(PlayerXP[id],savedxp,64)
        
fvault_set_data(VAULTNAME,steamid,savedxp)
    }
}

public 
deathmsg()
{
    new 
killerid read_data(1)
    
//new victimid = read_data(2)
    
new headshot read_data(3)
    
    
PlayerXP[killerid] += get_pcvar_num(amx_xp_killreward)
    
    if( 
headshot )
        
PlayerXP[killerid] += get_pcvar_num(amx_xp_hsbonus)
    
    
    
    if(
PlayerXP[killerid] >= LEVELS[PlayerLevel[killerid]])
    {
        
PlayerLevel[killerid] += 1
        client_print
(killeridprint_chat"[AMXX] Congratulations! You are level %i!",PlayerLevel[killerid])
    }
    
DisplayHud(killerid)
    
SaveData(killerid)
}

public 
DisplayHud(id)
{
    
set_hudmessage(02552550.750.0106.015.0)
    
show_hudmessage(id"Level: %i^nXP: %i",PlayerLevel[id],PlayerXP[id])
}

public 
SaveData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
    
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-xPmoD",AuthID)
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id])
    
fvault_set_data(VAULTNAME,vaultkey,vaultdata)
    return 
PLUGIN_CONTINUE
}
public 
LoadData(id)
{
    new 
AuthID[35]
    
get_user_authid(id,AuthID,34)
    
    new 
vaultkey[64],vaultdata[256]
    
format(vaultkey,63,"%s-xPmoD",AuthID)
    
format(vaultdata,255,"%i#%i#",PlayerXP[id],PlayerLevel[id])
    
fvault_get_data(VAULTNAME,vaultkey,vaultdata,255)
    
    
replace_all(vaultdata255"#"" ")
    
    new 
playerxp[32], playerlevel[32]
    
    
parse(vaultdataplayerxp31playerlevel31)
    
    
PlayerXP[id] = str_to_num(playerxp)
    
PlayerLevel[id] = str_to_num(playerlevel)
    
    return 
PLUGIN_CONTINUE
}

public 
Player_Spawn(id)
{
    new class = 
entity_get_int(idEV_INT_playerclass)
    switch(class)
    {
        case 
0:
        {
            
set_task(0.1,"Player_Spawn",id)
        }
        case 
.. 10:
        {
            
Health_Regen(id)
        }
    }
}

public 
Health_Regen(id)
{
    if(
g_healthtime[id] == 0)
        
g_healthtime[id] = get_gametime()
    switch(
LEVELS[id])
    {
        case 
1:
        {
            while(
g_healthtime[id] == get_gametime())
            {
                new 
health get_user_health(id)
                
set_user_health(id, (health 3) )
                
g_healthtime[id] = get_gametime() + 5.0
            
}
            
        }
        case 
2:
        {
            while( 
g_healthtime[id] == get_gametime() )
            {
                new 
health get_user_health(id)
                
set_user_health(id, (health 5) )
                
g_healthtime[id] = get_gametime() + 3.0
            
}
        }
    }    
}

public 
DisplayTime(id)
{
    new 
Float:currenttime get_gametime()
    new 
Float:timeplusfive = ( get_gametime() + 5.0 )
    
client_print(id,print_chat,"[AMXX] Gametime:%f Next Check:%f Your Time:%f",currenttime,timeplusfive,g_healthtime[id])


this is obviously a very rough prototype, but "my time" is always less than next check and the current gametime, am I using the "while" loop wrong?

Arkshine 05-07-2010 18:53

Re: get_gametime mismatch
 
lol, you can't do that while() and such, it doesn't work like that. You have to set a set_task or using function/entity which thinks.

HLM 05-07-2010 18:59

Re: get_gametime mismatch
 
=/ im trying to get off the whole set_task, but I see since im expecting something in the future to happen "now" it will never happen and will always exit the loop, so ill have to set the task and adjust the code, thanks arkshine.


All times are GMT -4. The time now is 03:46.

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