function delete_player($name) { $SQL = $GLOBALS['SQL']; $player = new OTS_Player(); $player->find($name); if ($player->isLoaded()) { try { $SQL->query("DELETE FROM player_skills WHERE player_id = '" . $player->getId() . "';"); } catch (PDOException $error) { } try { $SQL->query("DELETE FROM guild_invites WHERE player_id = '" . $player->getId() . "';"); } catch (PDOException $error) { } try { $SQL->query("DELETE FROM player_items WHERE player_id = '" . $player->getId() . "';"); } catch (PDOException $error) { } try { $SQL->query("DELETE FROM player_depotitems WHERE player_id = '" . $player->getId() . "';"); } catch (PDOException $error) { } try { $SQL->query("DELETE FROM player_spells WHERE player_id = '" . $player->getId() . "';"); } catch (PDOException $error) { } try { $SQL->query("DELETE FROM player_storage WHERE player_id = '" . $player->getId() . "';"); } catch (PDOException $error) { } try { $SQL->query("DELETE FROM player_viplist WHERE player_id = '" . $player->getId() . "';"); } catch (PDOException $error) { } try { $SQL->query("DELETE FROM player_deaths WHERE player_id = '" . $player->getId() . "';"); } catch (PDOException $error) { } try { $SQL->query("DELETE FROM player_deaths WHERE killed_by = '" . $player->getId() . "';"); } catch (PDOException $error) { } $rank = $player->getRank(); if (!empty($rank)) { $guild = $rank->getGuild(); if ($guild->getOwner()->getId() == $player->getId()) { $rank_list = $guild->getGuildRanksList(); if (count($rank_list) > 0) { $rank_list->orderBy('level'); foreach ($rank_list as $rank_in_guild) { $players_with_rank = $rank_in_guild->getPlayersList(); $players_with_rank->orderBy('name'); $players_with_rank_number = count($players_with_rank); if ($players_with_rank_number > 0) { foreach ($players_with_rank as $player_in_guild) { $player_in_guild->setRank(); $player_in_guild->save(); } } $rank_in_guild->delete(); } $guild->delete(); } } } $player->delete(); return TRUE; } }
<?php // to not repeat all that stuff include 'quickstart.php'; // creates new player object $player = new OTS_Player('Wrzasq'); // deletes player $player->delete(); // as player was deleted this will insert new row into database but all data will be restored $player->save();