AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Removing train controls from a player (https://forums.alliedmods.net/showthread.php?t=305785)

WAR3DM 03-04-2018 03:27

Removing train controls from a player
 
Hello :)

Is it possible to revoke access to a train, while it's being used?

Example:
1. Player pushes E on train controls to drive train.
2. Custom block trigger is enabled for specific player ID.
3. Player is removed from train controls, making the hud for it disappear.
4. Player is blocked from using train controls again for that entity.

Any help is greatly appreciated!

E1_531G 03-04-2018 08:19

Re: Removing train controls from a player
 
Try to execute Ham_Use on player. I think this will force the player to release the train. It should be tested.

WAR3DM 03-04-2018 09:46

Re: Removing train controls from a player
 
I think Ham_Use is only for detecting if Use was used.

E1_531G 03-04-2018 15:31

Re: Removing train controls from a player
 
The most (if not all) of Ham_* can be executed: ExecuteHam/ExecuteHamB

Th3822 03-06-2018 06:56

Re: Removing train controls from a player
 
Try with this, should work fine:
PHP Code:

RegisterHam(Ham_Use"tracktrain""Ham_Use_Train_Pre"0);
RegisterHam(Ham_Use"func_vehicle""Ham_Use_Train_Pre"0); // For CS's vehicles too 

PHP Code:

public Ham_Use_Train_Pre(entid)
{
    if (
g_cantUseTrain[id])
    {
        static 
buttonscurTimeplayerTime[33], msgTrain;

        
buttons pev(idpev_button);
        if (
buttons IN_USE)
        {
            
set_pev(idpev_buttonbuttons & ~IN_USE);
            
set_pev(idpev_oldbuttonspev(idpev_oldbuttons) | IN_USE);
        }

        
// Ratelimited
        
if (playerTime[id] != (curTime get_systime()))
        {
            
message_begin(MSG_ONE, (msgTrain msgTrain : (msgTrain get_user_msgid("Train"))), _id);
            
write_byte(0);
            
message_end();
            
playerTime[id] = curTime;
        }
        return 
HAM_SUPERCEDE;
    }
    return 
HAM_IGNORED;


btw, check https://forums.alliedmods.net/showthread.php?p=869443 (i'm using it with this func, and a chat msg)

WAR3DM 03-08-2018 15:09

Re: Removing train controls from a player
 
Thanks! It's pretty close.

I also wanted to remove the controls from the player, so the Vehicle Controls HUD disappears. (Similar to if the player would push E again.)

Any idea?

HamletEagle 03-08-2018 17:02

Re: Removing train controls from a player
 
Quote:

Originally Posted by WAR3DM (Post 2581967)
Thanks! It's pretty close.

I also wanted to remove the controls from the player, so the Vehicle Controls HUD disappears. (Similar to if the player would push E again.)

Any idea?

Try to simply execute Ham_Use as suggested before.

WAR3DM 03-08-2018 19:22

Re: Removing train controls from a player
 
I've attempted to use ExecuteHam/ExecuteHamB:

Code:

new bool:g_cantUseTrain[ 33 ] = false

public plugin_init() {
        register_concmd("amx_test","test",ADMIN_KICK)
        RegisterHam(Ham_OnControls, "func_vehicle", "train", 0);
        RegisterHam(Ham_Use, "func_vehicle", "train", 0);
        RegisterHam(Ham_Use, "func_vehiclecontrol", "train", 0);
}

public train(ent, id) {
    if (g_cantUseTrain[id])
    {
                ExecuteHamB(Ham_Use, ent, 0, 0, 0, 0);                 
                return HAM_SUPERCEDE;
    }
    return HAM_IGNORED;


public test() {       
        g_cantUseTrain[1] = true       
        return PLUGIN_HANDLED
}

The vehicle comes to a dead stop and can't be used again, but the HUD controls stick until the player pushes E or jumps.

Maybe I'm using the function wrong?

Th3822 03-08-2018 19:46

Re: Removing train controls from a player
 
Sending the Train(0) msg should hide train controls on the player

WAR3DM 03-08-2018 21:16

Re: Removing train controls from a player
 
Yes, it hides the controls while holding down movement keys but the player seems to still be stuck on the controls until pushing E or jumping. Maybe it'd be easier to simulate those keys?

Code:

#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <engine>
#include <fakemeta>
#include <fakemeta_stocks>
#include <fun>

new bool:g_cantUseTrain[ 33 ] = false

public plugin_init() {
        register_concmd("amx_test","test",ADMIN_KICK)
        RegisterHam(Ham_Use, "func_vehicle", "train", 0);
}

public train(ent, id) {
    if (g_cantUseTrain[id])
    {
                ExecuteHamB(Ham_Use, ent, 0, 0, 0, 0); 
               
        static buttons, msgTrain;               
                buttons = pev(id, pev_button);
               
        if (buttons & IN_USE)
        {
            set_pev(id, pev_button, buttons & ~IN_USE);
            set_pev(id, pev_oldbuttons, pev(id, pev_oldbuttons) | IN_USE);
        }
               
                message_begin(MSG_ONE, (msgTrain ? msgTrain : (msgTrain = get_user_msgid("Train"))), _, id);
                write_byte(0);
                message_end();
                       
        return HAM_SUPERCEDE;
    }
    return HAM_IGNORED;


public test() {       
        g_cantUseTrain[1] = true       
        return PLUGIN_HANDLED
}

Appreciate the help this far.


All times are GMT -4. The time now is 23:31.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.