Team System v1.0.2

Started by Fjose, Oct 21, 2014, 03:16 AM

Previous topic - Next topic

Fjose

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.

Drake

Not Working for me!!!!

Fjose

Quote from: KraTO$ on Oct 26, 2014, 01:00 PMNot Working for me!!!!

What's the line? where you have the error.

Drake

Brother ..
time() gets an error (attempt to call 'integer')

Fjose

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?

Drake

That only gives me Error...IDK Why!!!!

Fjose

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?

Drake

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().    ??

Fjose

#8
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.

Drake

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...

Honey

Are any specific lines ( like 70 or 18 ) mentioned?

Drake

I told the Specific Line already -_-


Honey

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.

George

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".

.

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
  • line number(s) (maybe even column if possible)
  • actual error message with as much debug information as possible
  • circumstances under which the code was used (step by step)
  • was there any other code involved? (maybe it's your code failing)
  • sometimes even actual screenshots of the console output
  • server and used plugin versions
  • details... details... details...
.