UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

Custom Dvars

broken avatar :(
Created 7 years ago
by NoScopeNinja25
0 Members and 1 Guest are viewing this topic.
5,881 views
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 17 April 2016
Last active: 5 years ago
Posts
11
Respect
Forum Rank
Legless Crawler
Primary Group
Member
My Contact & Social Links
More
Signature
BO3 Map(s): Die Kiste
Scripter
Mapper
×
How do you make a custom dvar?

When I run this code it crashes my game.

Code Snippet
Plaintext
function bank()
{
    players = GetPlayers();
    for (i = 0;i<players.size;i++)
    {
        players[i].balance = players[i] GetDvarInt("bank_points", 0);
    }
   
    level thread deposit();
    level thread withdraw();
}
I'm trying to use it to make a bank that saves your points between games but I can't get it to work.

Help fixing the dvar or any other way to save a variable between games would be greatly appreciated.
This topic contains a post which is marked as the Best Answer. Click here to view it.
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 4 years ago
Posts
6,877
Respect
1,004Add +1
Forum Rank
Immortal
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Signature
If you want scripts / features made for you, then contact me by PM or email / skype etc
it will cost you tho so if you have no intention of reciprocating don't even waste my time ;)
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social Links[email protected]HarryBo21HarryBo000
prob coz your "getting" a dvar that doesnt exist "before setting" it then trying to use it

also i believe GetDvar is global, so shouldnt be used "on" a player
Last Edit: January 07, 2017, 04:28:09 pm by Harry Bo21
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 17 April 2016
Last active: 5 years ago
Posts
11
Respect
Forum Rank
Legless Crawler
Primary Group
Member
My Contact & Social Links
More
×
prob coz your "getting" a dvar that doesnt exist "before setting" it then trying to use it
Dvars are different in Black Ops 3.  The number after the dvar name, in this case 0, is the default value to set the dvar if it doesn't find it.

also i believe GetDvar is global, so shouldnt be used "on" a player
I think this is the problem I was having because this code works:

Code Snippet
Plaintext
function bank()
{
    level.balance = GetDvarInt("bank_points", 0);
   
    level thread deposit();
    level thread withdraw();
}
Now I just have to figure out how to get it to work with individual players.

Also, are dvars supposed to save when you completely close the game?  Does this only happen in the mod tools or in the regular game too?  Right now it only saves when you leave the map and start the map again without closing the game.
Last Edit: January 09, 2017, 06:23:36 pm by NoScopeNinja25
Marked as best answer by NoScopeNinja25 7 years ago
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 4 years ago
Posts
6,877
Respect
1,004Add +1
Forum Rank
Immortal
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social Links[email protected]HarryBo21HarryBo000
youd need getCLIENTdvar for that, but according to the api that doesnt exist, previously this has only worked for host or via csc so im guessing at least for now thats still the case

Code Snippet
Plaintext
could do getDvarInt( "bank_player_" + int, "0" );

or something and track the players with "int"

i believe the old ugx mod did something similar back in the old days
Last Edit: January 07, 2017, 11:13:20 pm by Harry Bo21
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 17 April 2016
Last active: 5 years ago
Posts
11
Respect
Forum Rank
Legless Crawler
Primary Group
Member
My Contact & Social Links
More
×
Now when I set the dvar it sets it to 1000 and then it immediately goes to zero:

Code Snippet
Plaintext
function bank()
{
    players = GetPlayers();
    for (i = 0;i<players.size;i++)
    {
        GetDvarInt("bank_player_" + i, 0);
        players[i].order = i;
    }
   
    level thread deposit();
    level thread withdraw();
}

function deposit()
{
    trig_depo = GetEnt("deposit_trig","targetname");
    trig_depo SetHintString("Hold ^3[{+activate}]^7 to Deposit into Bank[Amount:1000]");
    trig_depo SetCursorHint("HINT_NOICON");
    while(1)
    {
        while(1)
        {
            trig_depo waittill("trigger", player);
         
            if (player zm_score::can_player_purchase(1000))
            {
                player zm_score::minus_to_player_score(1000);
                SetDvar("bank_player_" + self.order, GetDvarInt("bank_player_" + self.order)+1000);
                IPrintLn("Deposited $1000(New Total = " + GetDvarInt("bank_player_" + self.order) + ")");
                player PlayLocalSound("purchase_accept");
            }
            else
            {
                player PlayLocalSound("purchase_deny");
                IPrintLn("Not Enough Money");
            }
            break;
        }
        wait(0.25);
    }
}

function withdraw()
{
    trig_with = GetEnt("withdraw_trig", "targetname");
    trig_with SetHintString("Hold ^3[{+activate}]^7 to Withdraw From Bank\n[Amount: 1000][Fee: 100]");
    trig_with SetCursorHint("HINT_NOICON");
    while(1)
    {
        while(1)
        {
            trig_with waittill("trigger", player);
           
            if (GetDvarInt("bank_player_" + self.order) >= 1000 && player zm_score::can_player_purchase(100))
            {
                player zm_score::add_to_player_score(1000);
                SetDvar("bank_player_" + self.order, GetDvarInt("bank_player_" + self.order)-1000);
                IPrintLn("Withdrew $1000(New Total = " + GetDvarInt("bank_player_" + self.order) + ")");
                wait(0.01);
                player zm_score::minus_to_player_score(100);
                player PlayLocalSound("purchase_accept");
            }
            else if (player zm_score::can_player_purchase(100))
            {
                player PlayLocalSound("purchase_deny");
                IPrintLn("Not Enough Money");
            }
            else
            {
                player PlayLocalSound("purchase_deny");
                IPrintLn("Insufficient Funds(Total = " + GetDvarInt("bank_player_" + self.order) + ")");
            }
            break;
        }
        wait(0.25);
    }
}
broken avatar :(
×
broken avatar :(
Location: nlApeldoorn
Date Registered: 17 December 2013
Last active: 1 year ago
Posts
1,187
Respect
1,404Add +1
Forum Rank
Zombie Colossus
Primary Group
Community Scripter Elite
My Groups
More
My Contact & Social Links
More
Personal Quote
It aint much, if it aint Dutch
Signature
×
BluntStuffy's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
Oil Rig Beta Access
Oil Rig Beta Access
BluntStuffy's Contact & Social LinksBluntstuffy@BluntZombieBluntStuffyStuffyZombie
Code Snippet
Plaintext
self.order

Should be:

Code Snippet
Plaintext
player.order
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 17 April 2016
Last active: 5 years ago
Posts
11
Respect
Forum Rank
Legless Crawler
Primary Group
Member
My Contact & Social Links
More
×
I got it to work finally.  I changed the order variable to use the player's name because that works better if you play a game with someone else.  The name_split parts are to get it to work with a guest account because the space in the name messes with the dvar.  I have one more question, do dvars usually save their values after the game is closed completely?

Code Snippet
Plaintext
function bank()
{
    players = GetPlayers();
    for (i = 0;i<players.size;i++)
    {
        players[i].name_split = strTok(players[i].playername, " ");
        if (players[i].name_split.size == 2)
        {
            GetDvarInt("bank_player_" + players[i].name_split[0] + players[i].name_split[1], 0);
        }
        else
        {
            GetDvarInt("bank_player_" + players[i].playername, 0);
        }
    }
   
    level thread deposit();
    level thread withdraw();
}

function deposit()
{
    trig_depo = GetEnt("deposit_trig","targetname");
    trig_depo SetHintString("Hold ^3[{+activate}]^7 to Deposit into Bank[Amount:1000]");
    trig_depo SetCursorHint("HINT_NOICON");
    while(1)
    {
        while(1)
        {
            trig_depo waittill("trigger", player);
         
            if (player zm_score::can_player_purchase(1000))
            {
                player zm_score::minus_to_player_score(1000);
                player.name_split = strTok(player.playername, " ");
                if (player.name_split.size == 2)
                {
                    SetDvar("bank_player_" + player.name_split[0] + player.name_split[1], GetDvarInt("bank_player_" + player.name_split[0] + player.name_split[1])+1000);
                    IPrintLn("Deposited $1000(New Total = " + GetDvarInt("bank_player_" + player.name_split[0] + player.name_split[1]) + ")");
                }
                else
                {
                    SetDvar("bank_player_" + player.playername, GetDvarInt("bank_player_" + player.playername)+1000);
                    IPrintLn("Deposited $1000(New Total = " + GetDvarInt("bank_player_" + player.playername) + ")");
                }
                player PlayLocalSound("purchase_accept");
            }
            else
            {
                player PlayLocalSound("purchase_deny");
                IPrintLn("Not Enough Money");
            }
            break;
        }
        wait(0.25);
    }
}

function withdraw()
{
    trig_with = GetEnt("withdraw_trig", "targetname");
    trig_with SetHintString("Hold ^3[{+activate}]^7 to Withdraw From Bank\n[Amount: 1000][Fee: 100]");
    trig_with SetCursorHint("HINT_NOICON");
    while(1)
    {
        while(1)
        {
            trig_with waittill("trigger", player);
           
            player.name_split = strTok(player.playername, " ");
            if (player.name_split.size == 2)
            {
                if (GetDvarInt("bank_player_" + player.name_split[0] + player.name_split[1]) >= 1000 && player zm_score::can_player_purchase(100))
                {
                    player zm_score::add_to_player_score(1000);
                    SetDvar("bank_player_" + player.name_split[0] + player.name_split[1], GetDvarInt("bank_player_" + player.name_split[0] + player.name_split[1])-1000);
                    IPrintLn("Withdrew $1000(New Total = " + GetDvarInt("bank_player_" + player.name_split[0] + player.name_split[1]) + ")");
                    wait(0.01);
                    player zm_score::minus_to_player_score(100);
                    player PlayLocalSound("purchase_accept");
                }
                else if (player zm_score::can_player_purchase(100) == false)
                {
                    player PlayLocalSound("purchase_deny");
                    IPrintLn("Not Enough Money");
                }
                else
                {
                    player PlayLocalSound("purchase_deny");
                    IPrintLn("Insufficient Funds(Total = " + GetDvarInt("bank_player_" + player.name_split[0] + player.name_split[1]) + ")");
                }
            }
            else
            {
                if (GetDvarInt("bank_player_" + player.playername) >= 1000 && player zm_score::can_player_purchase(100))
                {
                    player zm_score::add_to_player_score(1000);
                    SetDvar("bank_player_" + player.playername, GetDvarInt("bank_player_" + player.playername)-1000);
                    IPrintLn("Withdrew $1000(New Total = " + GetDvarInt("bank_player_" + player.playername) + ")");
                    wait(0.01);
                    player zm_score::minus_to_player_score(100);
                    player PlayLocalSound("purchase_accept");
                }
                else if (player zm_score::can_player_purchase(100) == false)
                {
                    player PlayLocalSound("purchase_deny");
                    IPrintLn("Not Enough Money");
                }
                else
                {
                    player PlayLocalSound("purchase_deny");
                    IPrintLn("Insufficient Funds(Total = " + GetDvarInt("bank_player_" + player.playername) + ")");
                }
            }
            break;
        }
        wait(0.25);
    }
}
Last Edit: January 12, 2017, 08:55:56 pm by NoScopeNinja25
broken avatar :(
×
broken avatar :(
Location: nlApeldoorn
Date Registered: 17 December 2013
Last active: 1 year ago
Posts
1,187
Respect
1,404Add +1
Forum Rank
Zombie Colossus
Primary Group
Community Scripter Elite
My Groups
More
My Contact & Social Links
More
Personal Quote
It aint much, if it aint Dutch
×
BluntStuffy's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
Oil Rig Beta Access
Oil Rig Beta Access
BluntStuffy's Contact & Social LinksBluntstuffy@BluntZombieBluntStuffyStuffyZombie
No they dont, you can try and use

Code Snippet
Plaintext
SetSavedDvar( <dvar>, <value> );

and otherwise you have to use stats to be able to save it between games.

EDIT:
one thing you might want to think about: dvar's can be very easily changed by the player using the console ( not sure about a saved-dvar, but i think as well ). Easy way to get points  :D
Last Edit: January 12, 2017, 10:02:18 pm by BluntStuffy
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 17 April 2016
Last active: 5 years ago
Posts
11
Respect
Forum Rank
Legless Crawler
Primary Group
Member
My Contact & Social Links
More
×
Code Snippet
Plaintext
SetSavedDvar( <dvar>, <value> );
I couldn't find "SetSavedDvar" in the BO3 API.

and otherwise you have to use stats to be able to save it between games.
How do you use stats?
broken avatar :(
×
broken avatar :(
Location: gbMilton Keynes
Date Registered: 17 January 2014
Last active: 4 years ago
Posts
6,877
Respect
1,004Add +1
Forum Rank
Immortal
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
×
Harry Bo21's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Harry Bo21's Contact & Social Links[email protected]HarryBo21HarryBo000
I read somewhere set stat is disabled in bo3
broken avatar :(
×
broken avatar :(
Location: nlApeldoorn
Date Registered: 17 December 2013
Last active: 1 year ago
Posts
1,187
Respect
1,404Add +1
Forum Rank
Zombie Colossus
Primary Group
Community Scripter Elite
My Groups
More
My Contact & Social Links
More
Personal Quote
It aint much, if it aint Dutch
×
BluntStuffy's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
Oil Rig Beta Access
Oil Rig Beta Access
BluntStuffy's Contact & Social LinksBluntstuffy@BluntZombieBluntStuffyStuffyZombie
I couldn't find "SetSavedDvar" in the BO3 API.
How do you use stats?

Yeah, i kinda forgot it was about bo3 when i replied there.. Not sure if any of those are in bo3, my bad..

 
Loading ...