Active Player Reward System

Discussion in 'Scripting Discussions' started by TylerHumor, Jun 28, 2014.

  1. TylerHumor

    TylerHumor Member

    Joined:
    Jul 3, 2013
    Messages:
    94
    Likes Received:
    2
    I'm looking for a way to implement a system that rewards players once a day for logging in and playing.
    It would reward them maybe gold, or a currency I haven't implemented like topaz which would be redeemable at a custom trader, which they could get special items with their topaz that they achieved from being a dedicated player.
     
  2. Matt L

    Matt L OpenDayZ Rockstar!

    Joined:
    May 10, 2013
    Messages:
    841
    Likes Received:
    136
    idk about logging in but you could have a script based on time played using diag_tickTime. It executes and starts a timer when they first log in and resets everytime they log out, but if they are online long enough it gives them the item etc etc
     
  3. TylerHumor

    TylerHumor Member

    Joined:
    Jul 3, 2013
    Messages:
    94
    Likes Received:
    2
    Is there a way I could make the script give them a reward once daily for being on as little as a minute?
     
  4. Matt L

    Matt L OpenDayZ Rockstar!

    Joined:
    May 10, 2013
    Messages:
    841
    Likes Received:
    136
    You could probably run an event in your database that adds an item to their inventory if they've logged in, and runs it once a day. I don't know enough sql to help with that, though
     
  5. FallingSheep

    FallingSheep OpenDayZ Lord!

    Joined:
    Mar 17, 2013
    Messages:
    1,964
    Likes Received:
    576
    Im working on my levels system but it's not saving between loads (no Sql yet) but ialso wanted to count the number of times a player logged in each day and how many days in a row

    I'm making progress slowly and will post how I did it when I'm finished
     
  6. TylerHumor

    TylerHumor Member

    Joined:
    Jul 3, 2013
    Messages:
    94
    Likes Received:
    2
    I know it's been a while, but I'd like to ask if you know of a way I could do this.
    Specifically, each hour they're on the server, I don't care if it's in the lobby or not, they get a prize that I could customize.
     
  7. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    [​IMG]

    That being said ... this isnt very hard ... I think .. have to test this code and see what happens.
    I believe that this data will be deleted when you quit Arma2 so it will be reset to 0. Then this counter will only increment when they are playing on your server. If they play 30 minutes, then go to another server and come back it will start at 30 minutes and count up from there .. as long as they dont quit Arma2.
    EDIT: I was wrong. Killzone Kid says the profilenamespace variables will be saved automatically (I thought you HAD to use saveprofilenamespace) which means the counter will never reset .. so have to ponder a method to reset the data when you quit the game so it only counts this session. This would not be an issue if we discounted being in the LOBBY. So if we only reward them for how long they play and do not DIE, then it would be simple. Going to the lobby resets all the variables except profilenamespace.

    What we could do instead is keep the counter running when they are in the server and just give a reward for every 60 minutes or something using this code.
    if (_minutes mod 60 == 0) then


    rewardme.sqf
    Code:
    _minutes= profilenamespace getvariable["onlinetime",0];
    while {true} do {
    profilenamespace setVariable ["onlinetime",_minutes];
    sleep 60;
    _minutes= _minutes+ 1; //minutes connected
    switch (_minutes)   do {
    case 30: {
                   //reward for 30 minutes
                   };
    case 60: {
                   //reward for 60 minutes
                    };
    case 90: {
                   //reward for 90 minutes
                    };
    };
    };
    
    and in your init.sqf
    Code:
    if (!isserver) then {
    execvm "rewardme.sqf";
    };
    
     
    Last edited: Jan 3, 2015
  8. TylerHumor

    TylerHumor Member

    Joined:
    Jul 3, 2013
    Messages:
    94
    Likes Received:
    2
    I am truly dying from the picture. XD
    "if (_minutes mod 60 == 0) then " <-- example or do I use this? lol

    rewardme.sqf to dayz.code/mission.pbo?


    How would I customize the rewards?

    By the way thank you so much for the response! :D
     
  9. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    if (_minutes mod 60 == 0) then
    the math operator "mod" is a division operator that returns the remainder .. So 17 / 5 = 3 with a remainder of 2. Using mod it would be 17 mod 5 = 2 because 2 is the remainder. This allows us to find out if a number is a multiple of another number because it will have a remainder of zero.
    So 60,120,180,240,300 ... all will have a remainder of zero when divided by 60. What we are doing is triggering the rest of the script whenever our timer hits one of those numbers. You could just as easily have multiple switch-case or if-then statements testing for the actual time, but I like to have an overall test at the start.

    Almost every script you add will go into the mission folder and be executed from your init.sqf file.

    to customize the rewards just insert code into the case statements giving whatever you want. NVG's, restore health, spawn a vehicle, spawn a hooker .. whatever.

    case 60: { //reward for 60 minutes
    player addweapon "nvg";
    };

    I sense that you are a sqf noob .. no shame in that, we all learned at somepoint. Only problem is that I will happily give help but I dont have the time or desire to create fully functioning scripts so its up to you to take this 'hint' and turn it into a working script. Its not tested, I can almost guarantee it wont work as-is, but it will take VERY LITTLE edits to complete. At least you are in the right direction. And this goes for all the answers I give on this site, most of them are from my cellphone while I am at work (work 16 hours a day 5 days a week, recover on the other two) so they can get you in the right direction but dont expect them to be finished or working.
     
  10. TylerHumor

    TylerHumor Member

    Joined:
    Jul 3, 2013
    Messages:
    94
    Likes Received:
    2
    Code:
    _minutes= profilenamespace getvariable["onlinetime",0];
    while {true} do {
    profilenamespace setVariable ["onlinetime",_minutes];
    sleep 60;
    _minutes= _minutes+ 1; //minutes connected
    switch (_minutes)   do {
    case 30: {
    player addrandom "30time_random"               //reward for 30 minutes
                                    };
    case 60: {
    player addrandom "60time_random"               //reward for 60 minutes
                                    };
    case 90: {
    player addrandom "90time_random"               //reward for 90 minutes
                                    };
                                };
                            };
                        };
                    };
                };   
            time_items                    = ["FoodNutmix","FoodPistachio","FoodMRE","ItemSodaOrangeSherbet","ItemSodaRbull","ItemSodaR4z0r","ItemSodaPepsi","ItemBandage","ItemSodaCoke","FoodbaconCooked","FoodCanBakedBeans","FoodCanFrankBeans","FoodCanPasta","FoodCanSardines","FoodchickenCooked","FoodmuttonCooked","FoodrabbitCooked","ItemTroutCooked","ItemTunaCooked","ItemSeaBassCooked","ItemAntibiotic","ItemBloodbag","ItemEpinephrine","ItemHeatPack","ItemMorphine","ItemGoldBar","ItemGoldBar10oz","CinderBlocks","ItemCanvas","ItemComboLock","ItemLightBulb","ItemLockbox","ItemSandbag","ItemTankTrap","ItemWire","MortarBucket","PartEngine","PartFueltank","PartGeneric","PartGlass","PartPlankPack","PartVRotor","PartWheel","PartWoodPile"];
            time_items_high_value        = ["ItemBriefcase100oz","ItemVault","30m_plot_kit","ItemHotwireKit"];
            time_items_food            = ["ItemWaterbottle","FoodNutmix","FoodPistachio","FoodMRE","ItemSodaOrangeSherbet","ItemSodaRbull","ItemSodaR4z0r","ItemSodaPepsi","ItemSodaCoke","FoodbaconCooked","FoodCanBakedBeans","FoodCanFrankBeans","FoodCanPasta","FoodCanSardines","FoodchickenCooked","FoodmuttonCooked","FoodrabbitCooked","ItemTroutCooked","ItemTunaCooked","ItemSeaBassCooked"];
            time_items_buildables        = ["forest_large_net_kit","cinder_garage_kit",["PartPlywoodPack",5],"ItemSandbagExLarge5X","park_bench_kit","ItemComboLock",["CinderBlocks",10],"ItemCanvas","ItemComboLock",["ItemLightBulb",5],"ItemLockbox",["ItemSandbag",10],["ItemTankTrap",10],["ItemWire",10],["MortarBucket",10],["PartPlankPack",5],"PartWoodPile"];
            time_items_vehicle_repair    = ["PartEngine","PartFueltank","PartGeneric","PartGlass","PartVRotor","PartWheel"];
            time_items_medical            = ["ItemWaterbottle","ItemAntibiotic","ItemBloodbag","ItemEpinephrine","ItemHeatPack","ItemMorphine","ItemBandage","FoodCanFrankBeans","FoodCanPasta"];
            time_items_chainbullets    = ["2000Rnd_762x51_M134","200Rnd_762x51_M240","100Rnd_127x99_M2","150Rnd_127x107_DSHKM"];   
           
            30time_random                = [time_items,time_items_food,time_items_buildables,time_items_vehicle_repair,time_items_medical,time_items_chainbullets];
            60time_random               = [time_items_vehicle_repair,time_items_buildables,time_items_medical,time_items_chainbullets];
            90time_random                = [time_items_high_value,time_items_buildables,time_items_vehicle_repair,time_items_chainbullets];
    This is what I've done so far and I did it in a very short amount of time. I know for a fact that it is wrong, but I was hoping that you could point me in the right direction.
    I'm wanting the script to choose one item out of any of the the groups listed for the time when they reach the time instructed: 30,60,90. Not one out of each group, but just one item. The closer you get to group "90" the better the chance of better loot.
     
  11. Matt L

    Matt L OpenDayZ Rockstar!

    Joined:
    May 10, 2013
    Messages:
    841
    Likes Received:
    136
    That code is so wrong it hurts to look at and I don't have the time to fix it, but good try.
     
  12. TylerHumor

    TylerHumor Member

    Joined:
    Jul 3, 2013
    Messages:
    94
    Likes Received:
    2
    :D:D:D:D:D
    Don't make me blush. Yeah, I've never tried to write my own.
     
  13. Matt L

    Matt L OpenDayZ Rockstar!

    Joined:
    May 10, 2013
    Messages:
    841
    Likes Received:
    136
    well, addrandom isn't a command. You'll want seperate arrays that contain either magazines or weapons. and you cant do ["item",5] for quantity, at least not how you're trying. What you're going to need to do (especially for all the shit you want to add) is create a box or something at their feet, then display a message. Then using the foreach command, example :
    Code:
    _array = ["list","of","magazines"];
    { _box addMagazineCargoGlobal _x; } forEach _array;
    and for things you want more than one of, just add another to the array. It's gonna be kind of a bulky script once you get going, but otherwise should work. Also all the shit you want to add needs to be declared at the top of the script so that each individual part can actually access it, otherwise the script will break.
     
  14. delpi

    delpi Well-Known Member

    Joined:
    Feb 4, 2014
    Messages:
    336
    Likes Received:
    15
    I have nothing to really add other than to add my love for the graphic from ShootingBlanks
     
    Matt L likes this.
  15. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    First of all, you are using a switch case statement that is adding variables that are defined AFTER the code that uses them. Move your time_items ... 90time_random code above the switch statement somewhere.

    Secondly after case:90: you have 6 closing braces }; ... if you used notepad++ features with syntax highlighting you would see that there is no matching opening braces for those. Each case: statement has an opening and closing and the entire switch block should have an opening and closing brace.

    Thirdly, as matt says, there is no addrandom command. Use this website to search for commands and how to use them https://community.bistudio.com/wiki/Category:ArmA:_Scripting_Commands
    It doesnt have ALL the used commands as it lacks the command you WANTED to use which is bis_fnc_selectrandom which is included in a separate file and not an integral sqf syntax which is why its not listed on that page. https://community.bistudio.com/wiki/BIS_fnc_selectRandom and here is a list of some more commands where that one is listed https://community.bistudio.com/wiki/Category:See_also_needed

    So what you want to do in your reward code is this:
    1. select a random reward
    2. optionally check to make sure they dont have the item already
    3. apply it to the player
    So you have your array of item arrays in 30time_random. The result is something like this and you cant select one item randomly because it will return an array (item one is food, item two is buildables) ... you want a SINGLE item.
    Code:
    30time_random = [["FoodNutmix","FoodPistachio"],["forest_large_net_kit","cinder_garage_kit",["PartPlywoodPack",5]]]
    Instead of doing that, simply ADD the contents of each array to a variable which will give you a single array that includes all the items. For now stick with single items by removing the [planks, 5] because that will require more code, you can add that later when its working as-is.
    Code:
    30time_random = 30time_random + time_items + time_items_food;
    For now we will skip the check if they already have the item, but you will need that later because they will be ripped off if you say they get something and they didnt because they already had the item.
    So to select a random item from an array use this code And to give the item to the player. Matt also mentions the issue of giving item TYPES. Some need addweapon, some needs addmagazine so you either have to use code to determine the type or sort them into different groups.
    I like matts idea of putting a box on the ground and allow them to select an item although that would require code to prevent them from selecting multiple items.
    Code:
    _reward = 30time_random call bis_fnc_selectrandom;
    player addweapon _reward; 


    There you go, another step in the right direction.
     
    TylerHumor likes this.
  16. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    BTW ... I have stepped away from Dayz and the internet in general as its a huge time vampire and I have so little free time to spare. Think of it this way .. in dayz we use a weighted loot table where some items are given more importance (trash, watch, flares) to be selected randomly while others are less likely (map, DMR) . To apply the same type of code to my Real-Life 'free time' select random code, it has looked like this ..
    Code:
    ["opendayz", "arma3", "family","internet porn","internet porn","internet porn","internet porn","internet porn","internet porn","internet porn"] call bis_fnc_selectrandom;
    
    I am attempting to change it to this
    Code:
    ["work", "kids","kids","wife","fixing my home", "showering","internet_porn"] call bis_fnc_selectrandom;
    
     
  17. Matt L

    Matt L OpenDayZ Rockstar!

    Joined:
    May 10, 2013
    Messages:
    841
    Likes Received:
    136
    I don't think I can like this post more than once, but goddamn I really wish I was able to.
     
  18. ShootingBlanks

    ShootingBlanks OpenDayZ Guru!

    Joined:
    Mar 31, 2013
    Messages:
    2,415
    Likes Received:
    336
    how about this for an idea thieving from the other games.
    at,the specified times, create a menu that has a list of maybe 5 items and they can select ONEwhich will remove the menu. a biplane will fly overhead and drop the item with a parachute for the player.. solves picking multiples, solves choosing, solves addweapon vs addmagazine ... and its cool
     
  19. Matt L

    Matt L OpenDayZ Rockstar!

    Joined:
    May 10, 2013
    Messages:
    841
    Likes Received:
    136
    I'm too lazy to do that shit, but feel free xD
     
  20. TylerHumor

    TylerHumor Member

    Joined:
    Jul 3, 2013
    Messages:
    94
    Likes Received:
    2
    That sounds really cool. I'd love to see that. Also, thank you for the responses.
     

Share This Page