Raised This Month: $51 Target: $400
 12% 

Saving scores after sv_restart 1?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 12-23-2018 , 05:52   Saving scores after sv_restart 1?
Reply With Quote #1

I'm working on a PUG plugin for my custom server and I was wondering how would one go around and actually save each player's individual score and set it back upon the second half's start.
Let's just say it's 14-0, the players that are losing won the round, it's 14-1 its the 15th round, normally I do a sv_restart 1 after I change the players' teams.

How do I save each player's score on the round end of the 14th round and set it back on the 15th? To each player individually, I think it should be possible but then again I'm no experienced coder - especially in the HL/AMXX domain.

I tried some dumb stuff with this piece of "code" (I'm really really sorry if I cause some headache with this indentation)

PHP Code:
new players[32], frags[33], deaths[33], num;
    
get_playersplayersnum );
        if(
roundnumber<<15)
        {
          for (new 
inumi++)
          {
          
frags=get_user_frags(players[i])
          
deaths=cs_get_user_deaths(players[i])
          }
        }
        if(
roundnumber==15)
        {
          for (new 
inumi++)
          {
          
set_user_frags(players[i], frags)
          
cs_set_user_deaths(players[i], deaths)
          }
        } 
Not sure why it doesn't work though, tried to do it in other ways as well but they ended up being so stupid I was too shy to post the src here.
I don't want to be spoon-fed I just want some insight - is it even possible?
Sorry - I'm just dumb.

I've seen this concept originally in CS_PugMod source code on github, I did not copy + paste it, I just tried to copy the concept, I'm not even sure if what I did was right in the first place.

Last edited by deprale; 12-23-2018 at 05:57.
deprale is offline
shauli
Member
Join Date: Jun 2018
Old 12-23-2018 , 09:52   Re: Saving scores after sv_restart 1?
Reply With Quote #2

Quote:
Originally Posted by deprale View Post
I don't want to be spoon-fed I just want some insight - is it even possible?
That's an important sentence that will surely get you more help, it's nice to hear.
And yes, it's possible.

Basically there are major 2 problems here:

1. You've created the variables "frags" and "deaths" as an arrays, which is fine, but you didn't use them like you should.

In this line for example:
PHP Code:
frags=get_user_frags(players[i]) 
You haven't specified which element in the array you want to change. It should be like this:
PHP Code:
frags[players[i]] = get_user_frags(players[i]) 
2. Your arrays, "frags" and "deaths", will be deleted from memory each time the function ends. So when a new round will begin "frags" and "deaths" will be 0 and not the values you set.
There are 2 methods of solving this: using static variables, or using global variables.

Also there's a potential bug that one player will disconnect and another player will get his ID and his frags/deaths. Rare, but possible.

BTW, roundnumber<<15 should be roundnumber<15.
shauli is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 12-23-2018 , 09:56   Re: Saving scores after sv_restart 1?
Reply With Quote #3

Quote:
Originally Posted by shauli View Post
That's an important sentence that will surely get you more help, it's nice to hear.
And yes, it's possible.

Basically there are major 2 problems here:

1. You've created the variables "frags" and "deaths" as an arrays, which is fine, but you didn't use them like you should.

In this line for example:
PHP Code:
frags=get_user_frags(players[i]) 
You haven't specified which element in the array you want to change. It should be like this:
PHP Code:
frags[players[i]] = get_user_frags(players[i]) 
2. Your arrays, "frags" and "deaths", will be deleted from memory each time the function ends. So when a new round will begin "frags" and "deaths" will be 0 and not the values you set.
There are 2 methods of solving this: using static variables, or using global variables.

Also there's a potential bug that one player will disconnect and another player will get his ID and his frags/deaths. Rare, but possible.

BTW, roundnumber<<15 should be roundnumber<15.
Appreciate your input, lots of gratitude sir, I'll look more into that.
Very clear explanation and lots of tips, thank you!!! Really, couldn't have asked for more!


EDIT: Just succeeded, using static arrays I managed to get the deaths just fine, now onto fixing the frags issue

Last edited by deprale; 12-23-2018 at 09:58.
deprale is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-23-2018 , 12:46   Re: Saving scores after sv_restart 1?
Reply With Quote #4

I would change this since you only care about the data in round 14, right? Doing the same thing for rounds 1 to 13 is a waste.
PHP Code:
if(roundnumber<<15)

to

if ( roundnumber == 14 
__________________

Last edited by Bugsy; 12-23-2018 at 13:31.
Bugsy is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 12-24-2018 , 01:03   Re: Saving scores after sv_restart 1?
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
I would change this since you only care about the data in round 14, right? Doing the same thing for rounds 1 to 13 is a waste.
PHP Code:
if(roundnumber<<15)

to

if ( roundnumber == 14 
That's also a great idea Bugsy, but I was also thinking, what if somebody disconnects and reconnects at round 5?
I'm trying to create a PUG mod that upon reconnecting ON THE SAME MAP won't reset your score(because in 2018 there are certain persons that still care about their scores and abuse the +800$ +lost round$)

I still don't have a PoC of this idea, but I was thinking about saving player name's for arrays and checking if the array has the same name as the player then assigning that as his user frags/deaths upon reconnecting on the same map. Not even sure if it's possible because I haven't tried it yet.

I check it every round just in case someone disconnects/reconnects in-between the rounds.
deprale is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-24-2018 , 11:14   Re: Saving scores after sv_restart 1?
Reply With Quote #6

I think you should save the data outside of variables, such as in nVault. Storing data in variables is only good for that single connection to the server. Once they disconnect, another player could connect on that same slot so you can never assume it's the same player.

Store the data in nVault, using the steam ID as the key. The logic is pretty simple to do this. Use nVault Array, create an enumerator to organize the data to be stored, on player authorized, retrieve the data. When he disconnects, save the data. There is an example of this in the include thread.

If you want to only save/restore data for a round, you can call nvault_prune() at round start which would wipe out any existing data, leaving it fresh for the round that is about to take place.

I do not know anything about this mod so I cannot provide much more input.
__________________

Last edited by Bugsy; 12-24-2018 at 17:59.
Bugsy is offline
deprale
Senior Member
Join Date: Oct 2018
Location: Leeds
Old 01-04-2019 , 19:35   Re: Saving scores after sv_restart 1?
Reply With Quote #7

Thanks bugsy, sorry for the VERY late reply.

Unfortunately I haven't had enough time to learn how to do that but I will make sure to try it out these days ;)
deprale is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:27.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode