Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: Fjose on Oct 21, 2014, 03:16 AM

Title: Team System v1.0.2
Post by: Fjose on Oct 21, 2014, 03:16 AM
Player Team System

Functions:
Class PlayerInfo {
Team = false;
Request = false;
TimeRequest = 0;
Partner = null;
}

function onScriptLoad()
{
    pinfo <- array( GetMaxPlayers(), null );
}

function onPlayerJoin( player )
{
    pinfo[ player.ID ] = PlayerInfo();
}

function onPlayerSpawn( player )
{
if ( pinfo[ player.ID ].Team == true )
{
local plr = FindPlayer( pinfo[ player.ID ].Partner );
if ( plr ) player.Pos = plr.Pos;
}
}

function onPlayerPart( player, reason )
{
if ( pinfo[ player.ID ].Team == true )
{
local plr = FindPlayer( pinfo[ player.ID ].Partner );
if ( plr ) {
PrivMessage( plr, "[!] " + player.Name + " left the team." );
pinfo[ plr.ID ].Partner = null;
pinfo[ plr.ID ].Team = false;
}
}
pinfo[ player.ID ] = null;
}

function onPlayerSpawn( player )
{
 if ( pinfo[ player.ID ].Team == true )
 {
  local plr = FindPlayer( pinfo[ player.ID ].Partner );
  if ( plr ) player.Pos = plr.Pos;
 }
}

GetTok and NumTok: there are two versions. use whatever you want.
// Version no.1
function GetTok(string, separator, n, ...)
{
local m = vargv.len() > 0 ? vargv[0] : n,
  tokenized = split(string, separator),
  text = "";

if (n > tokenized.len() || n < 1) return null;
for (; n <= m; n++)
{
text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
}
return text;
}

function NumTok(string, separator)
{
local tokenized = split(string, separator);
return tokenized.len();
}

// Version no.2
function GetTok(str, sep, pos, len = null)
{
 if (typeof str != "string" || str.len() < 1) return "";
 else if (typeof sep != "string" || sep.len() < 1) return "";
 local tok = split(str, sep);
 if (typeof tok != "array") return str;
 else if (tok.len() == 1 && tok[0] == str) return tok[0];
 if (typeof pos != "integer")
 {
  if (typeof pos == "float" || typeof pos == "string") pos = pos.tointeger();
  else return "";
 }
 if (pos >= tok.len()) return "";
 else if (pos < 0) pos = 0;
 if (len == null)
  len = (tok.len() - pos);
 else if (typeof len != "integer")
 {
  if (typeof len == "float" || typeof len == "string") len = len.tointeger();
  else return "";
 }
 if ((pos+len) > tok.len()) len = (tok.len() - pos);
 else if (len <= 0) return "";
 tok = tok.slice(pos, pos+len);
 if (tok.len() > 1)
 {
  local res = tok[0];
  tok.remove(0);
  foreach (tk in tok) res += sep + tk;
  return res;
 }
 else if (tok.len() == 1) return tok[0];
 else return "";
}

function NumTok(str, sep)
{
 if (typeof str != "string" || str.len() < 1) return 0;
 else if (typeof sep != "string" || sep.len() < 1) return 0;
 local tok = split(str, sep);
 if (typeof tok != "array") return 0;
 else if (tok.len() == 1 && tok[0] == str) return 0;
 else return tok.len();
}

Commands:
function onPlayerCommand( player, cmd, text )
{
    local plr, i = 0;
if ( text ) {
plr = FindPlayer( text );
i = NumTok(text, " ").tointeger();
}

    if ( cmd == "team" )
    {
local plr = FindPlayer( GetTok( text, " ", 1 ) );
if ( pinfo[ player.ID ].Team == true ) PrivMessage( player, "[Error] You already have a team." );
else if ( !text ) PrivMessage( player, "Syntax: /team <player name or id>" );
else if ( !plr ) PrivMessage( player, "[Error] Unknown player." );
else if ( pinfo[ plr.ID ].Team == true ) PrivMessage( player, "[Error] " + plr.Name + " is already in a team." );
else if ( pinfo[ player.ID ].Request == true ) PrivMessage( player, "[Error] You already have a request." );
else if ( pinfo[ plr.ID ].Request == true ) PrivMessage( player, "[Error] " + plr.Name + " already have a request." );
else
{
if ( pinfo[ player.ID ].TimeRequest < time() ) {
pinfo[ player.ID ].Request = false; pinfo[ player.ID ].Partner = null;  pinfo[ player.ID ].TimeRequest = 0;
pinfo[ plr.ID ].Request = false; pinfo[ plr.ID ].Partner = null; pinfo[ plr.ID ].TimeRequest = 0;
}
   
PrivMessage( plr, "[!] " + player.Name + " would like to team up with you." );
PrivMessage( player, "Request submitted." );
pinfo[ player.ID ].Partner = plr;
pinfo[ plr.ID ].Partner = player;
pinfo[ player.ID ].TimeRequest = time() + 30;
pinfo[ plr.ID ].TimeRequest = time() + 30;
pinfo[ plr.ID ].Request = true;
pinfo[ player.ID ].Request = true;
}
}
 
else if ( cmd == "accept" )
{
local plr = FindPlayer( pinfo[ player.ID ].Partner );
if ( pinfo[ player.ID ].Request == false ) PrivMessage( player, "[Error] You don't have a request." );
else if ( pinfo[ player.ID ].Team == true ) PrivMessage( player, "[Error] You already have a team-mate." );
else
{
if ( pinfo[ player.ID ].TimeRequest < time() ) {
PrivMessage( player, "[Error] Time ended." );
pinfo[ player.ID ].Request = false;
pinfo[ player.ID ].Partner = null;
pinfo[ plr.ID ].Request = false;
pinfo[ plr.ID ].Partner = null;
pinfo[ player.ID ].TimeRequest = 0;
pinfo[ plr.ID ].TimeRequest = 0;
    } else {
   
PrivMessage( plr, "[!] " + player.Name + " is doing team with you." );
PrivMessage( player, "Request Accepted! You are now teaming with " + plr.Name );
pinfo[ player.ID ].Team = true;
pinfo[ plr.ID ].Team = true;
pinfo[ player.ID ].Request = false;
pinfo[ plr.ID ].Request = false;
pinfo[ player.ID ].TimeRequest = 0;
pinfo[ plr.ID ].TimeRequest = 0;
player.Pos = plr.Pos;
}
}
}
   
else if ( cmd == "deny" )
{
if ( pinfo[ player.ID ].Request == false ) PrivMessage( player, "[Error] You don't have a request." );
else
{
                   local plr = FindPlayer( pinfo[ player.ID ].Partner );
   if ( pinfo[ player.ID ].TimeRequest < time() ) {
PrivMessage( player, "[Error] Time ended." );
pinfo[ player.ID ].Request = false;
pinfo[ plr.ID ].Request = false;
pinfo[ player.ID ].Partner = null;
pinfo[ plr.ID ].Partner = null;
pinfo[ player.ID ].TimeRequest = 0;
pinfo[ plr.ID ].TimeRequest = 0;
   } else {
   
   PrivMessage( plr, "[!] " + plr.Name + " denied your request." );
   PrivMessage( player, "Request Denied." );
   pinfo[ player.ID ].Request = false;
   pinfo[ plr.ID ].Request = false;
   pinfo[ player.ID ].TimeRequest = 0;
   pinfo[ plr.ID ].TimeRequest = 0;
   }
}
}

else if ( cmd == "leave" )
{
if ( pinfo[ player.ID ].Team == false ) PrivMessage( player, "[Error] You don't have team." );
else
{
                        local plr = FindPlayer( pinfo[ player.ID ].Partner );
                        PrivMessage( plr, "[!] " + player.Name + " left the team." );
PrivMessage( player, "You are not more team of " + plr.Name );
pinfo[ player.ID ].Team = false;
pinfo[ plr.ID ].Team = false;
pinfo[ player.ID ].Partner = null;
pinfo[ plr.ID ].Partner = null;
}
}
}

Credits
Scripter: Fjose
Special thanks to:
S.L.C. - For his special functions (GetTok & NumTok)
Honey & soulshaker - For supporting me with the current problems about some functions.
Title: Re: Team System
Post by: Drake on Oct 26, 2014, 01:00 PM
Not Working for me!!!!
Title: Re: Team System
Post by: Fjose on Oct 26, 2014, 01:34 PM
Quote from: KraTO$ on Oct 26, 2014, 01:00 PMNot Working for me!!!!

What's the line? where you have the error.
Title: Re: Team System
Post by: Drake on Oct 26, 2014, 02:47 PM
Brother ..
time() gets an error (attempt to call 'integer')
Title: Re: Team System
Post by: Fjose on Oct 26, 2014, 02:52 PM
Quote from: KraTO$ on Oct 26, 2014, 02:47 PMBrother ..
time() gets an error (attempt to call 'integer')

I'm using the time() in all script, can be more specific?
Title: Re: Team System
Post by: Drake on Oct 26, 2014, 02:57 PM
That only gives me Error...IDK Why!!!!
Title: Re: Team System
Post by: Fjose on Oct 26, 2014, 03:03 PM
Quote from: KraTO$ on Oct 26, 2014, 02:57 PMThat only gives me Error...IDK Why!!!!

:/ are you using the cmd "team" right? or the error is with other cmd?
Title: Re: Team System
Post by: Drake on Oct 26, 2014, 03:31 PM
Quote from: KraTO$ on Oct 26, 2014, 02:57 PMThat only gives me Error...IDK Why!!!!

-_-...I am Not Nobb....


yes i am using all the things you said!!!!

I think like if we use date().hour;    etc
There is something time().    ??
Title: Re: Team System
Post by: Fjose on Oct 26, 2014, 03:58 PM
date() gets the current date.
time() gets the date since 1970.

In this case if I'm using a code such: pinfo[ player.ID ].TimeRequest = time() + 30;
I'm adding 30 seconds to the current time.

and then in this line:
else if ( pinfo[ player.ID ].TimeRequest < time() ) { PrivMessage( player, "[Error] Time ended." ); pinfo[ player.ID ].Request = false; pinfo[ player.ID ].Partner = null; pinfo[ plr.ID ].Request = false; pinfo[ plr.ID ].Partner = null; }
I'm confirming if the time request is minor than the current time.

Scripts Updated.
Title: Re: Team System
Post by: Drake on Oct 26, 2014, 04:09 PM
Listen I get error in this line:

else if ( pinfo[ player.ID ].TimeRequest < time() ) { PrivMessage( player, "[Error] Time ended." ); pinfo[ player.ID ].Request = false; pinfo[ player.ID ].Partner = null; pinfo[ plr.ID ].Request = false; pinfo[ plr.ID ].Partner = null; }

Error : attempt to call 'integer'


Thats all I get...
Title: Re: Team System
Post by: Honey on Oct 26, 2014, 04:25 PM
Are any specific lines ( like 70 or 18 ) mentioned?
Title: Re: Team System
Post by: Drake on Oct 26, 2014, 06:11 PM
I told the Specific Line already -_-

Title: Re: Team System
Post by: Honey on Oct 27, 2014, 01:24 AM
That is not a specific line.Those are 2-3 lines.Let me try this code and I'll tell you if i face the same problem.
Title: Re: Team System
Post by: George on Oct 27, 2014, 01:25 AM
Quote from: KraTO$ on Oct 26, 2014, 04:09 PMelse if ( pinfo[ player.ID ].TimeRequest < time() ) { PrivMessage( player, "[Error] Time ended." ); pinfo[ player.ID ].Request = false; pinfo[ player.ID ].Partner = null; pinfo[ plr.ID ].Request = false; pinfo[ plr.ID ].Partner = null; }
Really?
If you don't have an "if" above that, remove the "else".
Title: Re: Team System
Post by: . on Oct 27, 2014, 01:26 AM
Quote from: KraTO$ on Oct 26, 2014, 06:11 PMI told the Specific Line already -_-

No you haven't! Not even the provided error message seems to be correct. Call "integer" where?... maybe "tointeger". I haven't looked at the code but based on the error message you provided the code is trying to use a variable of integer data type as a function. At least that's what I understand from that message. Because I don't see a function/method named "integer" being called.

Learn to provide the proper information to the author so that he won't have to waste 10-20 posts just to get one simple information such as
Title: Re: Team System
Post by: Drake on Oct 27, 2014, 08:49 AM
Ok then see the Error yourself....   

When I type "/team kra  [Player's Name]   or   0  [Player's ID]

(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi62.tinypic.com%2F2utgftk.jpg&hash=785e99d703c2dd802c863e5fc75c74435cb873ef)



Line 921 is :

if ( status[ player.ID ].TimeRequest < time() )

Full Code of team is

else if ( cmd == "team" )
    {
  local plr = FindPlr( GetTok( text, " ", 1 ) );
  if ( status[ player.ID ].Team == true ) PrivMessage( player, "[Error] You already are in team." );
  else if ( !text ) PrivMessage( player, "Syntax: /team <player name or id>" );
  else if ( !plr ) PrivMessage( player, "[Error] Unknown player." );
  else if ( status[ plr.ID ].Team == true ) PrivMessage( player, "[Error] " + plr.Name + " is already in team." );
  else if ( status[ player.ID ].Request == true ) PrivMessage( player, "[Error] You already have a request." );
  else if ( status[ plr.ID ].Request == true ) PrivMessage( player, "[Error] " + plr.Name + " already have a request." );
  else
  {
   if ( status[ player.ID ].TimeRequest < time() )
   {
    status[ player.ID ].Request = false; status[ player.ID ].Partner = null;  status[ player.ID ].TimeRequest = 0;
    status[ plr.ID ].Request = false; status[ plr.ID ].Partner = null; status[ plr.ID ].TimeRequest = 0;
   }
   
   PrivMessage( plr, "[!] " + player.Name + " would like to team up with you." );
   PrivMessage( player, "Request submitted." );
   status[ player.ID ].Partner = plr.ID;
   status[ plr.ID ].Partner = player.ID;
   status[ player.ID ].TimeRequest = time() + 30;
   status[ plr.ID ].TimeRequest = time() + 30;
  }
 }

Title: Re: Team System
Post by: Fjose on Oct 27, 2014, 03:09 PM
I think it I have the solution but first.

post the line 912 of onplayercommand and the 289 of gettok.

note: are you sure that you have added the timerequest as is written? post your class too. maybe the error is in the class
Title: Re: Team System
Post by: Honey on Oct 27, 2014, 03:52 PM
Well I'm back with a fixed team script.This script had many bugs to solve but now it works perfectly for me. FJose update your script with this or atleast take a good look at your's because you're forgetting to do something important in the team cmd.Your FindPlr wasn't working for me so I had to use FindPlayer and I also edit some other lines of code.This is the code :

else if ( cmd == "team" )
    {
if ( !text ) MessagePlayer2( "Syntax: /team <player name or id>", player );
local plr = FindPlayer( GetTok( text, " ", 1 ) );
if ( !plr ) MessagePlayer2( "[Error] Unknown player.", player );
else if ( pinfo[ player.ID ].Team == true ) MessagePlayer2( "[Error] You already are in team.", player );
else if ( pinfo[ plr.ID ].Team == true ) MessagePlayer2( "[Error] " + plr.Name + " is already in team.", player );
else if ( pinfo[ player.ID ].Request == true ) MessagePlayer2( "[Error] You already have a request.", player );
else if ( pinfo[ plr.ID ].Request == true ) MessagePlayer2( "[Error] " + plr.Name + " already have a request.", player );
else
{
if ( pinfo[ player.ID ].TimeRequest < time() ) {
pinfo[ player.ID ].Request = false; pinfo[ player.ID ].Partner = null;  pinfo[ player.ID ].TimeRequest = 0;
pinfo[ plr.ID ].Request = false; pinfo[ plr.ID ].Partner = null; pinfo[ plr.ID ].TimeRequest = 0;
}

MessagePlayer2( "" + player.Name + " would like to team up with you.", plr );
MessagePlayer2( "Request submitted.", player );
pinfo[ player.ID ].Partner = plr.Name;
pinfo[ plr.ID ].Partner = player.Name;
pinfo[ player.ID ].TimeRequest = time() + 30;
pinfo[ plr.ID ].TimeRequest = time() + 30;
pinfo[ plr.ID ].Request = true;
pinfo[ player.ID ].Request = true
}
}
else if ( cmd == "accept" )
{
local plr = FindPlayer( pinfo[ player.ID ].Partner );
if ( pinfo[ player.ID ].Request == false ) MessagePlayer2( "[Error] You don't have a request.", player );
else if ( pinfo[ player.ID ].Team == true ) MessagePlayer2( "[Error] You already have a team-mate.", player );
else
{
if ( pinfo[ player.ID ].TimeRequest < time() ) {
MessagePlayer2( "[Error] Time ended.", player );
pinfo[ player.ID ].Request = false;
pinfo[ player.ID ].Partner = null;
pinfo[ plr.ID ].Request = false;
pinfo[ plr.ID ].Partner = null;
pinfo[ player.ID ].TimeRequest = 0;
pinfo[ plr.ID ].TimeRequest = 0;
} else {

MessagePlayer2( "[!] " + player.Name + " is doing team with you.", player );
MessagePlayer2( "Request Accepted! You are now teaming with " + plr.Name, player );
pinfo[ player.ID ].Team = true;
pinfo[ plr.ID ].Team = true;
pinfo[ player.ID ].Request = false;
pinfo[ plr.ID ].Request = false;
pinfo[ player.ID ].TimeRequest = 0;
pinfo[ plr.ID ].TimeRequest = 0;
player.Pos = plr.Pos;
}
}
}

else if ( cmd == "deny" )
{
local plr = FindPlayer( pinfo[ player.ID ].Partner );
if ( pinfo[ player.ID ].Request == false ) MessagePlayer2( "[Error] You don't have a request.", player );
else
{
if ( pinfo[ player.ID ].TimeRequest < time() ) {
MessagePlayer2( "[Error] Time ended.", player );
pinfo[ player.ID ].Request = false;
pinfo[ plr.ID ].Request = false;
pinfo[ player.ID ].Partner = null;
pinfo[ plr.ID ].Partner = null;
pinfo[ player.ID ].TimeRequest = 0;
pinfo[ plr.ID ].TimeRequest = 0;
}

MessagePlayer2( "[!] " + plr.Name + " denied your request.", player );
MessagePlayer2( "Request Denied.", player );
pinfo[ player.ID ].Request = false;
pinfo[ plr.ID ].Request = false;
pinfo[ player.ID ].TimeRequest = 0;
pinfo[ plr.ID ].TimeRequest = 0;
}
}

else if ( cmd == "leave" )
{
local plr = FindPlayer( pinfo[ player.ID ].Partner );
if ( pinfo[ player.ID ].Team == false ) MessagePlayer2( "[Error] You don't have team.", player );
else
{
MessagePlayer2( "[!] " + player.Name + " left the team.", player );
MessagePlayer2( "[!] " + player.Name + " left the team.", pinfo[ player.ID ].Partner );
pinfo[ player.ID ].Team = false;
pinfo[ plr.ID ].Team = false;
pinfo[ player.ID ].Partner = null;
pinfo[ plr.ID ].Partner = null;
}
}

Waiting for replies :)
Title: Re: Team System
Post by: Fjose on Oct 27, 2014, 04:07 PM
ok thanks honey,

rarely.. I never had a problem with the FindPlr
Title: Re: Team System
Post by: Drake on Oct 27, 2014, 06:25 PM
Which plugins contains time(). Function?
Title: Re: Team System
Post by: . on Oct 27, 2014, 06:46 PM
Quote from: KraTO$ on Oct 27, 2014, 06:25 PMWhich plugins contains time(). Function?

It's built into the Squirrel standard library (http://squirreldoc.neonapple.com/v3/lib.index.html).
Title: Re: Team System
Post by: Fjose on Oct 27, 2014, 06:52 PM
Quote from: KraTO$ on Oct 27, 2014, 06:25 PMWhich plugins contains time(). Function?

squirrel plugin as said S.L.C. anyway you can try the code fixed by honey. still I have my doubts of why the script had that problem but for now I'll update the code wih the code of honey.
Title: Re: Team System
Post by: Drake on Oct 28, 2014, 01:38 AM
I think my plugins are not correct....please give the plugins you have..
Title: Re: Team System
Post by: soulshaker on Oct 28, 2014, 05:08 AM
Quote from: KraTO$ on Oct 28, 2014, 01:38 AMI think my plugins are not correct....please give the plugins you have..
Download latest plugins from Here (http://forum.vc-mp.org/?board=3.0)
Title: Re: Team System
Post by: Drake on Oct 28, 2014, 03:36 PM
Same Error after replacing all the plugins and the server .. :(

(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi58.tinypic.com%2F14ka42e.png&hash=eb6d6983af88cb74edf6321f2609e0c63bb985e0)

Title: Re: Team System
Post by: Fjose on Oct 28, 2014, 03:45 PM
surely you are missing something...

anyway about your question, these are my modules used: Windows (x86) Plugins Pack (http://v04.maxorator.com/files/plugins/win32_package_v1.zip)
+ server: Windows Server (x86) (http://v04.maxorator.com/files/VCMP04_server_v9_win32.zip)
Title: Re: Team System
Post by: Drake on Oct 28, 2014, 04:06 PM
Quote from: Fjose on Oct 28, 2014, 03:45 PMsurely you are missing something...

anyway about your question, these are my modules used: Windows (x86) Plugins Pack (http://v04.maxorator.com/files/plugins/win32_package_v1.zip)
+ server: Windows Server (x86) (http://v04.maxorator.com/files/VCMP04_server_v9_win32.zip)

Getting the Same Fucking Error ..
ahhhh   
Title: Re: Team System
Post by: Sebastian on Oct 28, 2014, 04:26 PM
Well, I know it is a very weird idea... but maybe there is something wrong with the VPS's PC time.
If I am not wrong, time() function returns the time of the pc that runs the server, so maybe something is blocking it. ???

Did you test the script on your server ? If not, give it a try and see the results. ;)
Title: Re: Team System
Post by: Drake on Oct 28, 2014, 04:31 PM
Quote from: sseebbyy on Oct 28, 2014, 04:26 PMWell, I know it is a very weird idea... but maybe there is something wrong with the VPS's PC time.
If I am not wrong, time() function returns the time of the pc that runs the server, so maybe something is blocking it. ???

Did you test the script on your server ? If not, give it a try and see the results. ;)


I tried both on PC and VPS....... Same error
Title: Re: Team System
Post by: soulshaker on Oct 28, 2014, 06:31 PM
Quote from: sseebbyy on Oct 28, 2014, 04:26 PMWell, I know it is a very weird idea... but maybe there is something wrong with the VPS's PC time.
If I am not wrong, time() function returns the time of the pc that runs the server, so maybe something is blocking it. ???
same question here, as it works very good for me
<~SouLy^> !exe StaffMessage(time());
<&Busty> 1414520795
<&Busty> This command has been successfully executed.
<~SouLy^> !exe StaffMessage(GetFullTime());
<&Busty> Tuesday, October 28, 2014, 14:27:58 EDT
<&Busty> This command has been successfully executed.
Title: Re: Team System
Post by: Fjose on Oct 28, 2014, 07:48 PM
PTS v1.0.1
- FindPlr() was removed, all functions/cmds uses now FindPlayer()
- onPlayerPart modified.
- all commands were updated.
- other issues were fixed.

everybody should update their script with this version.
Title: Re: Team System v1.0.1
Post by: . on Oct 28, 2014, 11:21 PM
NOTE: This is untested code! If you use this please make sure to test it first.

// Moved to PasteBin to preserve formatting: http://pastebin.com/F9j0EUtj
Title: Re: Team System v1.0.1
Post by: Drake on Oct 29, 2014, 02:33 AM
Why the fuck doesn't it works for me!!!!!!!

Now Developers can only Fix the Problem......
Title: Re: Team System v1.0.1
Post by: soulshaker on Oct 29, 2014, 07:14 AM
Just tried the code with seby's blank server and got the some errors:-

Error on Console:-

(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fs7.postimg.org%2F4bi0vcr57%2Fputty.png&hash=f094d3a05412ef971796acc8a0d1f58199b3bda6)

line 385:-

(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fs7.postimg.org%2Fwzuyyktbf%2F385.png&hash=fa87f86f40f4619ca9421696e234d62a57bbe6d3)

line 133:-

(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fs7.postimg.org%2F5rtjdhu23%2F133.png&hash=5a3b6550cc0982080f3f73cb6191b394561faaf9)

Title: Re: Team System v1.0.1
Post by: . on Oct 29, 2014, 12:03 PM
Try using this version of the GetTok() and NumTok() functions. They do various checks on the passed arguments before using them so they might be safer.

function GetTok(str, sep, pos, len = null)
{
    // First round is parameter validation
    if (typeof str != "string" || str.len() < 1) return ""; // Not a valid string
    else if (typeof sep != "string" || sep.len() < 1) return ""; // Not a valid separator
    // Split the string into tokens
    local tok = split(str, sep);
    // Second round is result validation
    if (typeof tok != "array") return str; // Maybe an internal error
    else if (tok.len() == 1 && tok[0] == str) return tok[0]; // No tokens we're found
    // Third round is position parameter adjustment
    if (typeof pos != "integer")
    {
        if (typeof pos == "float" || typeof pos == "string") pos = pos.tointeger();
        else return ""; // Invalid position
    }
    // Make sure the position is in bounds
    if (pos >= tok.len()) return ""; // The position is out of bounds
    else if (pos < 0) pos = 0;
    // Fourth round is length parameter adjustment
    if (len == null)
        len = (tok.len() - pos);
    else if (typeof len != "integer")
    {
        if (typeof len == "float" || typeof len == "string") len = len.tointeger();
        else return ""; // Invalid length
    }
    // Make sure the length is in bounds
    if ((pos+len) > tok.len()) len = (tok.len() - pos);
    else if (len <= 0) return ""; // The length is out of bounds or invalid
    // Retrieve the required tokens
    tok = tok.slice(pos, pos+len);
    // Make sure we don't go into a loop for nothing
    if (tok.len() > 1)
    {
        // Create a temporary variable to hold the generated string
        local res = tok[0];
        // Remove the element that we just used
        tok.remove(0);
        // Implode those tokens using the specified separator
        foreach (tk in tok) res += sep + tk;
        // Return the result
        return res;
    }
    // Just return the requested token
    else if (tok.len() == 1) return tok[0];
    // The array slicing failed somehow
    else return "";
}

function NumTok(str, sep)
{
    // First round is parameter validation
    if (typeof str != "string" || str.len() < 1) return 0; // Not a valid string
    else if (typeof sep != "string" || sep.len() < 1) return 0; // Token must be a string
    // Split the string into tokens
    local tok = split(str, sep);
    // Second round is result validation
    if (typeof tok != "array") return 0; // Maybe an internal error
    else if (tok.len() == 1 && tok[0] == str) return 0; // No tokens we're found
    else return tok.len(); // Return the number of found tokens
}

Be aware that they work a little different and the rest of the code might have to be adjusted to work with them:
function GetTok(str, sep, pos, len = null);
pos: Is the position where you want your string slicing to start. If you set it to 0 it will start from where the first separator is encountered. If it's set to 1 it will start from where the second separator is encountered. If it's set to 2 it will start from where the third separator is encountered. And so on...

len: Is the position where you want your string slicing to end. If you set it to 0 it return an empty string because that means to return no token. If it's set to 1 it'll end where the first separator is encountered after the start. If it's set to 2 it'll end where the second separator is encountered after the start. And so on...
Setting the len to null or simply omitting it will return everything from the start position until the last separator is encountered.

Here are some tests and the expected results:
local text = "param1 arg2 param3 val4 blah blah blah";

GetTok(text, " ", 0);
// Returns: "param1 arg2 param3 val4 blah blah blah"

GetTok(text, " ", 1);
// Returns: "arg2 param3 val4 blah blah blah"

GetTok(text, " ", 2);
// Returns: "param3 val4 blah blah blah"

GetTok(text, " ", 0, 2);
// Returns: "param1 arg2"

GetTok(text, " ", 2, 4);
// Returns: "param3 val4 blah"

GetTok(text, " ", 67);
// Returns: "" (Out of bounds)

GetTok(text, " ", -242, 4);
// Returns: "param1 arg2 param3 val4" (Got converted to 0)

GetTok(text, " ", 2, -23);
// Returns: "" (Out of bounds)

GetTok(text, "#", 2, -23);
// Returns: "param1 arg2 param3 val4 blah blah blah" (Separator not found)

GetTok(text, " ", "3", 3.2454);
// Returns: "val4 blah blah" (Automatically converted to integer)

GetTok(text, 261, "3", 3.2454);
// Returns: "" (Not a valid separator)

GetTok(null, " ", "3", 3.2454);
// Returns: "" (Not a valid string)
Title: Re: Team System v1.0.1
Post by: soulshaker on Oct 29, 2014, 01:57 PM
Thanks SLC that worked :D

@Fjose:-
Quote from: Fjose on Oct 21, 2014, 03:16 AMfunction onPlayerPart( player, reason )
{
   if ( pinfo[ player.ID ].Team == true )
   {
      local plr = FindPlayer( pinfo[ player.ID ].Partner );
      if ( plr ) {
         PrivMessage( plr, "[!] " + player.Name + " left the team." );
         pinfo[ plr.ID ].Partner = null;
         pinfo[ plr.ID ].Team = true;
      }
   }
   pinfo[ player.ID ] = null;
}
it must be false or the player will be in team always. Anyways you can update the script with this one:-

Functions:-
class PlayerInfo
{
Team = false;
Request = false;
TimeRequest = 0;
Partner = null;
}

function onScriptLoad()
{
pinfo <- array( GetMaxPlayers(), null );
}

function onPlayerJoin( player )
{
pinfo[ player.ID ] = PlayerInfo();
}

function onPlayerPart( player, reason )
{
if ( pinfo[ player.ID ].Team == true )
{
local plr = FindPlayer( pinfo[ player.ID ].Partner );
if ( plr )
{
PrivMessage( plr, "[!] " + player.Name + " left the team." );
pinfo[ plr.ID ].Partner = null;
pinfo[ plr.ID ].Team = false;
}
}
 pinfo[ player.ID ] = null;
}

function onPlayerSpawn( player )
{
if ( pinfo[ player.ID ].Team == true )
{
local plr = FindPlayer( pinfo[ player.ID ].Partner );
if ( plr ) player.Pos = plr.Pos;
}
}

function GetTok(str, sep, pos, len = null)
{
 if (typeof str != "string" || str.len() < 1) return "";
 else if (typeof sep != "string" || sep.len() < 1) return "";
 local tok = split(str, sep);
 if (typeof tok != "array") return str;
 else if (tok.len() == 1 && tok[0] == str) return tok[0];
 if (typeof pos != "integer")
 {
  if (typeof pos == "float" || typeof pos == "string") pos = pos.tointeger();
  else return "";
 }
 if (pos >= tok.len()) return "";
 else if (pos < 0) pos = 0;
 if (len == null)
  len = (tok.len() - pos);
 else if (typeof len != "integer")
 {
  if (typeof len == "float" || typeof len == "string") len = len.tointeger();
  else return "";
 }
 if ((pos+len) > tok.len()) len = (tok.len() - pos);
 else if (len <= 0) return "";
 tok = tok.slice(pos, pos+len);
 if (tok.len() > 1)
 {
  local res = tok[0];
  tok.remove(0);
  foreach (tk in tok) res += sep + tk;
  return res;
 }
 else if (tok.len() == 1) return tok[0];
 else return "";
}

function NumTok(str, sep)
{
 if (typeof str != "string" || str.len() < 1) return 0;
 else if (typeof sep != "string" || sep.len() < 1) return 0;
 local tok = split(str, sep);
 if (typeof tok != "array") return 0;
 else if (tok.len() == 1 && tok[0] == str) return 0;
 else return tok.len();
}

Commands:-
function onPlayerCommand( player, cmd, text )
{
local plr, i = 0;
if ( text )
{
plr = FindPlayer( text );
i = NumTok(text, " ").tointeger();
}
if ( cmd == "team" )
    {
  local plr = FindPlayer( GetTok( text, " ", 1 ) );
  if ( pinfo[ player.ID ].Team == true ) PrivMessage( player, "[Error] You already have a team." );
  else if ( !text ) PrivMessage( player, "Syntax: /team <player name or id>" );
  else if ( !plr ) PrivMessage( player, "[Error] Unknown player." );
  else if ( pinfo[ plr.ID ].Team == true ) PrivMessage( player, "[Error] " + plr.Name + " is already in a team." );
  else if ( pinfo[ player.ID ].Request == true ) PrivMessage( player, "[Error] You already have a request." );
  else if ( pinfo[ plr.ID ].Request == true ) PrivMessage( player, "[Error] " + plr.Name + " already have a request." );
  else
  {
   if ( pinfo[ player.ID ].TimeRequest < time() ) {
   pinfo[ player.ID ].Request = false; pinfo[ player.ID ].Partner = null;  pinfo[ player.ID ].TimeRequest = 0;
   pinfo[ plr.ID ].Request = false; pinfo[ plr.ID ].Partner = null; pinfo[ plr.ID ].TimeRequest = 0;
   }
   
   PrivMessage( plr, "[!] " + player.Name + " would like to team up with you." );
   PrivMessage( player, "Request submitted." );
   pinfo[ player.ID ].Partner = plr.ID;
   pinfo[ plr.ID ].Partner = player.ID;
   pinfo[ player.ID ].TimeRequest = time() + 30;
   pinfo[ plr.ID ].TimeRequest = time() + 30;
   pinfo[ plr.ID ].Request = true;
   pinfo[ player.ID ].Request = true;
  }
 }
 
 else if ( cmd == "accept" )
 {
  local plr = FindPlayer( pinfo[ player.ID ].Partner );
  if ( pinfo[ player.ID ].Request == false ) PrivMessage( player, "[Error] You don't have a request." );
  else if ( pinfo[ player.ID ].Team == true ) PrivMessage( player, "[Error] You already have a team-mate." );
  else
  {
   if ( pinfo[ player.ID ].TimeRequest < time() ) {
   PrivMessage( player, "[Error] Time ended." );
   pinfo[ player.ID ].Request = false;
   pinfo[ player.ID ].Partner = null;
   pinfo[ plr.ID ].Request = false;
   pinfo[ plr.ID ].Partner = null;
   pinfo[ player.ID ].TimeRequest = 0;
   pinfo[ plr.ID ].TimeRequest = 0;
      } else {
   
   PrivMessage( plr, "[!] " + player.Name + " is doing team with you." );
   PrivMessage( player, "Request Accepted! You are now teaming with " + plr.Name );
   pinfo[ player.ID ].Team = true;
   pinfo[ plr.ID ].Team = true;
   pinfo[ player.ID ].Request = false;
   pinfo[ plr.ID ].Request = false;
   pinfo[ player.ID ].TimeRequest = 0;
   pinfo[ plr.ID ].TimeRequest = 0;
   player.Pos = plr.Pos;
   }
  }
 }
   
 else if ( cmd == "deny" )
 {
  local plr = FindPlayer( pinfo[ player.ID ].Partner );
  if ( pinfo[ player.ID ].Request == false ) PrivMessage( player, "[Error] You don't have a request." );
  else
  {
     if ( pinfo[ player.ID ].TimeRequest < time() ) {
   PrivMessage( player, "[Error] Time ended." );
   pinfo[ player.ID ].Request = false;
   pinfo[ plr.ID ].Request = false;
   pinfo[ player.ID ].Partner = null;
   pinfo[ plr.ID ].Partner = null;
   pinfo[ player.ID ].TimeRequest = 0;
   pinfo[ plr.ID ].TimeRequest = 0;
     } else {
     
     PrivMessage( plr, "[!] " + plr.Name + " denied your request." );
     PrivMessage( player, "Request Denied." );
     pinfo[ player.ID ].Request = false;
     pinfo[ plr.ID ].Request = false;
     pinfo[ player.ID ].TimeRequest = 0;
     pinfo[ plr.ID ].TimeRequest = 0;
     }
  }
 }

 else if ( cmd == "leave" )
 {
  local plr = FindPlayer( pinfo[ player.ID ].Partner );
  if ( pinfo[ player.ID ].Team == false ) PrivMessage( player, "[Error] You don't have team." );
  else
  {
   PrivMessage( plr, "[!] " + player.Name + " left the team." );
   PrivMessage( player, "You are not more team of " + plr.Name );
   pinfo[ player.ID ].Team = false;
   pinfo[ plr.ID ].Team = false;
   pinfo[ player.ID ].Partner = null;
   pinfo[ plr.ID ].Partner = null;
  }
 }
return 1;
}
Title: Re: Team System v1.0.1
Post by: Fjose on Oct 29, 2014, 02:55 PM
@soulshaker I'll fix the onplayerpart. I'll add the GetTok and NumTok. still I thinking why the gettok mine had problems, incredibly I never had that error.

Did you a change with the cmds?


Script Updated v1.0.2
- GetTok & NumTok were replaced (thanks S.L.C.)
- Fixed a bad declaration when player leaves the server. (thanks souldshaker)
Title: Re: Team System v1.0.2
Post by: Drake on Oct 29, 2014, 03:51 PM
GetTok and NumTok are fine enough to work.....No need to change that

My problem also Fixed..... I had constants problem nothing else and now its working fine...Thanx Fjose....I will be waiting for another Snippet made by you..:D

Title: Re: Team System v1.0.2
Post by: soulshaker on Oct 29, 2014, 05:35 PM
Quote from: Fjose on Oct 29, 2014, 02:55 PMDid you a change with the cmds?
nope i didn't, just tried your previous code in a blank script and got those errors, and the functions by SLC worked like a charm :D

Quote from: Fjose on Oct 21, 2014, 03:16 AMClass PlayerInfo {
Team = false;
Request = false;
TimeRequest = 0;
Partner = null;
}

Class gives me a error of "expected (" but class works :)
Title: Re: Team System v1.0.2
Post by: Drake on Oct 29, 2014, 05:48 PM
Souly ...you are doing something wrong.......As I don't have any problem now
Title: Re: Team System v1.0.2
Post by: soulshaker on Oct 29, 2014, 05:50 PM
what wrong lol? i already said the script is working( and already said the errors i faced and fixed them)
Title: Re: Team System v1.0.2
Post by: ThunderStorm on Oct 30, 2014, 10:51 AM
Because there is no text to slice..
if ( cmd == "team" )
    {
  local plr = FindPlayer( GetTok( text, " ", 1 ) ); // Error here
  if ( pinfo[ player.ID ].Team == true ) PrivMessage( player, "[Error] You already have a team." );
  else if ( !text ) PrivMessage( player, "Syntax: /team <player name or id>" );
  else if ( !plr ) PrivMessage( player, "[Error] Unknown player." );
  else if ( pinfo[ plr.ID ].Team == true ) PrivMessage( player, "[Error] " + plr.Name + " is already in a team." );
  else if ( pinfo[ player.ID ].Request == true ) PrivMessage( player, "[Error] You already have a request." );
  else if ( pinfo[ plr.ID ].Request == true ) PrivMessage( player, "[Error] " + plr.Name + " already have a request." );
  else
  {
   if ( pinfo[ player.ID ].TimeRequest < time() ) {
   pinfo[ player.ID ].Request = false; pinfo[ player.ID ].Partner = null;  pinfo[ player.ID ].TimeRequest = 0;
   pinfo[ plr.ID ].Request = false; pinfo[ plr.ID ].Partner = null; pinfo[ plr.ID ].TimeRequest = 0;
   }
   
   PrivMessage( plr, "[!] " + player.Name + " would like to team up with you." );
   PrivMessage( player, "Request submitted." );
   pinfo[ player.ID ].Partner = plr.ID;
   pinfo[ plr.ID ].Partner = player.ID;
   pinfo[ player.ID ].TimeRequest = time() + 30;
   pinfo[ plr.ID ].TimeRequest = time() + 30;
   pinfo[ plr.ID ].Request = true;
   pinfo[ player.ID ].Request = true;
  }
 }

Modify it like

if ( cmd == "team" )
    {
 
  if ( pinfo[ player.ID ].Team == true ) PrivMessage( player, "[Error] You already have a team." );
  else if ( !text ) PrivMessage( player, "Syntax: /team <player name or id>" ); // Checks if there is text.
  else
  {
   local plr = FindPlayer( GetTok( text, " ", 1 ) );
  else if ( !plr ) PrivMessage( player, "[Error] Unknown player." );
  else if ( pinfo[ plr.ID ].Team == true ) PrivMessage( player, "[Error] " + plr.Name + " is already in a team." );
  else if ( pinfo[ player.ID ].Request == true ) PrivMessage( player, "[Error] You already have a request." );
  else if ( pinfo[ plr.ID ].Request == true ) PrivMessage( player, "[Error] " + plr.Name + " already have a request." );
  else
  {
   if ( pinfo[ player.ID ].TimeRequest < time() ) {
   pinfo[ player.ID ].Request = false; pinfo[ player.ID ].Partner = null;  pinfo[ player.ID ].TimeRequest = 0;
   pinfo[ plr.ID ].Request = false; pinfo[ plr.ID ].Partner = null; pinfo[ plr.ID ].TimeRequest = 0;
   }
   
   PrivMessage( plr, "[!] " + player.Name + " would like to team up with you." );
   PrivMessage( player, "Request submitted." );
   pinfo[ player.ID ].Partner = plr.ID;
   pinfo[ plr.ID ].Partner = player.ID;
   pinfo[ player.ID ].TimeRequest = time() + 30;
   pinfo[ plr.ID ].TimeRequest = time() + 30;
   pinfo[ plr.ID ].Request = true;
   pinfo[ player.ID ].Request = true;
   }
   }
 }
Title: Re: Team System v1.0.2
Post by: Drake on Oct 30, 2014, 12:31 PM
Correct Thunder....
I already did that.....
Title: Re: Team System v1.0.2
Post by: ToMz on Nov 03, 2014, 02:52 AM
Nice Working Fjose
Title: Re: Team System v1.0.2
Post by: PsyChO_KiLLeR on Mar 05, 2015, 04:42 AM
this is bug script
dont need to use it bug my full script
Title: Re: Team System v1.0.2
Post by: . on Mar 05, 2015, 04:46 AM
Quote from: PsyChO_KiLLeR on Mar 05, 2015, 04:42 AMthis is bug script
dont need to use it bug my full script

Can you elaborate?
Title: Re: Team System v1.0.2
Post by: PsyChO_KiLLeR on Mar 05, 2015, 04:47 AM
i cant coz it give everywhere error in playerpart in playerjoin and also buggy my script and then no cmd work
Title: Re: Team System v1.0.2
Post by: . on Mar 05, 2015, 04:49 AM
Quote from: PsyChO_KiLLeR on Mar 05, 2015, 04:47 AMi cant coz it give everywhere error in playerpart in playerjoin and also buggy my script and then no cmd work

I meant: Can you tell us the errors? You cannot make a claim without an evidence to support that.
Title: Re: Team System v1.0.2
Post by: PsyChO_KiLLeR on Mar 05, 2015, 04:50 AM
ahh leave it i have enough time to upload images blah blah  and i also dont want this system i was just checking
Title: Re: Team System v1.0.2
Post by: . on Mar 05, 2015, 04:53 AM
Quote from: PsyChO_KiLLeR on Mar 05, 2015, 04:50 AMahh leave it i have enough time to upload images blah blah  and i also dont want this system i was just checking

You can find another one here (http://forum.vc-mp.org/?topic=60.0) but I doubt you'll be able to integrate that in your base code. Try the script as a standalone first to get an idea and then see if you want to integrate it.
Title: Re: Team System v1.0.2
Post by: Fjose on Mar 05, 2015, 04:39 PM
Tested by me, tested by others, working for me, working for others. The unique difference are the GetTok and NumTok functions, but anyways works.
Title: Re: Team System v1.0.2
Post by: Thijn on Mar 05, 2015, 05:41 PM
I bet he just failed to copy paste it into his script. It needs a bit of knowledge to do that...
Title: Re: Team System v1.0.2
Post by: PsyChO_KiLLeR on Mar 06, 2015, 07:59 AM
his numtok and gettok function is bug
Title: Re: Team System v1.0.2
Post by: Fjose on Mar 06, 2015, 11:09 PM
You can test it with your GetTok and NumTok functions.
Title: Re: Team System v1.0.2
Post by: PsyChO_KiLLeR on Mar 07, 2015, 04:33 AM
as i say already its bug!!!!!!!!!!!!!
i try it without your numtok and gettok function still bug
Title: Re: Team System v1.0.2
Post by: Thijn on Mar 07, 2015, 11:30 AM
Quote from: PsyChO_KiLLeR on Mar 07, 2015, 04:33 AMas i say already its bug!!!!!!!!!!!!!
i try it without your numtok and gettok function still bug
And like we said, its not bugged if you actually know how the adapt scripts to your own.
Title: Re: Team System v1.0.2
Post by: Street Killer on Jun 26, 2015, 05:33 PM
Sorry For Bumping ... :(

Today I Test It This Snippet On The Blank Script And It's Work Fine But I have Seen The Problem With The Cmd...
For Example:- Player1 want To Team With Player2 ... And Player1 Type: /team player2 ... Then Turn player2 Can Accept, Deny And Leave... But Player1 Can Also Do It... Why!! No-Error On Console
Title: Re: Team System v1.0.2
Post by: SAzEe21 on Aug 24, 2015, 07:43 PM
Hmmm, I also use this system. It's working for me... Great work Fjose!
Title: Re: Team System v1.0.2
Post by: SAzEe21 on Aug 24, 2015, 08:13 PM
Sorry for double posting...


AN ERROR HAS OCCURED [Unexpected argument in FindPlayer: must be integer or string]
CALLSTACK
*FUNCTION [onPlayerCommand()] Cmds.nut line [978]..

/team & accept commands are working. But, /deny & leave commands not working...

And the line is

local plr = FindPlayer( pinfo[ player.ID ].Partner );
same problem in deny&leave command...
Title: Re: Team System v1.0.2
Post by: Fjose on Aug 26, 2015, 03:41 PM
@Zeeshan.Bhatti the error is produced because you are using these commands having this: partner = null; FindPlayer will only works if is a string or an integer, I just changed the position of that line, check the code again.
Title: Re: Team System v1.0.2
Post by: SAzEe21 on Aug 27, 2015, 09:50 AM
Ok thanks. Now, its working fine..
Title: Re: Team System v1.0.2
Post by: Wolf on Sep 07, 2015, 06:26 AM
guys where we add these codes
Title: Re: Team System v1.0.2
Post by: KAKAN on Sep 07, 2015, 06:34 AM
In your scripts, if not then please stop scripting