AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved] Save (https://forums.alliedmods.net/showthread.php?t=92707)

Xellath 05-18-2009 12:58

[Solved] Save
 
[Solved]

PHP Code:

public Save(id)
{
 if(
get_pcvar_num(g_pSaveXP) == 0)
 {
  return 
PLUGIN_HANDLED;
 }
 else
 {
  new 
Float:time_left;
  new 
Float:current_time;
 
  
current_time get_gametime();
  
time_left current_time last_save[id];
 
  if(
time_left SAVE_SPAM)
  {
   
client_print(idprint_chat"[%s] You must wait %0.1f seconds before saving again."PLUGIN_TAGSAVE_SPAM-time_left);
   return 
false;
  }
  else
  {
   
SaveData(id);
   
client_print(idprint_chat"[%s] Your points was saved."PLUGIN_TAG)
   
last_save[id] = 1
   
return true;
  }  
 }
 return 
false;


I made a function, as you see above.. to save a player points..
But when the time runs out.. the 60 secs that is defined with SAVE_SPAM, the player can spam save, which will result in lag.

How can I fix this?

joaquimandrade 05-18-2009 13:06

Re: Save
 
Change

PHP Code:

  last_save[id] = 


To

PHP Code:

  last_save[id] = current_time 


Xellath 05-18-2009 13:21

Re: Save
 
And that gives me a tag mismatch?

EDIT:

Can I do something like this?

PHP Code:

public Save(id)
{
 if(
get_pcvar_num(g_pSaveXP) == 0)
 {
  return 
PLUGIN_HANDLED;
 }
 else
 {
  if(
last_save[id] == 0)
  {
   
SaveData(id);
   
client_print(idprint_chat"[%s] Your points was saved."PLUGIN_TAG)
   
last_save[id] = 1
  
}
  else if(
last_save[id] == 1)
  {
   new 
Float:time_left;
   new 
Float:current_time;
   
   
current_time get_gametime();
   
time_left current_time
   
   
if(time_left SAVE_SPAM)
   {
    
client_print(idprint_chat"[%s] You must wait %0.1f seconds before saving again."PLUGIN_TAGSAVE_SPAM-time_left);
    return 
false;
   }
   else
   {
    
last_save[id] = 0
   
}
  }
 }
 return 
false;



joaquimandrade 05-18-2009 13:58

Re: Save
 
If you want a spam protection depending on time, you have to save the time in a global variable. Since you are not doing that in the above's code it won't work as you want it to.

About the tag mismatch:

PHP Code:

Float:last_save[33



All times are GMT -4. The time now is 01:25.

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