View Full Version : Problem with "if(getCvar" function
Invictus
27th December 2013, 23:06
Hi everyone ! :o
So... New trouble. I added to my mod, something like a "bash time" on end of map, nobody have ammo.
Callback_StartGameType()
setCvar("fun_bashtime", "0");
SpawnPlayer()
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()
if(secondsleft == 180)
{
setCvar("fun_bashtime", "1");
I allways have ammo. Why not work? No comment my way :) ps. sry for english :>
IzNoGoD
27th December 2013, 23:30
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
YuriJurek
28th December 2013, 02:13
As well you could try setting a new variable instead of cvar like
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?
IzNoGoD
28th December 2013, 09:52
As well you could try setting a new variable instead of cvar like
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...
Tally
28th December 2013, 10:43
As well you could try setting a new variable instead of cvar like
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.
Invictus
28th December 2013, 11:26
Ok, problem fixed. i paste setCvar("fun_bashtime", "0"); in for(;;) xD I don't see this.
YuriJurek
28th December 2013, 12:27
That's just wow.
kung foo man
28th December 2013, 13:13
There are sometimes strange bugs with cvar-functions, like:
Working:
iwdString = getcvar("sv_iwdNames");
iwds = strTok(iwdString, " ");
Not Working:
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.
serthy
28th December 2013, 13:35
does this only occur in strtok()?
since strtok is fcked up in CoD, even somewhere in the standart gsc files it was rewritten
guiismiti
28th December 2013, 13:51
if(secondsleft == 180)
{
setCvar("fun_bashtime", "1");
Do you get secondsleft like this?
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:
if(timelimit - timepassed == 30)
playSoundOnPlayers("thirtysecs");
if(timelimit - timepassed == 20)
playSoundOnPlayers("twentysecs");
if(timelimit - timepassed == 10)
playSoundOnPlayers("tensecs");
And this worked:
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).
PatmanSan
28th December 2013, 15:44
timepassed = (getTime() - level.starttime) / 1000;
secondsleft = int( (level.timelimit*60) - timepassed + 0.5 );
Invictus
28th December 2013, 16:17
My code works, but when sounds plays to late, just add one second. :)
passedtime = (getTime() - level.starttime) / 1000;
secondsleft = int((level.timelimit*60) - (passedtime));
if(secondsleft == 180)
{
////your code
}
guiismiti
28th December 2013, 18:42
In my code I'm using a float variable, and you are using an integer, that's probably why.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.