Raised This Month: $32 Target: $400
 8% 

Removing train controls from a player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
WAR3DM
Senior Member
Join Date: Mar 2016
Old 03-04-2018 , 03:27   Removing train controls from a player
Reply With Quote #1

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!

Last edited by WAR3DM; 03-04-2018 at 03:31.
WAR3DM is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 03-04-2018 , 08:19   Re: Removing train controls from a player
Reply With Quote #2

Try to execute Ham_Use on player. I think this will force the player to release the train. It should be tested.
__________________
My English is A0
E1_531G is offline
WAR3DM
Senior Member
Join Date: Mar 2016
Old 03-04-2018 , 09:46   Re: Removing train controls from a player
Reply With Quote #3

I think Ham_Use is only for detecting if Use was used.
WAR3DM is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 03-04-2018 , 15:31   Re: Removing train controls from a player
Reply With Quote #4

The most (if not all) of Ham_* can be executed: ExecuteHam/ExecuteHamB
__________________
My English is A0
E1_531G is offline
Th3822
Member
Join Date: Jan 2013
Location: Venezuela
Old 03-06-2018 , 06:56   Re: Removing train controls from a player
Reply With Quote #5

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)
Th3822 is offline
WAR3DM
Senior Member
Join Date: Mar 2016
Old 03-08-2018 , 15:09   Re: Removing train controls from a player
Reply With Quote #6

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?

Last edited by WAR3DM; 03-08-2018 at 15:12.
WAR3DM is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-08-2018 , 17:02   Re: Removing train controls from a player
Reply With Quote #7

Quote:
Originally Posted by WAR3DM View Post
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.
__________________
HamletEagle is offline
WAR3DM
Senior Member
Join Date: Mar 2016
Old 03-08-2018 , 19:22   Re: Removing train controls from a player
Reply With Quote #8

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?

Last edited by WAR3DM; 03-08-2018 at 19:26.
WAR3DM is offline
Old 03-08-2018, 19:28
WAR3DM
This message has been deleted by WAR3DM. Reason: double post
Th3822
Member
Join Date: Jan 2013
Location: Venezuela
Old 03-08-2018 , 19:46   Re: Removing train controls from a player
Reply With Quote #9

Sending the Train(0) msg should hide train controls on the player
Th3822 is offline
WAR3DM
Senior Member
Join Date: Mar 2016
Old 03-08-2018 , 21:16   Re: Removing train controls from a player
Reply With Quote #10

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.

Last edited by WAR3DM; 03-09-2018 at 04:25.
WAR3DM is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:42.


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