• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Gesior AAC]Admin Teleporter Player

gpedro

web developer
Joined
Dec 5, 2009
Messages
165
Reaction score
520
Location
Brazil
GitHub
gpedro
;)
veug40.png

1zpthcw.png
SQL PHPMYADMIN
PHP:
ALTER TABLE players ADD  `t_x` int(11) NOT NULL;
ALTER TABLE players ADD `t_y` int(11) NOT NULL;
ALTER TABLE players ADD `t_z` int(11) NOT NULL;
ALTER TABLE players ADD `t_active` int(11) NOT NULL;

teleport.php
PHP:
<script language="JavaScript">
function onlyNumbers(evt)
{
	var e = event || evt; // for trans-browser compatibility
	var charCode = e.which || e.keyCode;

	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

	return true;

}

function onlyText(e) {
var k;
document.all ? k = e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8);
}
</script>
<?PHP
header("Content-Type: text/html; charset=ISO-8859-1",true) ;
if($group_id_of_acc_logged >= $config['site']['access_admin_panel']) {
	if($action == "") {
		 $main_content .= '<FORM ACTION="?subtopic=buypoints&action=search" METHOD=post><TABLE WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=4><TR><TD BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white><B>Search player to teleport</B></TD></TR><TR><TD BGCOLOR="'.$config['site']['darkborder'].'"><TABLE BORDER=0 CELLPADDING=1><TR><TD>
		</TD><TD><INPUT NAME="name" VALUE=""SIZE=29 MAXLENGTH=29 onkeypress="return onlyText(event)"></TD><TD><INPUT TYPE=image NAME="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18></TD></TR></TABLE></TD></TR></TABLE></FORM>';
	}
	if($action == 'search') {
	$name = $_POST['name'];
	$select = $SQL->query('SELECT * FROM players WHERE name = "'.$name.'";')->fetch();
	$x = $select['posx']; //actual position
	$y = $select['posy']; //actual position
	$z = $select['posz']; //actual position 
	$main_content .='<center><form action="?subtopic=buypoints&action=send" METHOD="POST"><TABLE WIDTH=80% BORDER=0 CELLSPACING=1 CELLPADDING=4><TR>
  <TD width="19%" BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white>Name</TD>
  <TD width="20%" BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white>Position X</TD>
  <TD width="20%" BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white>Position Y</TD>
  <TD width="20%" BGCOLOR="'.$config['site']['vdarkborder'].'" CLASS=white>Position Z</TD>
</TR><TR>
    <TD colspan="4" BGCOLOR="'.$config['site']['darkborder'].'">
    <TABLE width="100%" BORDER=0 CELLPADDING=1>
      <TR><TD width="19%">
	  <input name="name" value="'.$name.'" disabled />
	  <input name="name" value="'.$name.'" type="hidden"/></TD>
	  <TD width="20%"><input name="t_x" value="'.$x.'" minlength="1" onkeypress="return onlyNumbers();"/></TD>
	  <TD width="20%"><input name="t_y" value="'.$y.'" minlength="1" onkeypress="return onlyNumbers();"/></TD>
	  <TD width="20%"><input name="t_z" value="'.$z.'" minlength="1" onkeypress="return onlyNumbers();"/></TD></TR>
    </TABLE></TD>
    </TR></TABLE><br /><INPUT TYPE=image NAME="Submit" SRC="'.$layout_name.'/images/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18></form></center>';
	}
	if($action == 'send') {
		$name = $_POST['name'];
		$t_x = $_POST['t_x']; //position to teleport
		$t_y = $_POST['t_y']; //position to teleport
		$t_z = $_POST['t_z']; //position to teleport
		
		$SQL->query('UPDATE players SET t_x = "'.$t_x.'", t_y = "'.$t_y.'", t_z = "'.$t_z.'", t_active = "1" WHERE name = "'.$name.'";');
		$main_content .= 'The player '.$name.' has been teleported for success';
		}
	} else { $main_content .= 'You don\'t have admin access.'; }
?>

data/lib/functions.lua or 050-functions.lua
Code:
function isActive(cid)
local activecheck = db.getResult("SELECT `t_active` FROM `players` WHERE `name` = '"..getCreatureName(cid).."';")
local activeValue = activecheck:getDataInt('t_active')
return activeValue
end

function setActive(cid, act)
ac = (act and act or 0)
local actnow = db.getResult("SELECT `t_active` FROM `players` WHERE `name` = '".. getCreatureName(cid) .."';")
local getNow = actnow:getDataInt('t_active')
  return db.executeQuery("UPDATE `players` SET `t_active` = '".. act .."' WHERE `name` = '".. getCreatureName(cid) .."' ")
end

function getTeleportPosition(cid)

local takeX = db.getResult("SELECT `t_x` FROM `players` WHERE `name` = '".. getCreatureName(cid) .."';")
local getX = takeX:getDataInt('t_x')

local takeY = db.getResult("SELECT `t_y` FROM `players` WHERE `name` = '".. getCreatureName(cid) .."';")
local getY = takeY:getDataInt('t_y')

local takeZ = db.getResult("SELECT `t_z` FROM `players` WHERE `name` = '".. getCreatureName(cid) .."';")
local getZ = takeZ:getDataInt('t_z')

  return {x=getX, y=getY, z=getZ}
end

function setTeleportPosition(cid, x, y, z)

db.executeQuery("UPDATE `players` SET `t_x` = '".. x .."' WHERE `name` = '".. getCreatureName(cid) .."' ")
db.executeQuery("UPDATE `players` SET `t_y` = '".. y .."' WHERE `name` = '".. getCreatureName(cid) .."' ")
db.executeQuery("UPDATE `players` SET `t_z` = '".. z .."' WHERE `name` = '".. getCreatureName(cid) .."' ")

  return true
end

data/globalevents/globalevents.xml
Code:
<globalevent name="teleport" interval="60" event="script" value="teleport.lua"/>

data/globalevents/scripts/teleport.lua
Code:
function onThink(interval, lastExecution)

  for qqqq=1,#getOnlinePlayers() do
local cid = getCreatureByName(getOnlinePlayers()[qqqq])

if(isActive(cid) == 1) then
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_DEFAULT, "You has been teleported")
   setActive(cid, 0)
   doTeleportThing(cid, getTeleportPosition(cid))
end
end
return true
end
 
lib shortened
Lua:
function isActive(cid)
	local activecheck = db.getResult("SELECT `t_active` FROM `players` WHERE `name` = '"..getCreatureName(cid).."';")
	return (activecheck:getID() ~= -1 and activecheck:getDataInt('t_active') or false)
end

function setActive(cid, act)
	ac = (act or 0)
	local actnow = db.getResult("SELECT `t_active` FROM `players` WHERE `name` = '".. getCreatureName(cid) .."';")
	local getNow = (actnow:getID() ~= -1 and actnow:getDataInt('t_active') or 0)
	return db.executeQuery("UPDATE `players` SET `t_active` = '".. act .."' WHERE `name` = '".. getCreatureName(cid) .."' ") or false
end

function getTeleportPosition(cid)

	local take = db.getResult("SELECT `t_x`, `t_y`, `t_z` FROM `players` WHERE `name` = '".. getCreatureName(cid) .."';")
	return (take:getID() ~= -1 and {x = take:getDataInt("t_x"), y = take:getDataInt("t_y"), z = take:getDataInt("t_z") or {x = getCreaturePosition(cid).x, y = getCreaturePosition(cid).y, getCreaturePosition(cid).z}
end

function setTeleportPosition(cid, pos)

	return db.executeQuery("UPDATE `players` SET `t_x` = '".. pos.x .."', `t_y` = '" .. pos.y .. "', `t_z` = '" .. pos.z .. "' WHERE `name` = '".. getCreatureName(cid) .."' ")
end
 
each db.getResult should be freed, indexed column (id) should be used instead of name and this is a waste of calls
{x = getCreaturePosition(cid).x, y = getCreaturePosition(cid).y, getCreaturePosition(cid).z}
 
Lua:
for qqqq=1,#getOnlinePlayers() do
local cid = getCreatureByName(getOnlinePlayers()[qqqq])
Is OTS script or CPU benchmark?
Should be:
Lua:
for qqqq, cid in pairs(getOnlinePlayers()) do
 
Lua:
for qqqq=1,#getOnlinePlayers() do
local cid = getCreatureByName(getOnlinePlayers()[qqqq])
Is OTS script or CPU benchmark?
Should be:
Lua:
for qqqq, cid in pairs(getOnlinePlayers()) do

Why would you even assign key as variable if you ain't gonna use it?
Code:
for _, cid in pairs(getPlayersOnline()) do
 
Why would you even assign key as variable if you ain't gonna use it?
Code:
for _, cid in pairs(getPlayersOnline()) do

And _ is what? Lua treat this variable as any other. There is no difference between using qqqq or _ except appearance.

Sorry, had to bump this one to debunk this myth. The only thing it may be useful in, is when you don't know how to name a variable or when its not used in a loop, it just looks more elegant.
 
Back
Top