login
April 27, 2024, 06:35:12 pm

Author Topic: [RELEASE] Spawn Weapon System  (Read 398 times)

0 Members and 1 Guest are viewing this topic.

MR SK

  • Newbie
  • *
  • Posts: 22
  • Country: pk
    • View Profile
    • My Youtube Channel
[RELEASE] Spawn Weapon System
« on: June 10, 2022, 12:28:43 pm »
Hi buddies, I created Spawn Weapon System because I just found only spawn weapon and it was bugged :/
So I decided to create my own Spawn Weapon System

Here is the code

Paste the spawn weapon class in the top of your main.nut file

Code: [Select]
class SpawnWeps
{
SpawnWepStatus = false;
SpawnWeps = null;
}

Paste this code on script load event

Code: [Select]
Spawnweps <- ConnectSQL("SpawnWep.db");
QuerySQL( Spawnweps, "CREATE TABLE IF NOT EXISTS SpawnWep(Name TEXT DEFAULT NULL, SpawnWepStatus BOOLEAN DEFAULT FALSE, Wep1 NUMERIC DEFAULT 0, Wep2 NUMERIC DEFAULT 0, Wep3 NUMERIC DEFAULT 0, Wep4 NUMERIC DEFAULT 0, Wep5 NUMERIC DEFAULT 0, Wep6 NUMERIC DEFAULT 0, Wep7 NUMERIC DEFAULT 0, Wep8 NUMERIC DEFAULT 0, Wep9 NUMERIC DEFAULT 0 )" );
spawnwep <- array(GetMaxPlayers(), null);
print("Spawn Weapon System by MR SK has been loaded successfully!");

Paste this line on player join event

Code: [Select]
GetSpawnWepData(player);
Paste this line on player spawn event

Code: [Select]
AssignSpawnWeps(player);
Now here are the commands

Code: [Select]
if(cmd == "spawnwep")
{
if(text)
{
QuerySQL( Spawnweps, "UPDATE SpawnWep SET Wep1='0',Wep2='0',Wep3='0',Wep4='0',Wep5='0',Wep6='0',Wep7='0',Wep8='0',Wep9='0' WHERE Name LIKE '" + escapeSQLString(player.Name) + "'" );
local ptext = split(text " ");
spawnwep[player.ID].SpawnWepStatus = true;
QuerySQL( Spawnweps, "UPDATE SpawnWep SET SpawnWepStatus='true' WHERE Name LIKE '" + escapeSQLString(player.Name) + "'" );
local wepnames = "";
foreach(wep in ptext)
{
local weaponId = IsNum(wep) ? wep.tointeger() : GetWeaponID(wep);
QuerySQL( Spawnweps, "UPDATE SpawnWep SET "+GetWepColumn(GetWeaponSlot(weaponId))+"='"+weaponId+"' WHERE Name LIKE '" + escapeSQLString(player.Name) + "'" );
player.GiveWeapon(weaponId, 9999);
wepnames += wepnames != "" ? format(", %s", GetWeaponName(weaponId)) : GetWeaponName(weaponId);
}
local q = QuerySQL(Spawnweps, "SELECT * FROM SpawnWep WHERE Name = '" + escapeSQLString(player.Name) + "'");
if(q != null)
{
spawnwep[player.ID].SpawnWeps = [GetSQLColumnData(q, 2).tointeger(), GetSQLColumnData(q, 3).tointeger(), GetSQLColumnData(q, 4).tointeger(), GetSQLColumnData(q, 5).tointeger(), GetSQLColumnData(q, 6).tointeger(), GetSQLColumnData(q, 7).tointeger(), GetSQLColumnData(q, 8).tointeger(), GetSQLColumnData(q, 9).tointeger(), GetSQLColumnData(q, 10).tointeger()];
}
if(wepnames != "")
{
MessagePlayer("[#00FF00][SPAWN WEP]: [#FFFFFF]You have set your spawn weapons to "+wepnames+" successfully!", player);
}
return 0;
}
else MessagePlayer("[#FFFF00]Syntax; /spawnwep <Weps Name/ID>", player);
}

else if(cmd == "spawnwepdel")
{
if(spawnwep[player.ID].SpawnWepStatus == true)
{
MessagePlayer("[#00FF00][SPAWN WEP]: [#FFFFFF]You have disabled your spawn weapons successfully!", player);
QuerySQL( Spawnweps, "UPDATE SpawnWep SET SpawnWepStatus='false', Wep1='0',Wep2='0',Wep3='0',Wep4='0',Wep5='0',Wep6='0',Wep7='0',Wep8='0',Wep9='0' WHERE Name LIKE '" + escapeSQLString(player.Name) + "'" );
spawnwep[player.ID].SpawnWepStatus = false;
spawnwep[player.ID].SpawnWeps = null;
}
else MessagePlayer("[#FF0000][ERROR]: Your spawn weapons are already disabled!", player);
return 0;
}

Now finally at last the function for this Spawn Weapons System are here

Code: [Select]
function GetSpawnWepData(player)
{
spawnwep[player.ID] = SpawnWeps();
local q = QuerySQL(Spawnweps, "SELECT * FROM SpawnWep WHERE Name = '" + escapeSQLString(player.Name) + "'");
if(q != null)
{
spawnwep[player.ID].SpawnWeps = [GetSQLColumnData(q, 2).tointeger(), GetSQLColumnData(q, 3).tointeger(), GetSQLColumnData(q, 4).tointeger(), GetSQLColumnData(q, 5).tointeger(), GetSQLColumnData(q, 6).tointeger(), GetSQLColumnData(q, 7).tointeger(), GetSQLColumnData(q, 8).tointeger(), GetSQLColumnData(q, 9).tointeger(), GetSQLColumnData(q, 10).tointeger()];
if(GetSQLColumnData(q, 1) == "true")
{
spawnwep[player.ID].SpawnWepStatus = true;
}
else{
spawnwep[player.ID].SpawnWepStatus = false;
}
}
else{
QuerySQL(Spawnweps, "INSERT INTO SpawnWep( Name, SpawnWepStatus, Wep1, Wep2, Wep3, Wep4, Wep5, Wep6, Wep7, Wep8, Wep9 ) VALUES ('"+escapeSQLString(player.Name)+"', 'false', '0', '0', '0', '0', '0', '0', '0', '0', '0' )" );
}
}

function AssignSpawnWeps(player)
{
if(spawnwep[player.ID].SpawnWepStatus == true)
{
player.Disarm();
foreach(weps in spawnwep[player.ID].SpawnWeps)
{
player.GiveWeapon(weps, 9999);
}
MessagePlayer("[#00FF00][SPAWN WEP]: [#FFFFFF]You've spawned with your spawn weapons!", player);
}
}

function GetWeaponSlot(weapon){
switch(weapon.tointeger())
{
case 0:
case 1:
return 0;

case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
return 1;

case 12:
case 13:
case 14:
case 15:
case 16:
return 2;

case 17:
case 18:
return 3;

case 19:
case 20:
case 21:
return 4;

case 22:
case 23:
case 24:
case 25:
return 5;

case 26:
case 27:
return 6;

case 30:
case 31:
case 32:
case 33:
return 7;

case 28:
case 29:
return 8;
}
}

function GetWepColumn(slotid)
{
switch(slotid.tointeger())
{
case 0: return "Wep1";
case 1: return "Wep2";
case 2: return "Wep3";
case 3: return "Wep4";
case 4: return "Wep5";
case 5: return "Wep6";
case 6: return "Wep7";
case 7: return "Wep8";
case 8: return "Wep9";

default: return "Unknown";
}
}

The code ends here...

NOTE: The code is tested and if you found any bug inside the code then don't hesitate to reply to this post as it can save newbies life :laugh:
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

@Mr_Sk@

Sk

  • Vice Underdog
  • Crazy Man
  • *
  • Posts: 618
  • Country: pk
  • #VU
    • View Profile
Re: [RELEASE] Spawn Weapon System
« Reply #1 on: June 10, 2022, 01:15:18 pm »
very nice, did you make it yourself without anyone help? if not then why not mention the credits?
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

le pro
http://i.imgur.com/j6yise0.png

Krediit Kokcex

MR SK

  • Newbie
  • *
  • Posts: 22
  • Country: pk
    • View Profile
    • My Youtube Channel
Re: [RELEASE] Spawn Weapon System
« Reply #2 on: June 10, 2022, 01:53:18 pm »
Ohh Sorry and thanks for appreciating I made this spawn weapons system by myself without anyone's help i got some idea :laugh: in that time when I made it it's too long I can't remember but I was searching for a file in my PC so i got some useful scripts so i decided to upload it  ^-^
Brain Donor Brain Donor x 2 (list)
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor

@Mr_Sk@