Author Topic: Forgot pawn scriptin :S  (Read 4003 times)

0 Members and 1 Guest are viewing this topic.

yazeen

  • Guest
Forgot pawn scriptin :S
« on: October 05, 2011, 09:46:45 am »
i forgot pawn scripting since i havent scipted for months well i know you guys have nothing to do about that. i will keep posting my doubts in this page instead of flooding forum with these kinda topics.

1)
[pawn]new Invalid = "%,#,@,!,%,^,&,*,-,+,:,\,|,- "
new nick[17]; GetPlayerName(playerid,nick,17);
if((strcmp(nick,Invalid)) kick(playerid)[/pawn]

i need kick all players whos nic contains invalid characters like those.

yazeen

  • Guest
Re: Forgot pawn scriptin :S
« Reply #1 on: October 05, 2011, 01:30:52 pm »
Where are the pros when we need them?

Offline heekz.shadow

  • LU testers
  • Made Man
  • *
  • Posts: 249
    • View Profile
Re: Forgot pawn scriptin :S
« Reply #2 on: October 05, 2011, 07:24:12 pm »
I will show you the long way D:.

just a think of mine  ::)


[pawn]new nick[2]; GetPlayerName(playerid,nick,2);
if((strcmp(nick) == "!") || (strcmp(nick) == "#") || (strcmp(nick) == "/") || (strcmp(nick) == "\") || (strcmp(nick) == "!") || (strcmp(nick) == "@")))
{
Kick(playerid);
}
else
{
break;
}[/pawn]

Code: [Select]
[20:23] <habi> later only i heard that lu chatbox is customizable. On my first visit, it appeared ugly.
[20:23] <habi> May be that also be the reason why lu has no players

Offline stormeus

  • VC:MP Developer
  • VC:MP Veteran
  • *
  • Posts: 1122
    • View Profile
Re: Forgot pawn scriptin :S
« Reply #3 on: October 05, 2011, 10:13:35 pm »
[pawn]strcmp(nick) == "!")[/pawn]
[pawn]break;[/pawn]

wat.

That code should look more like this:
[pawn]
// Make room for their name
new nick[2];

// Get their name in the variable "nick"
GetPlayerName(playerid, nick, 2);

// See if their name has invalid characters
if(strcmp(nick, "!", false) == 0 || strcmp(nick, "#", true) == 0 || strcmp(nick, "/", true) == 0 || strcmp(nick, "\\", true) == 0 || strcmp(nick, "@", true) == 0)
{
    // Kicks the player
    Kick(playerid);

    // Stops the function
    return false;
}
[/pawn]

First off the bat, here's what strcmp should look like:

strcmp( string1, string2, caseInsensitive, [length] )
string1 - A string to compare
string2 - Another string to compare
caseInsensitive - If true, doesn't check letter casing (uppercase/lowercase).
length - OPTIONAL; only compares strings up to the given length.

Secondly, break is only for for, while, and switch blocks. Anything else is wrong.

Lastly, you're kicking the player. Unless you have anything else to do, you need to return; something so the function doesn't do anything else.

EDIT: Also, \ is an escape character. You need to escape that too, so it looks like \\.
« Last Edit: October 05, 2011, 10:15:39 pm by stormeus »
Do not PM me for support.




yazeen

  • Guest
Re: Forgot pawn scriptin :S
« Reply #4 on: October 06, 2011, 03:03:03 pm »
Wanted to know what is these stuff used in C++
[pawn]throw,  catch(e) [/pawn]

and is there more stuff like this which can be used in pawno? can you give me a list (no need of if, else if, for , each etc.. kinda all time used stuff)

Offline tato

  • Made Man
  • ***
  • Posts: 106
  • I bet u don't know me!
    • View Profile
    • EA Server
Re: Forgot pawn scriptin :S
« Reply #5 on: October 07, 2011, 03:13:36 am »
[pawn]public OnPlayerConnect(playerid)
{
NickPlayerChar(playerid);

   return 1;
}[/pawn]


[pawn]stock IsNumeric(string[]) { for (new i = 0, j = strlen(string); i < j; i++) if (string > '9' || string < '0') return 0; return 1; }

//==============================================================================
public NickPlayerChar(playerid)
{
    if(IsInvalidChar(PlayerName(playerid))) {
      new MSN[256];
      format(MSN,256,">> Server Auto-Kick: %s, Reason:[ Invalid Nick ].", PlayerName(playerid));
      SendClientMessageToAll(BLUE,MSN);
      Kick(playerid);
   }
}
//==============================================================================
public IsInvalidChar(c[])
{
   if (strfind(c, "%", true) != -1 || strfind(c, "*", true) != -1 ||
       strfind(c, "#", true) != -1 || strfind(c, "-", true) != -1 ||
       strfind(c, "@", true) != -1 || strfind(c, "+", true) != -1 ||
       strfind(c, "!", true) != -1 || strfind(c, ":", true) != -1 ||
      strfind(c, "^", true) != -1 || strfind(c, "\", true) != -1 ||     
      strfind(c, "&", true) != -1 || strfind(c, "|", true) != -1)
       return 1;
   if (IsNumeric(c)) return 1;
        else return 0;
    return 1;
}
//==============================================================================
public PlayerName(playerid)
{
    new name[24];
   GetPlayerName(playerid,name,24);
   return name;
}
//==============================================================================
[/pawn]


i don't remember so well if i forget something tell me and i add it okay im in my cellphone and i'ts to hard to copy all that ._. from my old script

yazeen

  • Guest
Re: Forgot pawn scriptin :S
« Reply #6 on: October 07, 2011, 07:54:22 am »
Thanks anyway tato but tat problem is already solved :P the question is the last post above me
btw i could take it from madara's warchiefs :P

Offline tato

  • Made Man
  • ***
  • Posts: 106
  • I bet u don't know me!
    • View Profile
    • EA Server
Re: Forgot pawn scriptin :S
« Reply #7 on: October 07, 2011, 08:56:39 am »
Thanks anyway tato but tat problem is already solved :P the question is the last post above me
btw i could take it from madara's warchiefs :P
aight your welcome

Offline Morphine

  • Made Man
  • ***
  • Posts: 109
    • View Profile
Re: Forgot pawn scriptin :S
« Reply #8 on: October 07, 2011, 11:03:25 am »
catch and throw implement Exception Handling.

Code: [Select]
try {
   // code that could throw an exception
}
[ catch (exception-declaration) {
   // code that executes when exception-declaration is thrown
   // in the try block
}
[catch (exception-declaration) {
   // code that handles another exception type
} ] . . . ]
// The following syntax shows a throw expression:
throw [expression]

These exceptions are handled by code which is outside the normal flow of control.

A quick example off the Microsoft site:

Code: [Select]
// exceptions_trycatchandthrowstatements.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;
int main() {
   char *buf;
   try {
      buf = new char[512];
      if( buf == 0 )
         throw "Memory allocation failure!";
   }
   catch( char * str ) {
      cout << "Exception raised: " << str << '\n';
   }
}

In simplest to me words, try, catch and/or throw help against any anomalous activity that might happen outside of what you can control in your program.