Recent posts

#11
Script Showroom / Re: BindKey Process System
Last post by PSL - Mar 16, 2024, 08:35 AM
I've optimized the script to make it easier to add methods, use only one timer, and be more efficient. Adapt the following code to your server.
function onScriptLoad()
{
    PlayerKeys<-{};
    ProcessKey<-{};
    ProcessKeyTime<-100; //This number sets the speed of the code
    ProcessKeyTimer<-null;
}
function onPlayerPart(player,reason)
{
    DeleteAllPlayerKeyToTable(player.ID);
}
function onKeyDown(player,key)
{
    AddPlayerKeyToTable(player.ID,key);
}
function onKeyUp(player,key)
{
    DeletePlayerKeyToTable(player.ID,key);
}

//Functions
function AddKeyToTable(key)
{
    ProcessKey.rawset(key,key);
}
function DeleteKeyToTable(key)
{
    if(ProcessKey.rawin(key)) ProcessKey.rawdelete(key);
}
function AddPlayerKeyToTable(i,key)
{
    local plr=FindPlayer(i);
    if(plr)
    {
        if(ProcessKey.rawin(key))
        {
            if(PlayerKeys.rawin(plr.ID))
            {
                local arr=PlayerKeys.rawget(plr.ID),find=false;
                for(i=0;i<arr.len();i++)
                {
                    if(arr[i]==key)
                    {
                        find=true;
                        break;
                    }
                }
                if(find==false) arr.append(key);
            }
            else
            {
                local arr=[];
                arr.append(key);
                PlayerKeys.rawset(plr.ID,arr);
            }
            CreateProcessKeyTimer();
        }
    }
}
function DeletePlayerKeyToTable(i,key)
{
    local plr=FindPlayer(i);
    if(plr)
    {
        if(ProcessKey.rawin(key))
        {
            if(PlayerKeys.rawin(plr.ID))
            {
                local arr=PlayerKeys.rawget(plr.ID);
                for(local i=0;i<arr.len();i++)
                {
                    if(arr[i]==key)
                    {
                        arr.remove(i);
                        break;
                    }
                }
                if(arr.len()==0) PlayerKeys.rawdelete(plr.ID);
            }
            if(PlayerKeys.len()==0) DeleteProcessKeyTimer();
        }
    }
}
function DeleteAllPlayerKeyToTable(i)
{
    local plr=FindPlayer(i);
    if(plr)
    {
        if(PlayerKeys.rawin(plr.ID)) PlayerKeys.rawdelete(plr.ID);
    }
}
function CreateProcessKeyTimer()
{
    if(ProcessKeyTimer==null) ProcessKeyTimer=NewTimer("onServerKeyProcess",ProcessKeyTime,0);
}
function DeleteProcessKeyTimer()
{
    if(ProcessKeyTimer!=null) ProcessKeyTimer.Delete();
    ProcessKeyTimer=null;
}
function onServerKeyProcess()
{
    for(local i=0;i<100;i++)
    {
        local plr=FindPlayer(i);
        if(plr)
        {
            if(PlayerKeys.rawin(plr.ID))
            {
                local arr=PlayerKeys.rawget(plr.ID);
                for(local i=0;i<arr.len();i++) onKeyDown(plr,arr[i]);
            }
        }
    }
}

test code: A simple fly code, I key up, K key down. The above code must be installed first.
function onScriptLoad()
{
    Key_J<-BindKey(true,0x4A,0,0);
    Key_L<-BindKey(true,0x4C,0,0);
    Key_I<-BindKey(true,0x49,0,0);
    Key_K<-BindKey(true,0x4B,0,0);
   
    AddKeyToTable(Key_I); //Adds the binding key to the table that is looped
    AddKeyToTable(Key_K);

    ProcessKeyTime=10;
}
function onKeyDown(player,key)
{
    if(key==Key_I) player.Pos.z+=1;
    if(key==Key_K) player.Pos.z-=1;
    if(key==Key_J) MessagePlayer("[#FFFF00]Key: J",player);
    if(key==Key_L) MessagePlayer("[#FFFF00]Key: L",player);
}
#12
Script Showroom / Re: Ban & echo,system
Last post by Abbas_905 - Mar 14, 2024, 12:28 AM
bro oh so thank you for you have discord?
#13
Quote from: gamingpro on Jan 28, 2024, 07:54 AMHi bro, Can you tell me how you port forward please ?, because i try it but not success please tell me, Are port forward show server in masterlist or not ?

Hey, just add announce plugin in server.cfg
And try to port forward the port number you have in server.cfg by your router.
#14
Script Showroom / Re: Ban & echo,system
Last post by Mohamed Boubekri - Mar 13, 2024, 01:40 PM
You need to create database, store player informations into it, for example: name, id, ip, uid, ban (true, false)... And simply you can select any row from database by one of the informations and change 'ban' with values true or false.
There are many examples in the forum, just search you will be fine.
#15
Script Showroom / Ban & echo,system
Last post by Abbas_905 - Mar 13, 2024, 08:59 AM
guys how i can do ban players if players in game or no exmaple: player did not playing server but how can i do ban to him


How to add private acmds into discord-server-echo
#16
Script Showroom / Re: Dipeos command
Last post by Abbas_905 - Mar 13, 2024, 03:56 AM
else if(cmd == "lastpos" || cmd == "diepos")
 {
 if(!text) MessagePlayer("Syntax: /"+cmd+" <on/off>.",player);
 else {
 if(text == "on")
 {
 if(status[player.ID].Lastpos == true) MessagePlayer("[#FF0000]Your lastpos is already on.",player);
 else {
 status[player.ID].Lastpos = true;
 MessagePlayer("[#00FF00]You have turned on your lastpos/diepos.",player);
 }
 }
 if(text == "off")
 {
  if(status[player.ID].Lastpos == false) MessagePlayer("[#FF0000]Your lastpos is already off.",player);
 else {
  status[player.ID].Lastpos = false;
   MessagePlayer("[#00FF00]You have turned off your lastpos/diepos.",player);
 }
 }

 }
 }




This is right or no? if have errors so fix it and repost it,
#17
Script Showroom / Re: Dipeos command
Last post by Abbas_905 - Mar 13, 2024, 03:50 AM
thanks for it,
#18
Script Showroom / Re: BindKey Process System
Last post by PSL - Mar 11, 2024, 01:02 PM
If you don't want I and J to trigger loop execution, you can do so.
function onKeyDown(player,key) //Now only KL can trigger the loop execution
{
    if(key==Key_I)
{
Message("Key: I");
}
    if(key==Key_J)
{
Message("Key: J");
}
    if(key==Key_K)
{
Message("Key: K");
AddKeyTable(player.ID,key);
}
    if(key==Key_L)
{
Message("Key: L");
AddKeyTable(player.ID,key);
}
}
#19
Script Showroom / BindKey Process System
Last post by PSL - Mar 11, 2024, 12:57 PM
When the player consistently presses a bound key, the script continues to execute the key's code. How is this done, see the code below.
The code has been tested and is accurate, although you can customize the code to suit your server.
class PlayerClass //Create two items here, one to store buttons pressed by the player and the other to keep repeating the timer
{
    keytimer=null;
    keytable=null;
}
function onScriptLoad()
{
    state<-array(100,null);
    //Here are the keys on the test keyboard
    Key_I<-BindKey(true,0x49,0,0);
    Key_J<-BindKey(true,0x4A,0,0);
    Key_K<-BindKey(true,0x4B,0,0);
    Key_L<-BindKey(true,0x4C,0,0);
}
function onPlayerJoin(player)
{
    state[player.ID]=PlayerClass(player.Name);
}
function onPlayerPart(player,reason)
{
if(state[player.ID].keytimer!=null) //When the player exits, delete these two things
{
state[player.ID].keytimer.Delete();
state[player.ID].keytimer=null;
state[player.ID].keytable.clear();
state[player.ID].keytable=null;
}
    state[player.ID]=null;
}
function onKeyDown(player,key)
{
    //When you press the key, the corresponding text will be displayed
    if(key==Key_I) Message("Key: I");
    if(key==Key_J) Message("Key: J");
    if(key==Key_K) Message("Key: K");
    if(key==Key_L) Message("Key: L");
    AddKeyTable(player.ID,key); //Saves the key that the player presses
}
function onKeyUp(player,key)
{
    RemoveKeyTable(player.ID,key); //Delete the key saved by the player
}
function AddKeyTable(i,key)
{
    local plr=FindPlayer(i);
    if(plr)
    {
        if(state[plr.ID].keytable==null) state[plr.ID].keytable={}; //The first time the key is pressed, the table is created

        if(state[plr.ID].keytable.rawin(key))
        {
        }
        else state[plr.ID].keytable.rawset(key,key); //If the key is not in the table, add it

        if(state[plr.ID].keytimer==null) //If the repetition timer is not created, create it
        {
            state[plr.ID].keytimer=NewTimer("onKeyProcess",10,0,plr.ID);
        }
    }
}

function RemoveKeyTable(i,key) //Here is the delete key function
{
    local plr=FindPlayer(i);
    if(plr)
    {
        if(state[plr.ID].keytable!=null)
        {
if(state[plr.ID].keytable.rawin(key)) //If the key exists in the player's table
{
state[plr.ID].keytable.rawdelete(key); //Delete it
if(state[plr.ID].keytable.len()==0)
{
state[plr.ID].keytable=null; //If there are no keys in the table, delete the table
if(state[plr.ID].keytimer!=null) //Also delete timer
{
state[plr.ID].keytimer.Delete();
state[plr.ID].keytimer=null;
}
                }
            }
        }
    }
}
function onKeyProcess(i)
{
    local plr=FindPlayer(i);
    if(plr)
    {
        if(state[plr.ID].keytable!=null)
        {
            if(state[plr.ID].keytable.len()>0)
            {
                local nokey=0;
                for(local i=0;i<state[plr.ID].keytable.len()+1000;i++) //Create a loop to get the keys in the player's store table
                {
                    if(state[plr.ID].keytable.rawin(i))
                    {
                        local key=state[plr.ID].keytable.rawget(i);
                        nokey=0;
                        onKeyDown(plr,key); //Execute this key
                    }
                    else nokey+=1;

                    if(nokey>=10) break; //The 10 here is the number you set when you create the number of binding keys
                }
      }
        }
    }
}
#20
Community Plugins / Re: NPC/Bots implementation in...
Last post by PSL - Mar 11, 2024, 11:20 AM
HI, Vitovc. I was working on controlling the vehicle in the passenger seat and stumbled upon this issue, which turns out not to be a bug.