Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - PSL

#16
Script Showroom / BindKey Process System
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
                }
      }
        }
    }
}
#17
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.
#18
HI Habi, I understand your code and have successfully crafted the judgment NPCS. thank you very much.
When the NPC is in the vehicle and is the driver, the vehicle cannot pass the Vehicle.AddSpeed to add speed.
#19
Script Showroom / Re: Dipeos command
Mar 10, 2024, 06:25 AM
Thanks to Xmair for the tip. I forgot about the player quitting.
Another point is that when the player falls into the water, the coordinates are not recorded.
DiePos<-{}; //Create a table where you can store coordinates
function onPlayerPart(player, reason) {
    if (DiePos.rawin(player.ID))
        DiePos.rawdelete(player.ID);
}

function onPlayerSpawn(player)
{
if(DiePos.rawin(player.ID)) //If an ID exists in the table
    {
        player.Pos=DiePos.rawget(player.ID); //Restores the player to death point
        DiePos.rawdelete(player.ID); //Delete coordinates after recovery
    }
}
function onPlayerDeath(player,reason)
{
 if(reason!=43)
{
 DiePos.rawset(player.ID,player.Pos); //After the player dies, the ID is used as the search object, and the death coordinates are stored in the table
}
}
#20
I always find problems as soon as you release a new version. Now I have no more problems to report.
This plugin is very good, with it you can make a lot of gameplay.
Hi Habi. How can I tell if an ID is an NPC player in an NPC script. Recognize players and NPCS. I don't want to give NPCS a uniform name or skin.
function OnPlayerStreamIn(playerid)
{
    print("I see the "+GetPlayerName(playerid)+" enter my field of view, and his ID is: "+playerid+".");

    local r=RFC("IsPlayerNPC")(playerid);
    print(""+r+""); //Always return true
}
#21
Script Showroom / Re: Dipeos command
Mar 09, 2024, 08:11 AM
The following code may help you
DiePos<-{}; //Create a table where you can store coordinates
function onPlayerSpawn(player)
{
if(DiePos.rawin(player.ID)) //If an ID exists in the table
    {
        player.Pos=DiePos.rawget(player.ID); //Restores the player to death point
        DiePos.rawdelete(player.ID); //Delete coordinates after recovery
    }
}
function onPlayerDeath(player,reason)
{
DiePos.rawset(player.ID,player.Pos); //After the player dies, the ID is used as the search object, and the death coordinates are stored in the table
}
#22
GetShowOnlyTeamMarkers()
This function gets an error every time it is called.
Hopefully the developers can fix it.
#23
This problem has been fixed perfectly, and I'm sorry to have caused you so much trouble.
#24
Hi Habi. I also have a small probability that when an NPC enters the vehicle and executes the playback file, the NPC will simply get out and walk, then stop, and there is no event triggering the NPC to leave the vehicle when getting out.
The npc console displays that Error. Vehicle is not acquired by NPCS.
This is the recording that triggered the error: https://file.io/rbteRVNXNxyh , Vehicle model is 226.
#25
Hi Habi, This operation can resume the action of getting out of the car, but the walking after getting out of the car cannot be resumed.
#26
Hi Habi, Both of these bugs have been fixed in this new release, which is great. After my update, these two issues have also been fixed. Thank you.
I put the NPC in the vehicle and played it back. After my NPC got out of the car, he stood upright like a corpse, only the coordinates had changed. This was also the case in the previous version. I didn't record the entire server, so maybe that will happen here as well.
#27
Hi Habi, I add PLAY_IGNORE_VEHICLEID, you will be able to play back normally. thank you.
But I've noticed that NPCS don't seem to be able to get into ships, say with ID 176.
I simply execute ConnectMultipleNpcs("testfile","127.0.0.1",7); , The NPC console does not appear at all, My server simply shut down after executing this code.What's the reason?
#28
Hi Habi, There was an error playing back the recording, and the vehicle stood still.  Error. Vehicle id from rec file different. See flags for overriding.
When I open the rec file, field2 is 141, When the NPC comes back to life, immediately create the vehicle with model ID 141, then put the NPC in the driving position, then execute the recording file with the RFC, and the NPC stays still.
#29
Delete the module you added.
#30
I ran some function scripts using dofile, Now I want to deactivate the previous dofile script, what do I do?