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!!
function onScriptLoad()
{
locations <- ConnectSQL( "databases/locations.db");
print("Locations loaded.");
Database();
}
function Database()
{
QuerySQL( locations, "CREATE TABLE IF NOT EXISTS location ( Name, Made, Pos )" );
}
We can't support you if you don't provide us the issue or errors coming from the console.
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();
}
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
QuerySQL(locations, "INSERT INTO location ( Name, Made, Pos ) VALUES ('" + arguments(string) + "', '" + player.Name + "', '" + escapeSQLString(player.Pos) "')");
Arguments is a string.
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.
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.
@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 + ".");
}
}
}
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)
Remove GetTok Function
and keep the function
https://pastebin.com/KeU1muUF
Status: Untested
Quote from: KAKAN on Aug 13, 2017, 08:52 AMhttps://pastebin.com/KeU1muUF
Status: Untested
thank you for the code. Now plz help me in saveloc cmd
Quote from: umar4911 on Aug 15, 2017, 05:03 PMQuote from: KAKAN on Aug 13, 2017, 08:52 AMhttps://pastebin.com/KeU1muUF
Status: 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.
Quote from: Xmair on Aug 18, 2017, 04:24 AMQuote from: umar4911 on Aug 15, 2017, 05:03 PMQuote from: KAKAN on Aug 13, 2017, 08:52 AMhttps://pastebin.com/KeU1muUF
Status: 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.
Try changing string to arguments
Quote from: umar4911 on Aug 22, 2017, 04:19 PMQuote from: Xmair on Aug 18, 2017, 04:24 AMQuote from: umar4911 on Aug 15, 2017, 05:03 PMQuote from: KAKAN on Aug 13, 2017, 08:52 AMhttps://pastebin.com/KeU1muUF
Status: 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 ued escapeSQLstring and it worked. Now please fix gotoloc cmd
if(cmd == "gotoloc")
{
if(!arguments) MessagePlayer("Use /" + cmd + " <Name>", player);
else
{
local q = QuerySQL(locations, "SELECT * FROM location WHERE Name = '" + escapeSQLString(arguments) + "'");
if(!q) MessagePlayer("[#CCFF66]** location does not exist ", player);
else
{
local
n = GetSQLColumnData( q, 0), // name of the location
p = GetSQLColumnData( q, 1), // name of the player
X = GetSQLColumnData( q, 2), // xaxis
Y = GetSQLColumnData( q, 3), // xaxis
Z = GetSQLColumnData( q, 4); // xaxis
Vector( X, Y Z);
MessagePlayer("[#CCFF66]** You have been teleported to location: " + n + " Made By: " + p + ".", player);
}
}
}
Change this Vector( X, Y Z);
toplayer.Pos = Vector( X, Y Z);
Quote from: Xmair on Sep 01, 2017, 04:34 AMChange this Vector( X, Y Z);
toplayer.Pos = Vector( X, Y Z);
It worked but there is still a problem.
I saved few locations with from different places but I am always teleported to one location.
Try usingplayer.Pos = Vector( X.tofloat( ), Y.tofloat( ), Z.tofloat( ) );
Quote from: umar4911 on Aug 11, 2017, 07:47 PMCan anybody give me the code of Set time and set weather. The code of set timer in wiki is wrong!!
Here You Are Friend Umar <3 TesTed With Command Colors!
function onPlayerCommand(player, command, arguments)
text = arguments;
Settime
else if ( cmd == "settime" )
{
if ( !text ) MessagePlayer( "[#ff0000]Correct syntax : /settime <hr> <min>", player );
else if ( split(text, " ").len() < 2) return MessagePlayer("[#ff0000]Correct syntax : /settime <hr> <min>", player )
else
{
local a = split(text, " ");
if ( !IsNum( a[0] )) MessagePlayer( "[#ffbb00]Format: /settime <hr> <min>", player );
else if ( !IsNum( a[1] )) MessagePlayer( "[#ffbb00]Format: /settime <hr> <min>", player );
else SetTime( a[0].tointeger(), a[1].tointeger() ) ;
}
}
Set Weather
else if ( cmd == "setweather" )
{
if ( !text ) MessagePlayer( "[#ff0000]Usage: setweather [Weather/ID]", player );
else {
switch( text.tolower() )
{
case "4":
SetWeather( 4 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Sunny.");
break;
case "5":
SetWeather( 5 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Rainy.");
break;
case "0":
SetWeather( 0 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Clear Skies.");
break;
case "1":
SetWeather( 1 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To OverCast.");
break;
case "2":
SetWeather( 2 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Rainy-Lightning.");
break;
case "3":
SetWeather( 3 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Foggy.");
break;
case "6":
SetWeather( 6 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Dark Sky Partly Cloudy.");
break;
case "7":
SetWeather( 7 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Light Sky Partly Cloudy.");
break;
case "8":
SetWeather( 8 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To OverCast Partly Cloudy.");
break;
case "9":
SetWeather( 9 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Grey Sky Black Clouds." );
break;
case "10":
SetWeather( 10 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Fog And Gray.");
break;
}
}
}
Quote from: Mahmoud Tornado on Sep 02, 2017, 01:51 AMSet Weather
else if ( cmd == "setweather" )
{
if ( !text ) MessagePlayer( "[#ff0000]Usage: setweather [Weather/ID]", player );
else {
switch( text.tolower() )
{
case "4":
SetWeather( 4 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Sunny.");
break;
case "5":
SetWeather( 5 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Rainy.");
break;
case "0":
SetWeather( 0 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Clear Skies.");
break;
case "1":
SetWeather( 1 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To OverCast.");
break;
case "2":
SetWeather( 2 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Rainy-Lightning.");
break;
case "3":
SetWeather( 3 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Foggy.");
break;
case "6":
SetWeather( 6 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Dark Sky Partly Cloudy.");
break;
case "7":
SetWeather( 7 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Light Sky Partly Cloudy.");
break;
case "8":
SetWeather( 8 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To OverCast Partly Cloudy.");
break;
case "9":
SetWeather( 9 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Grey Sky Black Clouds." );
break;
case "10":
SetWeather( 10 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Fog And Gray.");
break;
}
}
}
Don't make it hard.
if ( cmd == "setweather" )
{
if ( !text ) return MessagePlayer( "[#ff0000]Usage: setweather [Weather/ID]", player );
if ( !IsNum(text) ) return MessagePlayer( "[#ff0000]Use integers/numbers", player );
SetWeather( text.tointeger() );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To "+GetWeatherName());
return;
}
function GetWeatherName( )
{
switch( GetWeather() )
{
case 0 : return "Clear Skies";
case 1 : return "OverCast";
case 2 : return "Rainy-Lightning";
case 3 : return "Foggy";
case 4 : return "Sunny";
case 5 : return "Rainy";
case 6 : return "Dark Sky Partly Cloudy";
case 7 : return "Light Sky Partly Cloudy";
case 8 : return "OverCast Partly Cloudy";
case 9 : return "Grey Sky Black Clouds";
case 10 : return "Fog And Gray";
default : return "Unknown";
}
}
Quote from: zeus on Sep 02, 2017, 05:57 AMQuote from: Mahmoud Tornado on Sep 02, 2017, 01:51 AMSet Weather
else if ( cmd == "setweather" )
{
if ( !text ) MessagePlayer( "[#ff0000]Usage: setweather [Weather/ID]", player );
else {
switch( text.tolower() )
{
case "4":
SetWeather( 4 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Sunny.");
break;
case "5":
SetWeather( 5 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Rainy.");
break;
case "0":
SetWeather( 0 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Clear Skies.");
break;
case "1":
SetWeather( 1 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To OverCast.");
break;
case "2":
SetWeather( 2 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Rainy-Lightning.");
break;
case "3":
SetWeather( 3 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Foggy.");
break;
case "6":
SetWeather( 6 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Dark Sky Partly Cloudy.");
break;
case "7":
SetWeather( 7 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Light Sky Partly Cloudy.");
break;
case "8":
SetWeather( 8 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To OverCast Partly Cloudy.");
break;
case "9":
SetWeather( 9 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Grey Sky Black Clouds." );
break;
case "10":
SetWeather( 10 );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To Fog And Gray.");
break;
}
}
}
Don't make it hard.
if ( cmd == "setweather" )
{
if ( !text ) return MessagePlayer( "[#ff0000]Usage: setweather [Weather/ID]", player );
if ( !IsNum(text) ) return MessagePlayer( "[#ff0000]Use integers/numbers", player );
SetWeather( text.tointeger() );
Message( "[#4acc0a] Admin "+ player.Name +" Set The Weather To "+GetWeatherName());
return;
}
function GetWeatherName( )
{
switch( GetWeather() )
{
case 0 : return "Clear Skies";
case 1 : return "OverCast";
case 2 : return "Rainy-Lightning";
case 3 : return "Foggy";
case 4 : return "Sunny";
case 5 : return "Rainy";
case 6 : return "Dark Sky Partly Cloudy";
case 7 : return "Light Sky Partly Cloudy";
case 8 : return "OverCast Partly Cloudy";
case 9 : return "Grey Sky Black Clouds";
case 10 : return "Fog And Gray";
default : return "Unknown";
}
}
Oh Thx :D
Okay Here You Are Gotoloc And Saveloc { With Database }
https://forum.vc-mp.org/?topic=5131
And You Will See The Settime And Setweather Up This Post :D
Quote from: Mahmoud Tornado on Sep 10, 2017, 01:55 PMOkay Here You Are Gotoloc And Saveloc { With Database }
https://forum.vc-mp.org/?topic=5131
And You Will See The Settime And Setweather Up This Post :D
Thanks for other codes. I get error in this gotoloc and saveloc. This error comes in both just the onplayercommand line number is different
(https://image.ibb.co/g9RMm5/Capture.png)
Quote from: umar4911 on Sep 17, 2017, 08:48 AMQuote from: Mahmoud Tornado on Sep 10, 2017, 01:55 PMOkay Here You Are Gotoloc And Saveloc { With Database }
https://forum.vc-mp.org/?topic=5131
And You Will See The Settime And Setweather Up This Post :D
Thanks for other codes. I get error in this gotoloc and saveloc. This error comes in both just the onplayercommand line number is different
(https://image.ibb.co/g9RMm5/Capture.png)
lol it working with me.
can you give me pic for the problem ?
Just read the error ONCE by yourself, if you still cannot understand it, please quit scripting.
Quote from: Xmair on Sep 17, 2017, 12:51 PMJust read the error ONCE by yourself, if you still cannot understand it, please quit scripting.
me ?
Quote from: Mahmoud Tornado on Sep 17, 2017, 01:07 PMQuote from: Xmair on Sep 17, 2017, 12:51 PMJust read the error ONCE by yourself, if you still cannot understand it, please quit scripting.
me ?
No.
function onPlayerCommand(player, command, arguments)
else if ( cmd == "settime" )
wtf?
Quote from: kennedyarz on Sep 17, 2017, 01:19 PMfunction onPlayerCommand(player, command, arguments)
else if ( cmd == "settime" )
wtf?
xD
I also have this in my code:
local cmd, text;
cmd = command.tolower();
text = arguments;
Quote from: Xmair on Sep 17, 2017, 12:51 PMJust read the error ONCE by yourself, if you still cannot understand it, please quit scripting.
xD I think that too. I am new in squirrel so I am facing these problems. Now please help me. I really cannot find the error. xD
Expected "userdata" got "null". Tell me what is difficult in understanding this line.
Quote from: Xmair on Sep 17, 2017, 03:25 PMExpected "userdata" got "null". Tell me what is difficult in understanding this line.
hmm.... What does it mean??
Quote from: umar4911 on Sep 17, 2017, 03:26 PMQuote from: Xmair on Sep 17, 2017, 03:25 PMExpected "userdata" got "null". Tell me what is difficult in understanding this line.
hmm.... What does it mean??
it means it expected a userdata type, but got null.
Quote from: umar4911 on Sep 17, 2017, 03:26 PMhmm.... What does it mean??
The problem might be in the query or either you are messing wrong through locals.Post complete error for help.
No one can help you with this.Post LOCALS too
Quote from: umar4911 on Sep 17, 2017, 08:48 AM(https://image.ibb.co/g9RMm5/Capture.png)