Raised This Month: $ Target: $400
 0% 

[Solved] Save


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 05-18-2009 , 12:58   [Solved] Save
Reply With Quote #1

[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?
__________________
Achievements API - a simple way for you to create your OWN custom achievements!

Last edited by Xellath; 05-18-2009 at 15:02.
Xellath is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-18-2009 , 13:06   Re: Save
Reply With Quote #2

Change

PHP Code:
  last_save[id] = 

To

PHP Code:
  last_save[id] = current_time 
__________________
joaquimandrade is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 05-18-2009 , 13:21   Re: Save
Reply With Quote #3

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;

__________________
Achievements API - a simple way for you to create your OWN custom achievements!

Last edited by Xellath; 05-18-2009 at 13:39.
Xellath is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-18-2009 , 13:58   Re: Save
Reply With Quote #4

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
__________________
joaquimandrade 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 01:25.


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