In Game AddClass with /addclass with Database

Started by EnForcer, Sep 18, 2020, 03:46 PM

Previous topic - Next topic

EnForcer

In Game addclass via cmd with Database
Credits: EnForcer


Commands: /addclass <Team ID> <R> <G> <B> <Skin ID>


Extra Note: If you encounter any bug, inform me here or on discord my ID : iNForSir#7490

Paste it in onscriptload
db <- ConnectSQL( "Classes.db" );
QuerySQL(db, "CREATE TABLE IF NOT EXISTS Creation ( Team NUMERIC, Skin NUMERIC, X NUMERIC, Y NUMERIC, Z NUMERIC, R NUMERIC, G NUMERIC, B NUMERIC, Angle NUMERIC)" );
LoadClass();

Function to Loadclass
function LoadClass()
{
local q = QuerySQL( db, "SELECT * FROM Creation" ), i = 0;
while( GetSQLColumnData( q, 0 ) )
{
local
Team= GetSQLColumnData( q, 0 ),
Skin= GetSQLColumnData( q, 1 ),
X= GetSQLColumnData( q, 2 ),
Y= GetSQLColumnData( q, 3 ),
Z= GetSQLColumnData( q, 4 ),
R= GetSQLColumnData( q, 5 ),
G= GetSQLColumnData( q, 6 ),
B= GetSQLColumnData( q, 7 ),
Angle= GetSQLColumnData( q, 8 );
AddClass( Team, RGB( R,G,B ), Skin, Vector( X,Y,Z ), Angle, 21, 999 ,1, 1, 25, 255 );
GetSQLNextRow( q );
i++;
}
print("Class Count ("+i+")");
return 0;
}

Paste it in onplayercommand

else if (cmd=="addclass")
{
if ( !player.IsSpawned ) MessagePlayer( "[#ff0000][Error] - [#ffffff]You need be spawned to use this command.", player );
else if( !text ) MessagePlayer( "[#ff0000][Error] - [#ffffff]Use /"+cmd+" <Team ID> <R> <G> <B> <Skin ID>.", player);
else {
local TeamID = GetTok( text, " ", 1 );
local R = GetTok( text, " ", 2 );
local G = GetTok( text, " ", 3 );
local B = GetTok( text, " ", 4 );
local SkinID = GetTok( text, " ", 5 );
if (!IsNum(TeamID)) MessagePlayer( "[#ff0000][Error] - [#ffffff]Use /"+cmd+" <Team ID> <R> <G> <B> <Skin ID>.", player);
else if ( !IsNum(R)) MessagePlayer( "[#ff0000][Error] - [#ffffff]Use /"+cmd+" <Team ID> <R> <G> <B> <Skin ID>.", player);
else if ( !IsNum(G)) MessagePlayer( "[#ff0000][Error] - [#ffffff]Use /"+cmd+" <Team ID> <R> <G> <B> <Skin ID>.", player);
else if ( !IsNum(B)) MessagePlayer( "[#ff0000][Error] - [#ffffff]Use /"+cmd+" <Team ID> <R> <G> <B> <Skin ID>.", player);
else if ( !IsNum(SkinID)) MessagePlayer( "[#ff0000][Error] - [#ffffff]Use /"+cmd+" <Team ID> <R> <G> <B> <Skin ID>.", player);
else if ( ( !TeamID ) || ( !R ) || (!G ) || ( !B ) || ( !SkinID ) ) MessagePlayer( "[#ff0000][Error] - [#ffffff]Use /"+cmd+" <Veh/ID> <Col1/ID> <Col2/ID> <World> <Price>.", player);
else {
QuerySQL( db, "INSERT INTO Creation ( Team, Skin, R, G, B, X, Y, Z, Angle ) VALUES ( '"+TeamID+"', '"+SkinID+"', '"+R+"', '"+G+"', '"+B+"', '"+player.Pos.x+"', '"+player.Pos.y+"', '"+player.Pos.z+"', '"+player.Angle+"' )" );
AddClass( TeamID.tointeger(), RGB( R.tointeger(), G.tointeger(), B.tointeger() ) ,SkinID.tointeger(), player.Pos, player.Angle, 22, 999 ,17, 100, 21, 245 );
Message( "[#FFFFFF]Admin [#FF0000]"+player.Name+" [#FFFFFF]Has added a new Class." );
     }
     }
return 0;
}

else if ( cmd == "removeclass" )
    {
if ( !text ) MessagePlayer( "[#ff0000][Error] - [#ffffff]Use /"+cmd+" <Skin ID>.", player);
else if (!IsNum(text)) MessagePlayer( "[#ff0000][Error] - [#ffffff]Skin ID must be in numbers.", player);
else {   
local q = QuerySQL( db, "SELECT * FROM Creation WHERE Skin='"+text+"'" );
if ( !q ) MessagePlayer( "[#ff0000][Error] - [#ffffff]Skin ID "+text+" not found in class.", player );
else {
QuerySQL( db, "DELETE FROM Creation WHERE Skin='"+text+"'" );
Message( "[#FFFFFF]Admin [#FF0000]"+player.Name+" [#FFFFFF]Has removed Class." );
     }
     }
return 0;
}

SHy^

1: What does this basically does( I understand but noobs won't)? We can also add the same sentence in ScriptLoad rather than database. So elaborate more what's the ease of it rather than putting in onScriptLoad( for noobs).

2: You have added stats[ player.ID ].Level, so if someone directly copy pastes the script so he/she will get errors about it. ( ex blank vcmp server ) so better remove it.

3: You haven't provided the requires function which you used ( GetTok ) so if someone directly copy pastes, he'll get the GetTok index error.

After all that, nice work.

EnForcer

Quote from: Shy on Sep 19, 2020, 11:35 AM1: What does this basically does( I understand but noobs won't)? We can also add the same sentence in ScriptLoad rather than database. So elaborate more what's the ease of it rather than putting in onScriptLoad( for noobs).
Its easy to use instead of getting axis of player pos/angle pos then copy paste it in scripts.

Quote from: Shy on Sep 19, 2020, 11:35 AM2: You have added stats[ player.ID ].Level, so if someone directly copy pastes the script so he/she will get errors about it. ( ex blank vcmp server ) so better remove it.
I will remove it
Quote from: Shy on Sep 19, 2020, 11:35 AM3: You haven't provided the requires function which you used ( GetTok ) so if someone directly copy pastes, he'll get the GetTok index error.
Well these Gettoks are common things so i didn't added.

habi

#3
link not working.
nice work.
imagine player going to some place and press some button. A simple menu appears. It has images of each skin......

I recently found that if player.Team=255 for two players and if one player shoots another, the health of the second player will be reduced. So team id 255 is 'no team'.

EnForcer

#4
Quote from: habi on Sep 19, 2020, 04:44 PMlink not working.

Topic Updated Added Codes here.

Quote from: habi on Sep 19, 2020, 04:44 PMimagine player going to some place and press some button. A simple menu appears. It has images of each skin......
I can make as well as i already made a topic before here's link:
https://forum.vc-mp.org/?topic=7850.0

if you need more beautiful or any Help so you can dm me on discord.
here's my discord ID: iNForSir#7490

Quote from: habi on Sep 19, 2020, 04:44 PMI recently found that if player.Team=255 for two players and if one player shoots another, the health of the second player will be reduced. So team id 255 is 'no team'.
team 255 = Free Team
Free team = Can kill each other