AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Whats wrong with this code ? (https://forums.alliedmods.net/showthread.php?t=282323)

Awesome_man 05-04-2016 10:34

Whats wrong with this code ?
 
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN ""
#define VERSION "1.0"
#define AUTHOR ""



public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
}


public 
client_putinserver(id)
{
    if(!
is_user_connected(id))
    {
        return 
PLUGIN_HANDLED
    
}
    
    new 
time get_user_time(id,1);
    if(
time/60 240)
    {
        return 
PLUGIN_HANDLED
    

    
    if(
time/60 == 30)
    {
        
cs_set_user_money(id,2000)
        
    }
    else if(
time/60 == 60)
    {
        
cs_set_user_money(id,6000)
        
    }
    else if(
time/60 == 120)
    {
        
cs_set_user_money(id,4000)
        
    }
    else if(
time/60 == 180)
    {
        
cs_set_user_money(id,3000)
        
    }
    else 
    { 
        
cs_set_user_money(id,2000
    
    }
    
     


it's not working properly after playing 5 min it's giving me 4000 money

mlibre 05-08-2016 01:54

Re: Whats wrong with this code ?
 
test:

PHP Code:

public client_putinserver(id)
{
    if(!
is_user_connected(id))
    {
        return 
PLUGIN_HANDLED
    
}
    
    if(
get_user_time(id1) % 3600 60 240)
    {
        return 
PLUGIN_HANDLED
    

    
    if(
get_user_time(id1) % 3600 60 == 30)
    {
        
cs_set_user_money(id,2000)
        
    }
    
//..



siriusmd99 05-09-2016 07:02

Re: Whats wrong with this code ?
 
Because you use == , use comparing symbols instead : <, >. Values can't be exact.

Black Rose 05-10-2016 11:53

Re: Whats wrong with this code ?
 
Maybe a switch could help by making it easier to read and edit
Code:
public client_putinserver(id) {     if ( ! is_user_connected(id) )         return         switch ( get_user_time(id, 1) / 60 ) {         case   0 ..  29 : cs_set_user_money(id,2000)         case  30 ..  59 : cs_set_user_money(id,2000)         case  60 .. 119 : cs_set_user_money(id,6000)         case 120 .. 179 : cs_set_user_money(id,4000)         case 180 .. 239 : cs_set_user_money(id,3000)         default : return; // if the value of get_user_time()/60 can't be applied to any of the above alternatives this will be called.     }   }

siriusmd99 05-10-2016 14:41

Re: Whats wrong with this code ?
 
actually
case 0 .. 59 : cs_set_user_money(id,2000)


:))

siriusmd99 05-10-2016 14:44

Re: Whats wrong with this code ?
 
i dont understand, this native gets time played on current session and he uses it at client putinserver.IT wont give values more then 10 seconds ,will IT?
IT saves played time on disconnect ?

fysiks 05-10-2016 22:28

Re: Whats wrong with this code ?
 
"user time" is time connected to the server, not the map. If you view the info on a server, you'll probably see people with times greater than the map timelimit.

siriusmd99 05-11-2016 08:04

Re: Whats wrong with this code ?
 
Wait, you mean that i can use this native to show played time of the player without making a plugin that stores played time in nvault?

fysiks 05-11-2016 08:46

Re: Whats wrong with this code ?
 
Quote:

Originally Posted by siriusmd99 (Post 2418245)
Wait, you mean that i can use this native to show played time of the player without making a plugin that stores played time in nvault?

"user time" is reset when you leave the server (or when your computer fails to re-connect to the server during a map change quick enough, in my experience).

So, if you are trying to maintain the total time a player has been on the server, ever, I would not recommend using "user time". A plugin like you describe would be more reliable.

siriusmd99 05-11-2016 09:10

Re: Whats wrong with this code ?
 
Yes man, i meant this. If player disconnects then user time resets and this guy is using this native on client_putinserver and it wont give more than 10 seconds because he just connected.
Isn't this true?


All times are GMT -4. The time now is 18:35.

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