Saveloc, set hp and set time scripts fix

Started by umar4911, Aug 11, 2017, 07:47 PM

Previous topic - Next topic

umar4911

First of all. Sorry for spamming the forum.
Plz fix the following scripts
This is the location script.
[spoiler]
function onScriptLoad()
{
 locations <- ConnectSQL( "databases/locations.db");
 print("Locations loaded.");
}





function onPlayerCommand(player, command, arguments)
{
 
if(cmd == "saveloc")
{
if(!arguments) MessagePlayer("Use /" + cmd + " <Name>", player);
else
{
local q = QuerySQL(locations, "SELECT * FROM location WHERE Name = '" + escapeSQLString(arguments) +"' ");
if(!q)
{
// Name of the location
// Name of the player who saved it
// it's axis
QuerySQL(locations, "INSERT INTO location ( Name, Made, Pos ) VALUES ('" + arguments(string) + "', '" + player.Name + "', '" + escapeSQLString(player.Pos) "')");
MessagePlayer("[#CCFF66]** Location saved. Use /gotoloc " + arguments + ".", player);
}
}




}




if(cmd == "gotoloc")
{
if(!text) MessagePlayer("Use /" + cmd + " <Name>", player);
else
{

local q = QuerySQL(locations, "SELECT * FROM location WHERE Name = '" + escapeSQLString(arguments) + "'");
local
x = GetSQLColumnData( q, 0), // name of the location
y = GetSQLColumnData( q, 1), // name of the player
z = GetSQLColumnData( q, 2), // axis
MessagePlayer("[#CCFF66]** You have been teleported to location: " + x + " Made By: " + y + ".", player);


}
}


}

 
 
[/spoiler]


SetHP
[spoiler]  function onPlayerCommand(player, command, arguments)
{

 
if(cmd == "sethp")
{
if(!arguments) MessagePlayer("[#CCFF66]** Use /" + cmd + " <hp> <Name>", player);
else
{
local parm = split(arguments, " " );
local hp = parm[0], plr = FindPlayer(parm[1]);
if(!plr) MessagePlayer("[#CCFF66]** Invalid Player", player);
else
{
plr.Health = hp;
Message("[#CCFF66]** Your hp has been set to :" + hp + "by :" + Player.Name + ".", plr);
}
}
}
 

}

[/spoiler]

Can anybody give me the code of Set time and set weather. The code of set timer in wiki is wrong!!
I am gamer, programmer and hacker. Try to find me!
xD

Razor.

function onScriptLoad()
{
 locations <- ConnectSQL( "databases/locations.db");
 print("Locations loaded.");
 Database();
}

function Database()
{
 QuerySQL( locations, "CREATE TABLE IF NOT EXISTS location ( Name, Made, Pos )" );
}

D4rkR420R

We can't support you if you don't provide us the issue or errors coming from the console.

Zone_Killer

#3
SetHP

function onPlayerCommand(player, command, arguments)
{
 if(command == "sethp")
 {
 if(!arguments) MessagePlayer("[#CCFF66]** Use /" + command + " <hp> <Name>", player);
 else
 {
local plr = FindPlayer(GetTok( arguments, " ", 2 ));
local health = GetTok( arguments, " ", 1, NumTok( arguments, " " ) );
 if(!plr) MessagePlayer("[#CCFF66]** Invalid Player", player);
else
 {
 plr.Health = health;
 Message("[#CCFF66]** Your hp has been set to :" + health + "by :" + Player.Name + ".", plr);
 }
 }
 }
 

}

GetTok Function
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;
}

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

Bohemia Is God Of Punjabi Rap
Yo Yo Honey Singh tou chutiya hai

umar4911

Quote from: DarkRaZoR^ on Aug 12, 2017, 03:13 AMWe can't support you if you don't provide us the issue or errors coming from the console.
The error is wrong number of parameters
I am gamer, programmer and hacker. Try to find me!
xD

KAKAN

 QuerySQL(locations, "INSERT INTO location ( Name, Made, Pos ) VALUES ('" + arguments(string) + "', '" + player.Name + "', '" + escapeSQLString(player.Pos) "')");

Arguments is a string.
oh no

umar4911

Quote from: KAKAN on Aug 12, 2017, 05:34 AMQuerySQL(locations, "INSERT INTO location ( Name, Made, Pos ) VALUES ('" + arguments(string) + "', '" + player.Name + "', '" + escapeSQLString(player.Pos) "')");

Arguments is a string.
The index string does not exist.
I am gamer, programmer and hacker. Try to find me!
xD

umar4911

Quote from: Zone_Killer on Aug 12, 2017, 04:05 AMSetHP

function onPlayerCommand(player, command, arguments)
{
 if(command == "sethp")
 {
 if(!arguments) MessagePlayer("[#CCFF66]** Use /" + command + " <hp> <Name>", player);
 else
 {
local plr = FindPlayer(GetTok( arguments, " ", 2 ));
local health = GetTok( arguments, " ", 1, NumTok( arguments, " " ) );
 if(!plr) MessagePlayer("[#CCFF66]** Invalid Player", player);
else
 {
 plr.Health = health;
 Message("[#CCFF66]** Your hp has been set to :" + health + "by :" + Player.Name + ".", plr);
 }
 }
 }
 

}

GetTok Function
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;
}

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

The "get tok function" line is giving error, end of line explected. I used semi-colon but didn't work.
I am gamer, programmer and hacker. Try to find me!
xD

Zone_Killer

@umar4911 try this

if(cmd == "sethp")
 {
 if(!text) MessagePlayer("[#CCFF66]** Use /" + cmd + " <hp> <Name>", player);
 else
 {
local plr = FindPlayer(GetTok( text, " ", 2 ));
local health = GetTok( text, " ", 1, NumTok( text, " " ) );
 if(!plr) MessagePlayer("[#CCFF66]** Invalid Player", player);
else
 {
 plr.Health = health.tointeger();
 Message("[#CCFF66]** Your hp has been set to :" + health + "by :" + player.Name + ".");
 }
 }
 }
Bohemia Is God Of Punjabi Rap
Yo Yo Honey Singh tou chutiya hai

umar4911

Quote from: Zone_Killer on Aug 13, 2017, 04:11 AM@umar4911 try this

if(cmd == "sethp")
 {
 if(!text) MessagePlayer("[#CCFF66]** Use /" + cmd + " <hp> <Name>", player);
 else
 {
local plr = FindPlayer(GetTok( text, " ", 2 ));
local health = GetTok( text, " ", 1, NumTok( text, " " ) );
 if(!plr) MessagePlayer("[#CCFF66]** Invalid Player", player);
else
 {
 plr.Health = health.tointeger();
 Message("[#CCFF66]** Your hp has been set to :" + health + "by :" + player.Name + ".");
 }
 }
 }
The problem is in the
GetTok Function
function GetTok(string, separator, n, ...)
IT gives error that
error end of statement expected (; or if)
I am gamer, programmer and hacker. Try to find me!
xD

Xmair

Remove GetTok Function and keep the function

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

KAKAN

https://pastebin.com/KeU1muUFStatus: Untested
oh no

umar4911

Quote from: KAKAN on Aug 13, 2017, 08:52 AMhttps://pastebin.com/KeU1muUFStatus: Untested
thank you for the code.  Now plz help me in saveloc cmd
I am gamer, programmer and hacker. Try to find me!
xD

Xmair

Quote from: umar4911 on Aug 15, 2017, 05:03 PM
Quote from: KAKAN on Aug 13, 2017, 08:52 AMhttps://pastebin.com/KeU1muUFStatus: Untested
thank you for the code.  Now plz help me in saveloc cmd
1. Make a table in the database for locations.
2. Insert data(location name, position) into the table when a player uses /saveloc
3. When a player uses /gotoloc, select data from the table and set his position according to the data.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

umar4911

Quote from: Xmair on Aug 18, 2017, 04:24 AM
Quote from: umar4911 on Aug 15, 2017, 05:03 PM
Quote from: KAKAN on Aug 13, 2017, 08:52 AMhttps://pastebin.com/KeU1muUFStatus: Untested
thank you for the code.  Now plz help me in saveloc cmd
1. Make a table in the database for locations.
2. Insert data(location name, position) into the table when a player uses /saveloc
3. When a player uses /gotoloc, select data from the table and set his position according to the data.
It is gives me error that string does not exist.
I am gamer, programmer and hacker. Try to find me!
xD