String checking and passing help
#1

i was makeing a anti repeat system
so that a player can say the same line twice and not more than that in every 5 seconds
i know that i have done some basic things worng even the declaration but it was done to do things
i am not good regards to wroking with string so maybe you guys can help me
codes:
pawn Код:
new sstring[MAX_PLAYERS][128],stoped[MAX_PLAYERS],muted[MAX_PLAYERS];
public OnPlayerText(playerid, text[])
{
if((stoped[playerid])<2&&(muted[playerid])==0)
{
  if(strval(text) == ContestAnswer && ContestAnswer != -1) // Checks if the text the player has typed is equal to the Contest Answer, but isn't -1.
  {
    OnPlayerWinContest(playerid); // This'll direct the script to the OnPlayerWinContest callback.
  }
  if(strcmp(sstring[playerid][],text,true,sizeof((text)))!=0){
  strmid(sstring, text, 0,(sizeof(text)-1)); //sstring[playerid]=text[sizeof(text)];
  stoped=0;
  }
  else{
  stoped++;
  SendClientMessage(playerid,COLOR_ERROR,"Plese Dont Repeat your self again and again.");
    }
  }
  else if(stoped[playerid]>1)
  {
  SetTimer("Unmute(playerid)",5000,0);
  }
  else if(muted[playerid]==1)
  {
  SetTimer("Unmute(playerid)",60000,0);
  }
    return 1;
}
public Unmute(playerid)
{
if(stoped[playerid]>2)
{
stoped--;
}else if(muted[playerid]){
muted =0;
}
return 1;
}
errors:
pawn Код:
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(5397) : error 029: invalid expression, assumed zero
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(5397) : warning 224: indeterminate array size in "sizeof" expression (symbol "")
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(5398) : error 048: array dimensions do not match
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(5398) : warning 224: indeterminate array size in "sizeof" expression (symbol "")
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(5399) : error 033: array must be indexed (variable "stoped")
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(5402) : error 022: must be lvalue (non-constant)
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(5402) : warning 215: expression has no effect
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(5416) : warning 235: public function lacks forward declaration (symbol "Unmute")
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(5420) : error 022: must be lvalue (non-constant)
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(5420) : warning 215: expression has no effect
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(5423) : warning 209: function "Unmute" should return a value
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(6568) : warning 203: symbol is never used: "Timer"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


5 Errors.
Reply
#2

Here is what I would do.

pawn Код:
#define REPEAT_DELAY 5000
#define REPEAT_AMOUNT 2

new LastText[MAX_PLAYERS][128];
new LastTextTime[MAX_PLAYERS];
new TextRepeats[MAX_PLAYERS];

stock CheckRepeatText(playerid, text[])
{
    if(GetTickCount() - LastTextTime[playerid] < REPEAT_DELAY)
    {
        if(!strcmp(text, LastText[playerid])) TextRepeats[playerid]++;
        if(TextRepeats[playerid] == REPEAT_AMOUNT)
        {
            // Run mute code here
        }
    }
    else
    {
        TextRepeats[playerid] = 1;
        LastTextTime[playerid] = GetTickCount();
     }
    LastText[playerid] = text;
    return 1;
}
Pretty sure I got that right test it out and let me know I might have to expand it bit and save multiple lines and check them but in that case your anti-spam should kick in anyways.
Reply
#3

pawn Код:
G:\C\samp03x_svr_R1-2_win32\gamemodes\now.pwn(6573) : error 047: array sizes do not match, or destination array is too small
called the function to on player text with

pawn Код:
CheckRepeatText(playerid, text)//just to show i am doing it right
Reply
#4

stock CheckRepeatText(playerid, text[128])

try it like that
Reply
#5

hear carefully maybe you are going to learn something new today
first of all thx for giveing me those codes which i know are much faster than my old school timer once and now
i always knew string values/all the characters in an array cant be tranferred like this
pawn Код:
Array[..]=Array[..];
if they both are 2d arrays so it could be each of there sub stream holds 128 characters so a single = wont work
people use loops for them or compiler always gives some fucntions for it like we have   strmid to transfer string values
i know you are not a n00b and you will search it and find more about it
and the main thing the error we are getting is due to if the player posts or chats a string of more than 128 characters and our things resources only allowed it to 128 characters so what i did is
i made a new global string Text[MAX_PLAYERS][128];
and inside the on player text i took the text value and stored it in Text Sting with strid
and at last where we wanted to store
pawn Код:
LastText[playerid] = text;
i used the same thing and now it works just while passing the function
pawn Код:
CheckRepeatText(playerid, text[128])
chage it to
pawn Код:
CheckRepeatText(playerid, Text)
thats diffrent its a lot slow but maybe i got a new project :P
and thx again. +rep
EDIT:You must spread some Reputation around before giving it to [uL]Pottus again.
lol i gave you rep many time when you helped n00bs and they didnt gave you rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)