No need to die

Started by KrOoB_, Sep 30, 2020, 06:53 PM

Previous topic - Next topic

KrOoB_

INFORMATION
Normally when a player dies game sends player to character selection part, with this script there'll no character selection.
When a player dies script'll freeze and sets hp to 1, script waits 1 min for doctors (i add a function for doctors u can use it, named kaldir) (After 1 min script sends player to nearest hospital)

Credits
 KrOoB_ and Bob
(this script works with bob's script add it too)
Thanks Bob, Send Player to Nearest Hospital

Server Side
[noae][noae][noae][noae]class Playerstatus
{
 Died = false;
 d_X = null;
 d_Y = null;
 d_Z = null;
 DeadFor = null;
}


function onScriptLoad()
{
    acilarr <- array(GetMaxPlayers(), false);

status <- array(GetMaxPlayers(), null)
// You can edit SQL code it's just an example
        DB <- ConnectSQL("Databases/Hesap.db");
        QuerySQL(DB, "create table if not exists Other ( Name TEXT, Died BOOLEAN DEFAULT false, DX FLOAT, DY FLOAT, DZ FLOAT) ");
}

function onPlayerJoin( player )
{
status[player.ID] = Playerstatus();
DeadInfo(player);
}

function aciloff(player)
{
    player = FindPlayer( player );
    DestroyMarker( acils );
    acilarr[player.ID] = false;
}

function DeadInfo(player)
{
 local z = QuerySQL(DB, "SELECT * FROM Other WHERE Name = '" + escapeSQLString(player.Name) + "'");
 if (q)
 {
  status[player.ID].Died = GetSQLColumnData(z, 7);
  status[player.ID].d_X = GetSQLColumnData(z, 8);
  status[player.ID].d_Y = GetSQLColumnData(z, 9);
  status[player.ID].d_Z = GetSQLColumnData(z, 10);
 }
}
function onPlayerDeath( player, reason )
{
        player.Health = 1;
        status[player.ID].d_X = player.Pos.x;
        status[player.ID].d_Y = player.Pos.y;
        status[player.ID].d_Z = player.Pos.z;   
        status[player.ID].Died = true;

if ( status[player.ID].Died == true)
{
            // Emergency Call

 local acilci;
 for( local i = 0; i <= GetMaxPlayers(); i++ )
 {
 acilci = FindPlayer( i );
 if ( (acilci) && ( acilci.Skin == 1 ) )
 {
                Message("[#1b8bb4][EMERGENCY] [#FFFFFF]" + player.Name + " [#1b8bb4] needs medical attention. [#1b8bb4] Position:[#FFFFFF] " +GetDistrictName(player.Pos.x, player.Pos.y)+"")
                MessagePlayer("[#1b8bb4][EMERGENCY] [#FFFFFF]Doctors are called. [#1b8bb4] Position:[#FFFFFF] " +GetDistrictName(player.Pos.x, player.Pos.y)+"",player)   
     acils <- CreateMarker(1, Vector(player.Pos.x, player.Pos.y, player.Pos.z), 1, RGB(0, 255, 0), 22)
    NewTimer("aciloff", 30000, 1, player.ID);
    acilarr[player.ID] = true;
 }
    }
        player.SetAnim(0,126);
        player.IsFrozen = true;
    }
}

function onPlayerKill( killer, player, reason, bodypart )
{
    player.Health = 1;
    status[player.ID].Died = true;
    if ( status[player.ID].Died == true)
    {
            // Emergency Call
local acilci;
for( local i = 0; i <= GetMaxPlayers(); i++ )
{
acilci = FindPlayer( i );
if ( (acilci) && ( acilci.Skin == 1 ) )
{
                Message("[#1b8bb4][EMERGENCY] [#FFFFFF]" + player.Name + " [#1b8bb4] needs medical attention. [#1b8bb4] Position:[#FFFFFF] " +GetDistrictName(player.Pos.x, player.Pos.y)+"")
                MessagePlayer("[#1b8bb4][EMERGENCY] [#FFFFFF]Doctors are called. [#1b8bb4] Position:[#FFFFFF] " +GetDistrictName(player.Pos.x, player.Pos.y)+"",player)   
acils <- CreateMarker(1, Vector(player.Pos.x, player.Pos.y, player.Pos.z), 1, RGB(0, 255, 0), 22)
NewTimer("aciloff", 30000, 1, player.ID);
acilarr[player.ID] = true;
}
}
        player.SetAnim(0,126);
        player.IsFrozen = true;
    }
}

function onTimeChange(oldHour, oldMin, newHour, newMin)
{
for (local i = 0; i < GetMaxPlayers(); ++i)
{
local player = FindPlayer(i);

if (player)
{
if (player.IsSpawned)
{
            if ( status[player.ID].Died == true)
            {
                if (status[player.ID].DeadFor == null)
                {
                    // Calculating time
                        local Val = 1;
                        local DeadJail = Val * 10000, DeadJail2 = Val * 10;
                        status[player.ID].DeadFor = DeadJail2;
                }else {

                    local Time = status[player.ID].DeadFor,
mins = (Time % 3600) / 60,
secs = Time % 60;
Stream.StartWrite();
Stream.WriteInt(36);
Stream.WriteString(mins + ":" + secs);
Stream.SendStream(player);
status[player.ID].DeadFor--;
                }
if ( status[player.ID].DeadFor < 1)
{
if( Hospi[player.ID] == 1 )
{
GetNearestHospital(player);
player.World = 1;
                            // En yakın Hastane Scripti entegresi adamın süresi dolunca en yakın hastaneye gider
if (Hospital_Spawn[player.ID] == true) { player.Pos = Hospital_Locator[player.ID]; Hospital_Spawn[player.ID] = false; }
Hospi[player.ID] = 0;
MessagePlayer( "[#e74c3c][EMERGENCY] [#FFFFFF]Revived.", player );
Stream.StartWrite();
Stream.WriteInt(37);
Stream.SendStream(player);
status[player.ID].DeadFor = null;
status[player.ID].Died = false;
player.IsFrozen = false;
player.SetAnim(0,172);
}
    }
                }
            }
        }
    }
}
function onPlayerSpawn( player )
{
    if ( status[player.ID].Died == true)
    {
Hospi[player.ID] = 1;
        player.SetAnim(0,126);
        player.IsFrozen = true;
        player.Pos = Vector(status[player.ID].d_X,status[player.ID].d_Y,status[player.ID].d_Z);
        // i'm saving player's pos cause of dead bug like explode etc.
        // if player's death cause is explode, game sends player directly character selection
        local acilci;
        for( local i = 0; i <= GetMaxPlayers(); i++ )
        {
            acilci = FindPlayer( i );
            if ( (acilci) && ( acilci.Skin == 1 ) )
            {
                Message("[#1b8bb4][EMERGENCY] [#FFFFFF]" + player.Name + " [#1b8bb4] needs medical attention. [#1b8bb4] Position:[#FFFFFF] " +GetDistrictName(player.Pos.x, player.Pos.y)+"")
                MessagePlayer("[#1b8bb4][EMERGENCY] [#FFFFFF]Doctors are called. [#1b8bb4] Position:[#FFFFFF] " +GetDistrictName(player.Pos.x, player.Pos.y)+"",player)   
                acils <- CreateMarker(1, Vector(player.Pos.x, player.Pos.y, player.Pos.z), 1, RGB(0, 255, 0), 22)
                NewTimer("aciloff", 30000, 1, player.ID);
                acilarr[player.ID] = true;
            }
        }
    }
}

// function for doctors' command to revive dead/injured player
function kaldir( p )
{

 local player = FindPlayer( p );
 if( player )
    {
        player.IsFrozen = false;
        player.SetAnim(0,161);
        status[player.ID].Died = "false";
        MessagePlayer("[#ef5777]#[#0be881]VC[#d2dae2]-[#575fcf]TR[#ef5777]# [#828282]Tedavin bitti", player);
    }
Stream.StartWrite();
Stream.WriteInt(37);
Stream.SendStream(player);
status[player.ID].DeadFor = null;
}
function SaveAccount(player)
{
          QuerySQL(DB, "UPDATE Other SET Died = '" + status[player.ID].Died + "' WHERE Name = '" + player.Name + "'");
          QuerySQL(DB, "UPDATE Other SET DX = '" + status[player.ID].d_X + "' WHERE Name = '" + player.Name + "'");
          QuerySQL(DB, "UPDATE Other SET DY = '" + status[player.ID].d_Y + "' WHERE Name = '" + player.Name + "'");
          QuerySQL(DB, "UPDATE Other SET DZ = '" + status[player.ID].d_Z + "' WHERE Name = '" + player.Name + "'");
}


[/noae][/noae][/noae][/noae]
Client Side
[noae][noae][noae][noae]
Dead <-
    {
    Windows = null
    Labels = null
        Time = null
    }

function Server::ServerData(stream)
{
 local StreamReadInt = stream.ReadInt(),
 StreamReadString = stream.ReadString();
 switch (StreamReadInt.tointeger())
 {
case 36: local data = StreamReadString; DeadFors(data); break;
case 37: Dead.Labels = null; break;
 }
 }

  function DeadFors(data)
    {
    local separator = split(data ":"), mins = separator[0], secs = separator[1];
    Dead.Labels = GUILabel(VectorScreen(sX * 0.5, sY * 0.8), Colour(232, 232, 232), "", GUI_FLAG_TEXT_SHADOW | GUI_FFLAG_BOLD);
Dead.Labels.FontSize = 15;
    Dead.Labels.Text = "" + mins + " min " + secs + " sec";
    }
function DeadForN()
    {
    Dead.Labels = null;
    }

[/noae][/noae][/noae][/noae]
VIDEO
Note: I'm using it in my server no bug or error.(while extracting from server script i might be miss something, just in case u can tell thanks)