Skin System

Started by Thomas Br, May 12, 2016, 05:43 PM

Previous topic - Next topic

Thomas Br

hello, was willing to create a system for buying and selling skins, I managed to create and decided to share here in the forum for those who want to use

Add in main.nut


function onScriptLoad()
{
db <- ConnectSQL( "DataBase.db" );

QuerySQL( db, "CREATE TABLE IF NOT EXISTS Skins ( Name TEXT, Skin NUMERIC )" );
}

function onPlayerSpawn( player )
{
LoadSkin(player);
}

function onPlayerCommand( player, cmd, text )

else if ( cmd == "buyskin" )
{
local Pos = player.Pos, checkpoly;
checkpoly = InPoly( Pos.x, Pos.y, 424.555, 1017.27, 424.379, 1040.05, 403.933, 1040.42, 403.947, 1017.15);
if( !checkpoly ) MessagePlayer( "You need this in the gash store in the mall to buy skins.", player );
else if ( !text ) MessagePlayer ( "Syntax "+ cmd + " <Skin>", player );
else if ( player.Cash <= 100000 ) MessagePlayer( "Insufficient funds.", player );
else
{
local skin = GetTok( text, " ", 1);
if ( skin.tointeger() == 1 || skin.tointeger() == 2 || skin.tointeger() == 3 || skin.tointeger() == 4 || skin.tointeger() == 97 || skin.tointeger() == 98 || skin.tointeger() == 99 || skin.tointeger() == 100 || skin.tointeger() == 101 || skin.tointeger() == 102 || skin.tointeger() == 156 ) MessagePlayer( "Locked Skin .", player );
else if ( skin.tointeger() < 1 || skin.tointeger() > 195 ) MessagePlayer( "Use numbers 1-195 for skins.", player );
else
{
MessagePlayer( "Skin purchased! Price: $100000.", player );
MessagePlayer( "Use /useskin to use this skin or /sellskin to sell it .", player );
player.Cash -= 100000 ;
AddSkin( player, skin );
}
}
}

else if ( cmd == "useskin )
{
if ( !player.IsSpawned ) MessagePlayer("Choose a first skin.", player );
else if ( player.Vehicle ) MessagePlayer(" You can not use this command in a vehicle.", player );
else if ( skin(player) == 0 ) MessagePlayer("You do not have skins.", player );
else
{
MessagePlayer("Changed clothes.", player );
LoadSkin(player);
}
}

else if ( cmd == "sellskin" )
{
if ( !player.IsSpawned ) MessagePlayer("Choose a first skin.", player );
else if ( player.Vehicle ) MessagePlayer(" You can not use this command in a vehicle.", player );
else if ( skin(player) == 0 ) MessagePlayer("You do not have skins.", player );
else
{
MessagePlayer( "Skin sold! Price: $50000.", player );
player.Cash += 50000;
DelSkin( player );
}
}

Add in functions.nut

function AddSkin( player, skin )
{
if ( ( skin ) && IsNum( skin ) ) skin = skin.tointeger();
else if ( skin ) skin = GetSkinID( skin );
QuerySQL( db, "DELETE FROM Skins WHERE Name='" + player.Name + "'" );
QuerySQL( db, "INSERT INTO Skins ( Name, Skin ) VALUES ( '" + player.Name + "', '" + skin + "')" );
}

function DelSkin( player )
{
QuerySQL( db, "DELETE FROM Skins WHERE Name='" + player.Name + "'" );
}

function skin( player )
{
local skin =  GetSQLColumnData( QuerySQL( db, "SELECT Skin FROM Skins WHERE Name='" + player.Name + "'" ), 0 );
if ( skin ) return skin;
else return 0;
}

function LoadSkin( player )
{
if ( skin(player) == 0 ) player.Skin = 0 ;
else if ( skin(player) == 1 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( skin(player) == 2 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( skin(player) == 3 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( skin(player) == 4 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( skin(player) == 5 ) player.Skin = 5 ;
else if ( skin(player) == 6 ) player.Skin = 6 ;
else if ( skin(player) == 7 ) player.Skin = 7 ;
else if ( skin(player) == 8 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( skin(player) == 9 ) player.Skin = 9 ;
else if ( skin(player) == 10 ) player.Skin = 10 ;
else if ( skin(player) == 11 ) player.Skin = 11 ;
else if ( skin(player) == 12 ) player.Skin = 12 ;
else if ( skin(player) == 13 ) player.Skin = 13 ;
else if ( skin(player) == 14 ) player.Skin = 14 ;
else if ( skin(player) == 15 ) player.Skin = 15 ;
else if ( skin(player) == 16 ) player.Skin = 16 ;
else if ( skin(player) == 17 ) player.Skin = 17 ;
else if ( skin(player) == 18 ) player.Skin = 18 ;
else if ( skin(player) == 19 ) player.Skin = 19 ;
else if ( skin(player) == 20 ) player.Skin = 20 ;
else if ( skin(player) == 21 ) player.Skin = 21 ;
else if ( skin(player) == 22 ) player.Skin = 22 ;
else if ( skin(player) == 23 ) player.Skin = 23 ;
else if ( skin(player) == 24 ) player.Skin = 24 ;
else if ( skin(player) == 25 ) player.Skin = 25 ;
else if ( skin(player) == 26 ) player.Skin = 26 ;
else if ( skin(player) == 27 ) player.Skin = 27 ;
else if ( skin(player) == 28 ) player.Skin = 28 ;
else if ( skin(player) == 29 ) player.Skin = 29 ;
else if ( skin(player) == 30 ) player.Skin = 30 ;
else if ( skin(player) == 31 ) player.Skin = 31 ;
else if ( skin(player) == 32 ) player.Skin = 32 ;
else if ( skin(player) == 33 ) player.Skin = 33 ;
else if ( skin(player) == 34 ) player.Skin = 34 ;
else if ( skin(player) == 35 ) player.Skin = 35 ;
else if ( skin(player) == 36 ) player.Skin = 36 ;
else if ( skin(player) == 37 ) player.Skin = 37 ;
else if ( skin(player) == 38 ) player.Skin = 38 ;
else if ( skin(player) == 39 ) player.Skin = 39 ;
else if ( skin(player) == 40 ) player.Skin = 40 ;
else if ( skin(player) == 41 ) player.Skin = 41 ;
else if ( skin(player) == 42 ) player.Skin = 42 ;
else if ( skin(player) == 43 ) player.Skin = 43 ;
else if ( skin(player) == 44 ) player.Skin = 44 ;
else if ( skin(player) == 45 ) player.Skin = 45 ;
else if ( skin(player) == 46 ) player.Skin = 46 ;
else if ( skin(player) == 47 ) player.Skin = 47 ;
else if ( skin(player) == 48 ) player.Skin = 48 ;
else if ( skin(player) == 49 ) player.Skin = 49 ;
else if ( skin(player) == 50 ) player.Skin = 50 ;
else if ( skin(player) == 51 ) player.Skin = 51 ;
else if ( skin(player) == 52 ) player.Skin = 52 ;
else if ( skin(player) == 53 ) player.Skin = 53 ;
else if ( skin(player) == 54 ) player.Skin = 54 ;
else if ( skin(player) == 55 ) player.Skin = 55 ;
else if ( skin(player) == 56 ) player.Skin = 56 ;
else if ( skin(player) == 57 ) player.Skin = 57 ;
else if ( skin(player) == 58 ) player.Skin = 58 ;
else if ( skin(player) == 59 ) player.Skin = 59 ;
else if ( skin(player) == 60 ) player.Skin = 60 ;
else if ( skin(player) == 61 ) player.Skin = 61 ;
else if ( skin(player) == 62 ) player.Skin = 62 ;
else if ( skin(player) == 63 ) player.Skin = 63 ;
else if ( skin(player) == 64 ) player.Skin = 64 ;
else if ( skin(player) == 65 ) player.Skin = 65 ;
else if ( skin(player) == 66 ) player.Skin = 66 ;
else if ( skin(player) == 67 ) player.Skin = 67 ;
else if ( skin(player) == 68 ) player.Skin = 68 ;
else if ( skin(player) == 69 ) player.Skin = 69 ;
else if ( skin(player) == 70 ) player.Skin = 70 ;
else if ( skin(player) == 71 ) player.Skin = 71 ;
else if ( skin(player) == 72 ) player.Skin = 72 ;
else if ( skin(player) == 73 ) player.Skin = 73 ;
else if ( skin(player) == 74 ) player.Skin = 74 ;
else if ( skin(player) == 75 ) player.Skin = 75 ;
else if ( skin(player) == 76 ) player.Skin = 76 ;
else if ( skin(player) == 77 ) player.Skin = 77 ;
else if ( skin(player) == 78 ) player.Skin = 78 ;
else if ( skin(player) == 79 ) player.Skin = 79 ;
else if ( skin(player) == 80 ) player.Skin = 80 ;
else if ( skin(player) == 81 ) player.Skin = 81 ;
else if ( skin(player) == 82 ) player.Skin = 82 ;
else if ( skin(player) == 83 ) player.Skin = 83 ;
else if ( skin(player) == 84 ) player.Skin = 84 ;
else if ( skin(player) == 85 ) player.Skin = 85 ;
else if ( skin(player) == 86 ) player.Skin = 86 ;
else if ( skin(player) == 87 ) player.Skin = 87 ;
else if ( skin(player) == 88 ) player.Skin = 88 ;
else if ( skin(player) == 89 ) player.Skin = 89 ;
else if ( skin(player) == 90 ) player.Skin = 90 ;
else if ( skin(player) == 91 ) player.Skin = 91 ;
else if ( skin(player) == 92 ) player.Skin = 92 ;
else if ( skin(player) == 93 ) player.Skin = 93 ;
else if ( skin(player) == 94 ) player.Skin = 94 ;
else if ( skin(player) == 95 ) player.Skin = 95 ;
else if ( skin(player) == 96 ) player.Skin = 96 ;
else if ( skin(player) == 97 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( skin(player) == 98 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( skin(player) == 99 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( skin(player) == 100 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( skin(player) == 101 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( skin(player) == 102 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( skin(player) == 103 ) player.Skin = 103 ;
else if ( skin(player) == 104 ) player.Skin = 104 ;
else if ( skin(player) == 105 ) player.Skin = 105 ;
else if ( skin(player) == 106 ) player.Skin = 106 ;
else if ( skin(player) == 107 ) player.Skin = 107 ;
else if ( skin(player) == 108 ) player.Skin = 108 ;
else if ( skin(player) == 109 ) player.Skin = 109 ;
else if ( skin(player) == 110 ) player.Skin = 110 ;
else if ( skin(player) == 111 ) player.Skin = 111 ;
else if ( skin(player) == 112 ) player.Skin = 112 ;
else if ( skin(player) == 113 ) player.Skin = 113 ;
else if ( skin(player) == 114 ) player.Skin = 114 ;
else if ( skin(player) == 115 ) player.Skin = 115 ;
else if ( skin(player) == 116 ) player.Skin = 116 ;
else if ( skin(player) == 117 ) player.Skin = 117 ;
else if ( skin(player) == 118 ) player.Skin = 118 ;
else if ( skin(player) == 119 ) player.Skin = 119 ;
else if ( skin(player) == 120 ) player.Skin = 120 ;
else if ( skin(player) == 121 ) player.Skin = 121 ;
else if ( skin(player) == 122 ) player.Skin = 122 ;
else if ( skin(player) == 123 ) player.Skin = 123 ;
else if ( skin(player) == 124 ) player.Skin = 124 ;
else if ( skin(player) == 125 ) player.Skin = 125 ;
else if ( skin(player) == 126 ) player.Skin = 126 ;
else if ( skin(player) == 127 ) player.Skin = 127 ;
else if ( skin(player) == 128 ) player.Skin = 128 ;
else if ( skin(player) == 129 ) player.Skin = 129 ;
else if ( skin(player) == 130 ) player.Skin = 130 ;
else if ( skin(player) == 131 ) player.Skin = 131 ;
else if ( skin(player) == 132 ) player.Skin = 132 ;
else if ( skin(player) == 133 ) player.Skin = 133 ;
else if ( skin(player) == 134 ) player.Skin = 134 ;
else if ( skin(player) == 135 ) player.Skin = 135 ;
else if ( skin(player) == 136 ) player.Skin = 136 ;
else if ( skin(player) == 137 ) player.Skin = 137 ;
else if ( skin(player) == 138 ) player.Skin = 138 ;
else if ( skin(player) == 139 ) player.Skin = 139 ;
else if ( skin(player) == 140 ) player.Skin = 140 ;
else if ( skin(player) == 141 ) player.Skin = 141 ;
else if ( skin(player) == 142 ) player.Skin = 142 ;
else if ( skin(player) == 143 ) player.Skin = 143 ;
else if ( skin(player) == 144 ) player.Skin = 144 ;
else if ( skin(player) == 145 ) player.Skin = 145 ;
else if ( skin(player) == 146 ) player.Skin = 146 ;
else if ( skin(player) == 147 ) player.Skin = 147 ;
else if ( skin(player) == 148 ) player.Skin = 148 ;
else if ( skin(player) == 149 ) player.Skin = 149 ;
else if ( skin(player) == 150 ) player.Skin = 150 ;
else if ( skin(player) == 151 ) player.Skin = 151 ;
else if ( skin(player) == 152 ) player.Skin = 152 ;
else if ( skin(player) == 153 ) player.Skin = 153 ;
else if ( skin(player) == 154 ) player.Skin = 154 ;
else if ( skin(player) == 155 ) player.Skin = 155 ;
else if ( skin(player) == 156 ) player.Skin = 156 ;
else if ( skin(player) == 157 ) player.Skin = 157 ;
else if ( skin(player) == 158 ) player.Skin = 158 ;
else if ( skin(player) == 159 ) player.Skin = 159 ;
else if ( skin(player) == 160 ) player.Skin = 160 ;
else if ( skin(player) == 161 ) player.Skin = 161 ;
else if ( skin(player) == 162 ) player.Skin = 162 ;
else if ( skin(player) == 163 ) player.Skin = 163 ;
else if ( skin(player) == 164 ) player.Skin = 164 ;
else if ( skin(player) == 165 ) player.Skin = 165 ;
else if ( skin(player) == 166 ) player.Skin = 166 ;
else if ( skin(player) == 167 ) player.Skin = 167 ;
else if ( skin(player) == 168 ) player.Skin = 168 ;
else if ( skin(player) == 169 ) player.Skin = 169 ;
else if ( skin(player) == 170 ) player.Skin = 170 ;
else if ( skin(player) == 171 ) player.Skin = 171 ;
else if ( skin(player) == 172 ) player.Skin = 172 ;
else if ( skin(player) == 173 ) player.Skin = 173 ;
else if ( skin(player) == 174 ) player.Skin = 174 ;
else if ( skin(player) == 175 ) player.Skin = 175 ;
else if ( skin(player) == 176 ) player.Skin = 176 ;
else if ( skin(player) == 177 ) player.Skin = 177 ;
else if ( skin(player) == 178 ) player.Skin = 178 ;
else if ( skin(player) == 179 ) player.Skin = 179 ;
else if ( skin(player) == 180 ) player.Skin = 180 ;
else if ( skin(player) == 181 ) player.Skin = 181 ;
else if ( skin(player) == 182 ) player.Skin = 182 ;
else if ( skin(player) == 183 ) player.Skin = 183 ;
else if ( skin(player) == 184 ) player.Skin = 184 ;
else if ( skin(player) == 185 ) player.Skin = 185 ;
else if ( skin(player) == 186 ) player.Skin = 186 ;
else if ( skin(player) == 187 ) player.Skin = 187 ;
else if ( skin(player) == 188 ) player.Skin = 188 ;
else if ( skin(player) == 189 ) player.Skin = 189 ;
else if ( skin(player) == 190 ) player.Skin = 190 ;
else if ( skin(player) == 191 ) player.Skin = 191 ;
else if ( skin(player) == 192 ) player.Skin = 192 ;
else if ( skin(player) == 193 ) player.Skin = 193 ;
else if ( skin(player) == 194 ) player.Skin = 194 ;
else if ( skin(player) == 195 ) player.Skin = 195 ;
}

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();
}

If there is any bug comment down there to try to correct, good luck!

Thomas Br

Correct the error, the next time I will use code  in topics

aXXo

Inefficient programming.

Firstly, lets talk about your LoadSkin function.

You are calling the skin(player) function 196 times(worst case). This function queries a database and reads a value from your hard disk 196 times. Reading from hard disk is much slower than reading from a local variable in your RAM.

It is better to read from the database only once:
local savedSkin = skin(player);
Then, use savedSkin == 1 in your if, else if comparisons conditions 196 times.
function LoadSkin( player )
{

local savedSkin = skin(player);

if ( savedSkin == 0 ) player.Skin = 0 ;
else if ( savedSkin == 1 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( savedSkin == 2 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( savedSkin == 3 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( savedSkin == 4 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( savedSkin == 5 ) player.Skin = 5 ;
else if ( savedSkin == 6 ) player.Skin = 6 ;
else if ( savedSkin == 7 ) player.Skin = 7 ;
else if ( savedSkin == 8 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( savedSkin == 9 ) player.Skin = 9 ;
else if ( savedSkin == 10 ) player.Skin = 10 ;
else if ( savedSkin == 11 ) player.Skin = 11 ;
else if ( savedSkin == 12 ) player.Skin = 12 ;
else if ( savedSkin == 13 ) player.Skin = 13 ;
else if ( savedSkin == 14 ) player.Skin = 14 ;
else if ( savedSkin == 15 ) player.Skin = 15 ;
else if ( savedSkin == 16 ) player.Skin = 16 ;
else if ( savedSkin == 17 ) player.Skin = 17 ;
else if ( savedSkin == 18 ) player.Skin = 18 ;
else if ( savedSkin == 19 ) player.Skin = 19 ;
else if ( savedSkin == 20 ) player.Skin = 20 ;
else if ( savedSkin == 21 ) player.Skin = 21 ;
else if ( savedSkin == 22 ) player.Skin = 22 ;
else if ( savedSkin == 23 ) player.Skin = 23 ;
else if ( savedSkin == 24 ) player.Skin = 24 ;
else if ( savedSkin == 25 ) player.Skin = 25 ;
else if ( savedSkin == 26 ) player.Skin = 26 ;
else if ( savedSkin == 27 ) player.Skin = 27 ;
else if ( savedSkin == 28 ) player.Skin = 28 ;
else if ( savedSkin == 29 ) player.Skin = 29 ;
else if ( savedSkin == 30 ) player.Skin = 30 ;
else if ( savedSkin == 31 ) player.Skin = 31 ;
else if ( savedSkin == 32 ) player.Skin = 32 ;
else if ( savedSkin == 33 ) player.Skin = 33 ;
else if ( savedSkin == 34 ) player.Skin = 34 ;
else if ( savedSkin == 35 ) player.Skin = 35 ;
else if ( savedSkin == 36 ) player.Skin = 36 ;
else if ( savedSkin == 37 ) player.Skin = 37 ;
else if ( savedSkin == 38 ) player.Skin = 38 ;
else if ( savedSkin == 39 ) player.Skin = 39 ;
else if ( savedSkin == 40 ) player.Skin = 40 ;
else if ( savedSkin == 41 ) player.Skin = 41 ;
else if ( savedSkin == 42 ) player.Skin = 42 ;
else if ( savedSkin == 43 ) player.Skin = 43 ;
else if ( savedSkin == 44 ) player.Skin = 44 ;
else if ( savedSkin == 45 ) player.Skin = 45 ;
else if ( savedSkin == 46 ) player.Skin = 46 ;
else if ( savedSkin == 47 ) player.Skin = 47 ;
else if ( savedSkin == 48 ) player.Skin = 48 ;
else if ( savedSkin == 49 ) player.Skin = 49 ;
else if ( savedSkin == 50 ) player.Skin = 50 ;
else if ( savedSkin == 51 ) player.Skin = 51 ;
else if ( savedSkin == 52 ) player.Skin = 52 ;
else if ( savedSkin == 53 ) player.Skin = 53 ;
else if ( savedSkin == 54 ) player.Skin = 54 ;
else if ( savedSkin == 55 ) player.Skin = 55 ;
else if ( savedSkin == 56 ) player.Skin = 56 ;
else if ( savedSkin == 57 ) player.Skin = 57 ;
else if ( savedSkin == 58 ) player.Skin = 58 ;
else if ( savedSkin == 59 ) player.Skin = 59 ;
else if ( savedSkin == 60 ) player.Skin = 60 ;
else if ( savedSkin == 61 ) player.Skin = 61 ;
else if ( savedSkin == 62 ) player.Skin = 62 ;
else if ( savedSkin == 63 ) player.Skin = 63 ;
else if ( savedSkin == 64 ) player.Skin = 64 ;
else if ( savedSkin == 65 ) player.Skin = 65 ;
else if ( savedSkin == 66 ) player.Skin = 66 ;
else if ( savedSkin == 67 ) player.Skin = 67 ;
else if ( savedSkin == 68 ) player.Skin = 68 ;
else if ( savedSkin == 69 ) player.Skin = 69 ;
else if ( savedSkin == 70 ) player.Skin = 70 ;
else if ( savedSkin == 71 ) player.Skin = 71 ;
else if ( savedSkin == 72 ) player.Skin = 72 ;
else if ( savedSkin == 73 ) player.Skin = 73 ;
else if ( savedSkin == 74 ) player.Skin = 74 ;
else if ( savedSkin == 75 ) player.Skin = 75 ;
else if ( savedSkin == 76 ) player.Skin = 76 ;
else if ( savedSkin == 77 ) player.Skin = 77 ;
else if ( savedSkin == 78 ) player.Skin = 78 ;
else if ( savedSkin == 79 ) player.Skin = 79 ;
else if ( savedSkin == 80 ) player.Skin = 80 ;
else if ( savedSkin == 81 ) player.Skin = 81 ;
else if ( savedSkin == 82 ) player.Skin = 82 ;
else if ( savedSkin == 83 ) player.Skin = 83 ;
else if ( savedSkin == 84 ) player.Skin = 84 ;
else if ( savedSkin == 85 ) player.Skin = 85 ;
else if ( savedSkin == 86 ) player.Skin = 86 ;
else if ( savedSkin == 87 ) player.Skin = 87 ;
else if ( savedSkin == 88 ) player.Skin = 88 ;
else if ( savedSkin == 89 ) player.Skin = 89 ;
else if ( savedSkin == 90 ) player.Skin = 90 ;
else if ( savedSkin == 91 ) player.Skin = 91 ;
else if ( savedSkin == 92 ) player.Skin = 92 ;
else if ( savedSkin == 93 ) player.Skin = 93 ;
else if ( savedSkin == 94 ) player.Skin = 94 ;
else if ( savedSkin == 95 ) player.Skin = 95 ;
else if ( savedSkin == 96 ) player.Skin = 96 ;
else if ( savedSkin == 97 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( savedSkin == 98 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( savedSkin == 99 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( savedSkin == 100 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( savedSkin == 101 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( savedSkin == 102 ) QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
else if ( savedSkin == 103 ) player.Skin = 103 ;
else if ( savedSkin == 104 ) player.Skin = 104 ;
else if ( savedSkin == 105 ) player.Skin = 105 ;
else if ( savedSkin == 106 ) player.Skin = 106 ;
else if ( savedSkin == 107 ) player.Skin = 107 ;
else if ( savedSkin == 108 ) player.Skin = 108 ;
else if ( savedSkin == 109 ) player.Skin = 109 ;
else if ( savedSkin == 110 ) player.Skin = 110 ;
else if ( savedSkin == 111 ) player.Skin = 111 ;
else if ( savedSkin == 112 ) player.Skin = 112 ;
else if ( savedSkin == 113 ) player.Skin = 113 ;
else if ( savedSkin == 114 ) player.Skin = 114 ;
else if ( savedSkin == 115 ) player.Skin = 115 ;
else if ( savedSkin == 116 ) player.Skin = 116 ;
else if ( savedSkin == 117 ) player.Skin = 117 ;
else if ( savedSkin == 118 ) player.Skin = 118 ;
else if ( savedSkin == 119 ) player.Skin = 119 ;
else if ( savedSkin == 120 ) player.Skin = 120 ;
else if ( savedSkin == 121 ) player.Skin = 121 ;
else if ( savedSkin == 122 ) player.Skin = 122 ;
else if ( savedSkin == 123 ) player.Skin = 123 ;
else if ( savedSkin == 124 ) player.Skin = 124 ;
else if ( savedSkin == 125 ) player.Skin = 125 ;
else if ( savedSkin == 126 ) player.Skin = 126 ;
else if ( savedSkin == 127 ) player.Skin = 127 ;
else if ( savedSkin == 128 ) player.Skin = 128 ;
else if ( savedSkin == 129 ) player.Skin = 129 ;
else if ( savedSkin == 130 ) player.Skin = 130 ;
else if ( savedSkin == 131 ) player.Skin = 131 ;
else if ( savedSkin == 132 ) player.Skin = 132 ;
else if ( savedSkin == 133 ) player.Skin = 133 ;
else if ( savedSkin == 134 ) player.Skin = 134 ;
else if ( savedSkin == 135 ) player.Skin = 135 ;
else if ( savedSkin == 136 ) player.Skin = 136 ;
else if ( savedSkin == 137 ) player.Skin = 137 ;
else if ( savedSkin == 138 ) player.Skin = 138 ;
else if ( savedSkin == 139 ) player.Skin = 139 ;
else if ( savedSkin == 140 ) player.Skin = 140 ;
else if ( savedSkin == 141 ) player.Skin = 141 ;
else if ( savedSkin == 142 ) player.Skin = 142 ;
else if ( savedSkin == 143 ) player.Skin = 143 ;
else if ( savedSkin == 144 ) player.Skin = 144 ;
else if ( savedSkin == 145 ) player.Skin = 145 ;
else if ( savedSkin == 146 ) player.Skin = 146 ;
else if ( savedSkin == 147 ) player.Skin = 147 ;
else if ( savedSkin == 148 ) player.Skin = 148 ;
else if ( savedSkin == 149 ) player.Skin = 149 ;
else if ( savedSkin == 150 ) player.Skin = 150 ;
else if ( savedSkin == 151 ) player.Skin = 151 ;
else if ( savedSkin == 152 ) player.Skin = 152 ;
else if ( savedSkin == 153 ) player.Skin = 153 ;
else if ( savedSkin == 154 ) player.Skin = 154 ;
else if ( savedSkin == 155 ) player.Skin = 155 ;
else if ( savedSkin == 156 ) player.Skin = 156 ;
else if ( savedSkin == 157 ) player.Skin = 157 ;
else if ( savedSkin == 158 ) player.Skin = 158 ;
else if ( savedSkin == 159 ) player.Skin = 159 ;
else if ( savedSkin == 160 ) player.Skin = 160 ;
else if ( savedSkin == 161 ) player.Skin = 161 ;
else if ( savedSkin == 162 ) player.Skin = 162 ;
else if ( savedSkin == 163 ) player.Skin = 163 ;
else if ( savedSkin == 164 ) player.Skin = 164 ;
else if ( savedSkin == 165 ) player.Skin = 165 ;
else if ( savedSkin == 166 ) player.Skin = 166 ;
else if ( savedSkin == 167 ) player.Skin = 167 ;
else if ( savedSkin == 168 ) player.Skin = 168 ;
else if ( savedSkin == 169 ) player.Skin = 169 ;
else if ( savedSkin == 170 ) player.Skin = 170 ;
else if ( savedSkin == 171 ) player.Skin = 171 ;
else if ( savedSkin == 172 ) player.Skin = 172 ;
else if ( savedSkin == 173 ) player.Skin = 173 ;
else if ( savedSkin == 174 ) player.Skin = 174 ;
else if ( savedSkin == 175 ) player.Skin = 175 ;
else if ( savedSkin == 176 ) player.Skin = 176 ;
else if ( savedSkin == 177 ) player.Skin = 177 ;
else if ( savedSkin == 178 ) player.Skin = 178 ;
else if ( savedSkin == 179 ) player.Skin = 179 ;
else if ( savedSkin == 180 ) player.Skin = 180 ;
else if ( savedSkin == 181 ) player.Skin = 181 ;
else if ( savedSkin == 182 ) player.Skin = 182 ;
else if ( savedSkin == 183 ) player.Skin = 183 ;
else if ( savedSkin == 184 ) player.Skin = 184 ;
else if ( savedSkin == 185 ) player.Skin = 185 ;
else if ( savedSkin == 186 ) player.Skin = 186 ;
else if ( savedSkin == 187 ) player.Skin = 187 ;
else if ( savedSkin == 188 ) player.Skin = 188 ;
else if ( savedSkin == 189 ) player.Skin = 189 ;
else if ( savedSkin == 190 ) player.Skin = 190 ;
else if ( savedSkin == 191 ) player.Skin = 191 ;
else if ( savedSkin == 192 ) player.Skin = 192 ;
else if ( savedSkin == 193 ) player.Skin = 193 ;
else if ( savedSkin == 194 ) player.Skin = 194 ;
else if ( savedSkin == 195 ) player.Skin = 195 ;
}

A better and efficient way to do it, would be using a switch statement, but wait! We can do much better than a switch, since there seems to be a pattern in your search.

First, make an array list of skins that you want to delete:
local restrictedSkins = [1,2,3,4,8,97,98,99,100,101,102];

Now check if the saved skin is one of the restricted skins?
To check that we can use the array.find() method.
restrictedSkins.find()

Since we are finding the player skin, we will use:
local savedSkin = skin( player );
restrictedSkins.find(savedSkin)

This will try to find if the skin saved in the database is one of the restricted skin?
If it finds a value, it would return it's position in the array. If not, it will return null. Hence we can put a condition:
if( restrictedSkins.find(savedSkin) != null )
{
// Give the player the skin
}
else
{
//Delete the skin from database
}

So, our function now looks like:
function LoadSkin( player )
{
local restrictedSkins = [1,2,3,4,8,97,98,99,100,101,102];
local savedSkin = skin(player);

if( restrictedSkins.find(savedSkin) != null )
{
// Give the player the skin
player.Skin = savedSkin;
}
else
{
//Delete the skin from database
QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
}
}

Looks much prettier :)

Havent read the rest of your code.

KAKAN

And also, add a check whether the skin ID is less than 0 or more than 196.
So, the function would look like:
function LoadSkin( player )
{
local restrictedSkins = [1,2,3,4,8,97,98,99,100,101,102];
local savedSkin = skin(player);
if( restrictedSkins.find(savedSkin) != null && savedSkin >0 && savedSkin <196 )
{
// Give the player the skin
player.Skin = savedSkin;
}
else
{
//Delete the skin from database
QuerySQL( db, "DELETE FROM Skins WHERE Nome='" + player.Name + "'" );
}
}
It can still be improved, we can just query once, then load everything into an array and fetch things from it :)
oh no

W3aPoN^

Can we Use Custom Skins?

MacTavish

Congratulation for bumping a 7 months old topic and yeah you can use custom skins with the same way

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P