Spawnwep System by Mack

Started by Mack, Jan 16, 2016, 02:38 AM

Previous topic - Next topic

Mack

Hello, I go back again lol.


> First copy this lines and paste on "onScriptLoad()"
  db <- ConnectSQL( "Spawnwep.db" );
  QuerySQL( db,"CREATE TABLE IF NOT EXISTS Spawnwep( Nick TEXT, Weps TEXT)");
  SpawnwepPlayer <- array( GetMaxPlayers(), null );

> Now copy this line and paste on "onPlayerJoin( player )"
LoadSpawnwep(player);
> Paste this on "onPlayerSpawn( player )"
GiveSpawnwep(player);
> And now paste this on "onPlayerPart( player, reason )"
if (SpawnwepPlayer[ player.ID ] != null)
{
if(!CheckTableSpawnwep( player )) QuerySQL( db, "REPLACE INTO Spawnwep( Nick, Weps ) VALUES ( '" + player.Name + "','"+ SpawnwepPlayer[ player.ID ] + "' ) ");
else QuerySQL( db, "UPDATE Spawnwep SET Weps='"+ SpawnwepPlayer[ player.ID ] +"' WHERE Nick='" + player.Name + "'" );
SpawnwepPlayer[ player.ID ] = null; print( player.Name +"'s Spawnwep Saved!" );
}



//=================================SPAWNWEP STSTEM BY MACK==========================================================
function CheckTableSpawnwep( player )
{
    local si = GetSQLColumnData( QuerySQL( db, "SELECT Weps FROM Spawnwep WHERE Nick='" + player.Name + "'" ), 0 );
    if ( si ) return si;
    else return 0;
}
//-------------------------------------------------------------------------------------------------------------------
function LoadSpawnwep(player)
{
if(CheckTableSpawnwep( player )) SpawnwepPlayer[ player.ID ] = CheckTableSpawnwep( player );
else SpawnwepPlayer[ player.ID ] = null;
}
//-------------------------------------------------------------------------------------------------------------------
function GiveSpawnwep(player)
{
if (SpawnwepPlayer[ player.ID ] != null)
{
local i = 1, khe = SpawnwepPlayer[ player.ID ], Nweps = NumTok( khe," ");
while ( i < (Nweps.tointeger()+1))
{
local ID = GetTok( khe," ", i);
player.SetWeapon( ID.tointeger(), 99999 ); i++;
}
ClientMessage("-> [#83bab3][SPAWNWEP] Weapons setting in spawn, Completed successfully.",player,255,0,102);
}
}
//=================================SPAWNWEP STSTEM BY MACK==========================================================

> Credits to original creator of this functions.
//-------------------------------------------------------------------------------------------------------------------
function NumTok(string, separator)
{
    local tokenized = split(string, separator);
    return tokenized.len();
}
//-------------------------------------------------------------------------------------------------------------------
function GetPlayer( target )
{
local target1 = target.tostring();

if ( IsNum( target ) )
{
target = target.tointeger();

if ( FindPlayer( target) ) return FindPlayer( target );
else return null;
}
else if ( FindPlayer( target ) ) return FindPlayer( target );
else return null;
}
//-------------------------------------------------------------------------------------------------------------------

> Commands: /spawnwep, /spawnwepdel. <
if ( cmd == "spawnwep" )
    {
       
  if ( !text ) ClientMessage( "[#ea4335]-> Error: [#fbbc05]Type /spawnwep <Wep1> <Wep2> <Wep3> <Wep4> <Wep5> <Wep6>...", player,0,0,0 );
        else
        {
            local weps = split( text, " " ),ID, wepsset = null;
            for( local i = 0; i < weps.len(); i++ )
            {
                ( IsNum( weps[ i ] ) ) ? ID = weps[ i ].tointeger() : ID = GetWeaponID( weps[ i ] );                         
                if ( ID >= 33 ) ClientMessage( "[#ea4335]-> Error: [#c0c0c0]Invalid Weapon ID/Name.", player,0,0,0 );
                else
                {
                    player.SetWeapon( ID, 99999 );
                    ClientMessage( "-> [#daff00]Saving " + GetWeaponName( ID ) + " to your spawn.",player,255,0,102);
                    if (wepsset == null) wepsset = " "+ ID;
                    else wepsset += (" " + ID);
                }
            }
            if (wepsset) SpawnwepPlayer[ player.ID ] = wepsset;   
        }
    }
    else if ( cmd == "spawnwepdel")
    {

    if ( CheckTableSpawnwep( player ) )
    {
        QuerySQL( db, "DELETE FROM SpawnWep WHERE Nick='" + player.Name + "' COLLATE NOCASE" );
        ClientMessage( "-> Your Spawnwep have been deleted.",player,255,0,102); SpawnwepPlayer[ player.ID ] = null;
    }
    else ClientMessage( "-> Error: You not have spawnwep.",player,255,0,102);
    }

And the end would look like this.





I tested this script and work :)
Dowload Script: Mediafire
Virus Total: Link

Williams

This topic already posted. Btw great! :)
Hey, i m always at IRC and Forum you can comtact me at IRC channel :- #GDM @LUNet and Forum :- http://pro-fighter.tk/index.php

Mack


KAKAN

Quote from: Mack on Jan 16, 2016, 04:23 AM
Quote from: Williams on Jan 16, 2016, 04:17 AMThis topic already posted. Btw great! :)
This is different. :)
Yeah, at-least on 0.4

Oh well, it looks like you're new to this forum. Great work mate!
oh no

Xmair


Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

Anik

Off:- Which SOftware are u using for editing scripts?? Can u give me Download Link??

Drake

Quote from: [DS]Anik on Jan 16, 2016, 10:14 AMOff:- Which SOftware are u using for editing scripts?? Can u give me Download Link??
The software's name is clearly written in one of the images, Hint: title ;D

Mack

Quote from: [DS]Anik on Jan 16, 2016, 10:14 AMOff:- Which SOftware are u using for editing scripts?? Can u give me Download Link??

Subline.
http://www.sublimetext.com/

Sebastian

* sseebbyy likes very much the presentation of script.

ps: you could still add some more info about how the script works.

KAKAN

Quote from: Mack on Jan 16, 2016, 04:32 PM
Quote from: [DS]Anik on Jan 16, 2016, 10:14 AMOff:- Which SOftware are u using for editing scripts?? Can u give me Download Link??

Subline.
http://www.sublimetext.com/
Off:- I use that too, which syntax( language ) you use? Try using 'D'
oh no

doxuanhien2002

I can not use it on 04rel006

Gito Baloch

im getting bug
AN ERROR HAS OCCURED [cannot convert the string]

CALLSTACK
*FUNCTION [GiveSpawnwep()] scripts/main.nut line [124]
*FUNCTION [onPlayerSpawn()] scripts/main.nut line [370]

LOCALS
[ID] ""
[Nweps] 3
[khe] " 26 20"
1
[player] INSTANCE
[this] TABLE
[player] INSTANCE
Programming is the language I speak, the world I shape, and the future I code

habi

try changing to
while ( i < (Nweps.tointeger()))

=RK=MarineForce

not working. cannt convert to string

habi

why not u share more details, when having errors.