Jump to content
HollowAddiction

[WIP] Player Voting for Night/Day

Recommended Posts

Players can right-click on a specified item(We used a briefcase) and vote for day or night, and it consumes the item. If enough players vote it will broadcast a warning that the vote has been cast and it will become day/night with a countdown of 5 mins.

We have done some of the coding but have run into issues with the script. below is a download of what we have, anyone who helps will be credited. Thanks

 

 

Download:

http://craftdoge.com/downloads/wip.html

Share this post


Link to post
Share on other sites

This sounds great, but I see a problem of where, from what I know of is that the mission file cant manually set the time of the server with out it reverting back to the time it was at previously, This would have to be somehow implemented through either a dll file or dare I say it.. The Server.pbo

Share this post


Link to post
Share on other sites

You would need a script running server side to count the votes and implement the change

 

_votenight= 0;

_voteday= 0;

 

if (_txt in ['!votenight']) then _votenight = _votenight+ 1;

if (_txt in ['!voteday']) then _voteday = _voteday+ 1;

 

if (_votenight> 10) then

if (_voteday> 10) then

 

Problems I can see is it can't differentiate between different players voting, so 1 player could spam the votes to get night/day

Share this post


Link to post
Share on other sites

You would need a script running server side to count the votes and implement the change

 

_votenight= 0;

_voteday= 0;

 

if (_txt in ['!votenight']) then _votenight = _votenight+ 1;

if (_txt in ['!voteday']) then _voteday = _voteday+ 1;

 

if (_votenight> 10) then

if (_voteday> 10) then

 

Problems I can see is it can't differentiate between different players voting, so 1 player could spam the votes to get night/day

we've done the above, also its set to not differentiate so we can test. the issue we have is the actual function of voting and it initiating the script

Share this post


Link to post
Share on other sites

hmm i think i found an error..

 

private ["_day_votes","_night_votes","_time","_vote","_day","_night"];
_vote = _this select 1;
_day_votes = 0;
_night_votes = 0;
_time = 30;

if (_vote == 1) then {
    _day_votes = _day_votes + 1;
};

if (_vote == 2) then{
    _night_votes = _night_votes + 1;
};
    
while {true} do {
    _day = _day_votes;
    _night = _night_votes;
    
    [] spawn {
        waitUntil {_day > 5};
            set_day = [player,date,11];
            publicVariableServer "set_day"; //Send needed values to server.
            set_day = [];
    };
    
    [] spawn {
        waitUntil {_night > 5};
            set_night = [player,date,21];
            publicVariableServer "set_day"; //Send needed values to server.
            set_night = [];
    };
    
    sleep _time;
};

i think it should send the variable set_night to server instead of set_day .

Share this post


Link to post
Share on other sites

Why worry about the UID? Just make the item a full briefcase :) If someone wants to blow 5 briefcases so he can take a stroll in the moonlight, who are we to stop him? lol

 

/cash

Share this post


Link to post
Share on other sites

Why worry about the UID? Just make the item a full briefcase :) If someone wants to blow 5 briefcases so he can take a stroll in the moonlight, who are we to stop him? lol

 

/cash

well because different servers run different currencies, for instance on my server a briefcase is the equivalence of a gold bar 

Share this post


Link to post
Share on other sites

It's a bad idea to use something that is intended as an item-context action as a global-context action. That's what addAction is used for -- if it's your preference, that's fair enough, but this is easier to perform by having a custom dialogue or an addAction. I would recommend that the easiest thing to do to debug it is to check your RPT, consult with the BIstudio community wiki, and ARMAholic to query any errors you encounter. If you're unsure, the wiki and google is your friend. :lol:

Share this post


Link to post
Share on other sites

It's a bad idea to use something that is intended as an item-context action as a global-context action. That's what addAction is used for -- if it's your preference, that's fair enough, but this is easier to perform by having a custom dialogue or an addAction. I would recommend that the easiest thing to do to debug it is to check your RPT, consult with the BIstudio community wiki, and ARMAholic to query any errors you encounter. If you're unsure, the wiki and google is your friend. :lol:

Thats a good point, We just wanted to not clutter up the scrollwheel options anymore then we already have but i agree. thanks

 

We have been checking for errors, but it's not showing any. We have pretty much hit a brick wall.

Share this post


Link to post
Share on other sites

Thats a good point, We just wanted to not clutter up the scrollwheel options anymore then we already have but i agree. thanks

 

We have been checking for errors, but it's not showing any. We have pretty much hit a brick wall.

 

Some quick information you may find useful to know:

//voteloop.sqf
private ["_day_votes","_night_votes","_time","_vote","_day","_night"];

The variables you use to track how many votes are temporary variables (which are prefixed with _). You need to replace these with permanent variables without the _.

 

Here's an example of how you could accomplish what you're looking for.

// My Handler

"_my_var" addPublicVariableEventHandler {
 // Call a function to check the value of the permanent variable on the server

_voteResult = _this select 0;

[] call MyFunctionForCheckingPermanentVariable

// And so on and so on..
};
// HowManyDayNight.sqf

//When the server loads this, it will set this to 0
MY_PROGRAM_DAY_VOTES = 0;

MY_PROGRAM_NIGHT_VOTES = 0;

My_Function_Add_Day_Votes ={
 private["_voteType"];

_voteType = _this select 0;

// Suppose some cheeky other program has the same name as our permanent variable, we always set it to a value we want if it's not how we expect it.
if(typeName MY_PROGRAM_DAY_VOTES != "SCALAR") then
{
 MY_PROGRAM_DAY_VOTES = 0;
};
// Same as above
if(typeName MY_PROGRAM_NIGHT_VOTES != "SCALAR") then
{
 MY_PROGRAM_NIGHT_VOTES = 0;
};


if(_voteType == "DAY") then
{
 MY_PROGRAM_DAY_VOTES = MY_PROGRAM_DAY_VOTES + 1;
}
else
{
MY_PROGRAM_NIGHT_VOTES = MY_PROGRAM_NIGHT_VOTES +1;
};
};

You need to have the folllowing things to make it work:

  • On the client side, have the user submit their client UID and their vote. You need the Client UID because you want to prevent them from voting twice.
  • On the server side, you need to have an array which stores the person's UID in a permanent variable along with their vote. I.e. [123456789,"DAY"] -- this allows you to have persistence of who is voting, and write functions to find out who has voted.
  • On the server side you need to have the array counted and then when it hits a threshold, execute another function or code which changes to day/night.

So for instance:

// My Server script

MY_VOTES = [];

My_Program_Add_Vote ={
 private ["_voteType","_personsUID"];

_voteType = _this select 0;
_personsUID = _this select 1;

// What if they're cheeky and change the vote type to "BAH" ? Or there is an error? etc. 
 if (!_voteType in ["DAY","NIGHT"]) then
{
  // Do some more checking.. (i.e. Are they already in this list?)
 
 // Now add the person to the list..
 MY_VOTES set[(count MY_VOTES),[_personsUID,_voteType]];

/*
* MY_VOTES now looks like:
MY_VOTES [
 [1234567,"DAY"]
]
*/
};

};

Keep going, you'll get there.

 



Share this post


Link to post
Share on other sites

Some quick information you may find useful to know:

//voteloop.sqf
private ["_day_votes","_night_votes","_time","_vote","_day","_night"];

The variables you use to track how many votes are temporary variables (which are prefixed with _). You need to replace these with permanent variables without the _.

 

Here's an example of how you could accomplish what you're looking for.

// My Handler

"_my_var" addPublicVariableEventHandler {
 // Call a function to check the value of the permanent variable on the server

_voteResult = _this select 0;

[] call MyFunctionForCheckingPermanentVariable

// And so on and so on..
};
// HowManyDayNight.sqf

//When the server loads this, it will set this to 0
MY_PROGRAM_DAY_VOTES = 0;

MY_PROGRAM_NIGHT_VOTES = 0;

My_Function_Add_Day_Votes ={
 private["_voteType"];

_voteType = _this select 0;

// Suppose some cheeky other program has the same name as our permanent variable, we always set it to a value we want if it's not how we expect it.
if(typeName MY_PROGRAM_DAY_VOTES != "SCALAR") then
{
 MY_PROGRAM_DAY_VOTES = 0;
};
// Same as above
if(typeName MY_PROGRAM_NIGHT_VOTES != "SCALAR") then
{
 MY_PROGRAM_NIGHT_VOTES = 0;
};


if(_voteType == "DAY") then
{
 MY_PROGRAM_DAY_VOTES = MY_PROGRAM_DAY_VOTES + 1;
}
else
{
MY_PROGRAM_NIGHT_VOTES = MY_PROGRAM_NIGHT_VOTES +1;
};
};

You need to have the folllowing things to make it work:

  • On the client side, have the user submit their client UID and their vote. You need the Client UID because you want to prevent them from voting twice.
  • On the server side, you need to have an array which stores the person's UID in a permanent variable along with their vote. I.e. [123456789,"DAY"] -- this allows you to have persistence of who is voting, and write functions to find out who has voted.
  • On the server side you need to have the array counted and then when it hits a threshold, execute another function or code which changes to day/night.

So for instance:

// My Server script

MY_VOTES = [];

My_Program_Add_Vote ={
 private ["_voteType","_personsUID"];

_voteType = _this select 0;
_personsUID = _this select 1;

// What if they're cheeky and change the vote type to "BAH" ? Or there is an error? etc. 
 if (!_voteType in ["DAY","NIGHT"]) then
{
  // Do some more checking.. (i.e. Are they already in this list?)
 
 // Now add the person to the list..
 MY_VOTES set[(count MY_VOTES),[_personsUID,_voteType]];

/*
* MY_VOTES now looks like:
MY_VOTES [
 [1234567,"DAY"]
]
*/
};

};

Keep going, you'll get there.

 



 

Finally some help! Cheers mate

Share this post


Link to post
Share on other sites

Well unfortunately My knowledge on writing scripts is horribly limited and the other person working on it has decided to stop. So sad to say we are abandoning the project. If anyone wants to pick it up feel free.

 

Don't give up! :) Your knowledge doesn't get less limited by stopping. :D

 

I was planning on including voting in general in FairServer, anyway, so if you want to help on that, you're more than welcome, but either way, keep going ^_^

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Similar Content

    • By DirtySanchez
      Now use the Epoch Config to setup a perfect nighttime
      https://github.com/EpochModTeam/Epoch/blob/release/Sources/epoch_config/Configs/CfgEpochClient.hpp#L62
      Use this:
      niteLight[] = {1,666,10000};
      The 666 is a very nice and bright night
      420 is moderate nights and should be the goto brightness here
      300 is dark enough to call hardcore but still playable af





      Old Info using color corrections:

      Yes guys this is not too hard to accomplish
      Steps:
      1. Find your moonlit night and time for server start
      2. Play around with some corrections
      3. start your server
      Answers ye all seek:
      1. In your epochconfig.hpp change this line
      StaticDateTime[] = {2035,6,10,21,30}; 2. call this corrections.sqf from your init.sqf
      []execVM "corrections.sqf"; Save this code as corrections.sqf and put it in your mission folder.
      "ColorCorrections" ppEffectEnable true;"ColorCorrections" ppEffectAdjust [0.88, 0.88, 0.04, [0.2, 0.29, 0.4, -0.22], [1, 1, 1, 1.3], [0.15, 0.09, 0.09, 0.0]];"ColorCorrections" ppEffectCommit 0; 3. FUCKING ENJOY!
      Update: play around with the 0.04 setting for gamma changes. 0.06 is perfect for an all night server. 0.04 was tested on day and night and was not too washed out during the daytime.
    • By Alkeriece
      i just started up a server for friends but the server seems to be locked on day and as much as i've looked i cant find the string that lets me enable day/night cycling.
      if anyone wouldn't mind sharing the location of this that would be awesome.
  • Advertisement
  • Supporters
  • Discord

×
×
  • Create New...