Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Problem with "if(getCvar" function

  1. #1
    Private Invictus's Avatar
    Join Date
    Mar 2013
    Location
    Poland
    Posts
    32
    Thanks
    25
    Thanked 13 Times in 6 Posts

    Angry Problem with "if(getCvar" function

    Hi everyone !


    So... New trouble. I added to my mod, something like a "bash time" on end of map, nobody have ammo.



    Callback_StartGameType()
    PHP Code:
    setCvar("fun_bashtime""0"); 


    SpawnPlayer()
    PHP Code:
            self giveWeapon(self.pers["weapon"]);
            
    self setSpawnWeapon(self.pers["weapon"]);
        
        if(
    getCvar("fun_bashtime") == 1)
        { 
            
    self setWeaponSlotAmmo("primaryb"0);
            
    self setWeaponSlotClipAmmo("primaryb"0);
        }
        
        if(
    getCvar("fun_bashtime") == 0)
        {
            
    self giveMaxAmmo(self.pers["weapon"]);
        } 

    checkTimeLimit()
    PHP Code:
    if(secondsleft == 180
        { 
        
    setCvar("fun_bashtime""1"); 

    I allways have ammo. Why not work? No comment my way ps. sry for english :>
    Xfire : rozpierdalacz0

  2. #2
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    cvar returns a string
    try getcvarint.

    ninjaedit: also, that only works once a player goes through spawnplayer(), which it might not be. Try doing /kill when bashmode is enabled

  3. The Following User Says Thank You to IzNoGoD For This Useful Post:

    YuriJurek (28th December 2013)

  4. #3
    Private First Class YuriJurek's Avatar
    Join Date
    Jun 2013
    Posts
    219
    Thanks
    152
    Thanked 88 Times in 47 Posts
    As well you could try setting a new variable instead of cvar like
    PHP Code:
    fun_bashtime 1;

    // and then

        
    if(fun_bashtime == 1)
        { 
            
    self setWeaponSlotAmmo("primaryb"0);
            
    self setWeaponSlotClipAmmo("primaryb"0);
        }
        else
        {
            
    self giveMaxAmmo(self.pers["weapon"]);
        } 
    Anyway for my own info, is there any advantage of setting a cvar over variables?
    Last edited by YuriJurek; 28th December 2013 at 02:16.

  5. #4
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Quote Originally Posted by YuriJurek View Post
    As well you could try setting a new variable instead of cvar like
    PHP Code:
    fun_bashtime 1;

    // and then

        
    if(fun_bashtime == 1)
        { 
            
    self setWeaponSlotAmmo("primaryb"0);
            
    self setWeaponSlotClipAmmo("primaryb"0);
        }
        else
        {
            
    self giveMaxAmmo(self.pers["weapon"]);
        } 
    Anyway for my own info, is there any advantage of setting a cvar over variables?

    Probably due to the fact you can rcon-change it.

    Also, your code uses local vars, which is not the most useful thing to do...

  6. The Following User Says Thank You to IzNoGoD For This Useful Post:

    YuriJurek (28th December 2013)

  7. #5
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by YuriJurek View Post
    As well you could try setting a new variable instead of cvar like
    PHP Code:
    fun_bashtime 1;

    // and then

        
    if(fun_bashtime == 1)
        { 
            
    self setWeaponSlotAmmo("primaryb"0);
            
    self setWeaponSlotClipAmmo("primaryb"0);
        }
        else
        {
            
    self giveMaxAmmo(self.pers["weapon"]);
        } 
    Anyway for my own info, is there any advantage of setting a cvar over variables?
    Anyway for my own info, is there any advantage of setting a cvar over variables?
    The advantages of using variables instead of seeking the value of a cvar come into its own when seeking the value for a client/player, as you cannot get the value of a cvar for a client/player without using a menu. Hence, getting a client/player variable is the done thing. I typically turn all cvars into variables and seek the value of variables habitually as it is more sure-fire.

  8. The Following User Says Thank You to Tally For This Useful Post:

    YuriJurek (28th December 2013)

  9. #6
    Private Invictus's Avatar
    Join Date
    Mar 2013
    Location
    Poland
    Posts
    32
    Thanks
    25
    Thanked 13 Times in 6 Posts
    Ok, problem fixed. i paste setCvar("fun_bashtime", "0"); in for(;;) xD I don't see this.
    Xfire : rozpierdalacz0

  10. #7
    Private First Class YuriJurek's Avatar
    Join Date
    Jun 2013
    Posts
    219
    Thanks
    152
    Thanked 88 Times in 47 Posts
    That's just wow.

  11. #8
    Assadministrator kung foo man's Avatar
    Join Date
    Jun 2012
    Location
    trailerpark
    Posts
    2,011
    Thanks
    2,102
    Thanked 1,084 Times in 753 Posts
    There are sometimes strange bugs with cvar-functions, like:

    Working:
    PHP Code:
        iwdString getcvar("sv_iwdNames");
        
    iwds strTok(iwdString" "); 
    Not Working:
    PHP Code:
        iwds strTok(getcvar("sv_iwdNames"), " "); 
    "Logically" thats the same code, but a getcvar-function used directly as an argument for another function fails for some reason. I dont see that bug here, but might help somebody at some point.
    timescale 0.01

  12. #9
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    does this only occur in strtok()?

    since strtok is fcked up in CoD, even somewhere in the standart gsc files it was rewritten

  13. The Following User Says Thank You to serthy For This Useful Post:

    kung foo man (28th December 2013)

  14. #10
    Corporal guiismiti's Avatar
    Join Date
    Dec 2013
    Location
    Brazil
    Posts
    244
    Thanks
    121
    Thanked 42 Times in 31 Posts
    Quote Originally Posted by Invictus View Post
    PHP Code:
    if(secondsleft == 180
        { 
        
    setCvar("fun_bashtime""1"); 
    Do you get secondsleft like this?

    PHP Code:
    timepassed = (getTime() - level.starttime) / 1000;
    timelimit level.timelimit*60;
    secondsleft timelimit timepassed

    I'm asking it because I created a little code to play those time warning sounds from Counter Strike. It will play at 30 and 20 seconds left and also a countdown from 10 to 1.

    This did not work for me:

    PHP Code:
    if(timelimit timepassed == 30)
        
    playSoundOnPlayers("thirtysecs");

    if(
    timelimit timepassed == 20)
        
    playSoundOnPlayers("twentysecs");

    if(
    timelimit timepassed == 10)
        
    playSoundOnPlayers("tensecs"); 

    And this worked:

    PHP Code:
        if((timelimit timepassed 29.7)&&(timelimit timepassed 30.3))
            
    playSoundOnPlayers("thirtysecs");

        if((
    timelimit timepassed 19.7)&&(timelimit timepassed 20.3))
            
    playSoundOnPlayers("twentysecs");

        if((
    timelimit timepassed 9.7)&&(timelimit timepassed 10.3))
            
    playSoundOnPlayers("tensecs"); 
    It probably happens because checkTimeLimit is called every 1 second. So, I'm curious to know how you made it work with if(secondsleft == 180).
    Last edited by guiismiti; 28th December 2013 at 14:00.
    set logfile 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •