SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 13/03/2018, 05:24 PM   #1
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 280
Reputation: 72
Default IPUCH (Detects if player using car horn)

IPUCH:

This include detects if player pressing car horn and if player released car horn

function:


Code:
IsPlayerUsingCarHorn(playerid);


Callbacks:


Code:
OnPlayerPressCarHorn(playerid, vehicleid)

OnPlayerReleaseCarHorn(playerid, vehicleid)


PICS:










VIDEO:



SCRIPT USED IN THE VIDEO V1:



Code:
#include <a_samp>
#include <izcmd>

#include <IPUCH>

public OnPlayerPressCarHorn(playerid, vehicleid)
{
	GameTextForPlayer(playerid, "~g~~h~~h~Pressed on car horn", 2000, 4);
	return 1;
}

public OnPlayerReleaseCarHorn(playerid, vehicleid)
{
        GameTextForPlayer(playerid, "~g~~h~~h~Released car horn", 2000, 4);
	return 1;
}

SCRIPT USED IN THE VIDEO V1.1:


Code:
#include <a_samp>
#include <izcmd>

#include <IPUCH>

public OnPlayerCarHorn(playerid, vehicleid, status)
{
	switch(status)
	{
	    case 0: GameTextForPlayer(playerid, "~g~~h~~h~Pressed on car horn", 2000, 4);
	    case 1: GameTextForPlayer(playerid, "~g~~h~~h~Released car horn", 2000, 4);
	}
	return 1;
}


LINK V1: -REMOVED-

LINK V1.1: -REMOVED-

LINK V1.2:-REMOVED-

LINK V1.3: click


IF YOU ARE GETTING ERROR



Code:
error 004: function "OnPlayerCarHorn" is not implemented


SIMPLE JUST ADD THIS TO YOUR SCRIPT



Code:
public OnPlayerCarHorn(playerid, vehicleid, status)
{

	return 1;
}

CREDITS:
SAMP TEAM - FOR SAMP
ME - FOR IPUCH
Y_LESS - FOR Y_HOOKS
ROMZ - FOR SUGGESTING
VARIABLE - FOR SUGGESTING

Last edited by Lokii; 03/04/2018 at 06:27 PM.
Lokii is offline   Reply With Quote
Old 13/03/2018, 08:01 PM   #2
Romz
High-roller
 
Romz's Avatar
 
Join Date: Jun 2013
Location: Ukraine
Posts: 1,046
Reputation: 59
Default Re: IPUCH (Detects if player using car horn)

I propose to change
Code:
public OnPlayerPressCarHorn(playerid, vehicleid) { /* */ }
public OnPlayerReleaseCarHorn(playerid, vehicleid) { /* */ }
on
Code:
public OnPlayerCarHorn(playerid, vehicleid, status) {
/*
status:
0 - Press
1 - Release
*/
}
__________________
Romz is offline   Reply With Quote
Old 13/03/2018, 10:04 PM   #3
Variable™
Gangsta
 
Variable™'s Avatar
 
Join Date: Jul 2015
Location: Somewhere...
Posts: 709
Reputation: 133
Default Re: IPUCH (Detects if player using car horn)

- You don't check for vehicles that don't have horn at all, like helicopters and planes.
- You don't need to call the function remotely, just put it normally.
- Why do you redefine MAX_PLAYERS in your example code?
- You don't need defining H_HOLDING and H_RELEASED, you just use H_HOLDING and H_RELEASED one time, why extra definitions... I mean such a simple include should not have many useless stuff.
__________________
DW4 Community
Variable™ is online now   Reply With Quote
Old 13/03/2018, 10:27 PM   #4
Grim_
High-roller
 
Grim_'s Avatar
 
Join Date: Sep 2008
Location: United States
Posts: 2,883
Reputation: 109
Default Re: IPUCH (Detects if player using car horn)

Not bad, though I would suggest using timestamps for the cooldown versus timers. Check this link: http://forum.sa-mp.com/showthread.php?t=254915

Quote:
Originally Posted by Variable™ View Post
- You don't need to call the function remotely, just put it normally.
- Why do you redefine MAX_PLAYERS in your example code?
- You don't need defining H_HOLDING and H_RELEASED, you just use H_HOLDING and H_RELEASED one time, why extra definitions... I mean such a simple include should not have many useless stuff.
1. Maybe a filterscript needs to know when a horn is used?
2. A lot of people keep it at the default value, which is a huge waste of data.
3. It won't interfere, so why worry? If anything, he can just #undef them at the end of the script. There is zero overhead for macros.
Grim_ is online now   Reply With Quote
Old 14/03/2018, 06:11 PM   #5
Variable™
Gangsta
 
Variable™'s Avatar
 
Join Date: Jul 2015
Location: Somewhere...
Posts: 709
Reputation: 133
Default Re: IPUCH (Detects if player using car horn)

"Why do you redefine MAX_PLAYERS in your example code: as grim said "A lot of people keep it at the default value, which is a huge waste of data""

It has no relation with the horn system in general, I mean this is code optimization which is something according to the editor if he wishes to redefine it or not, and it should be redefined straight after including a_samp or just edit it through a_samp because it can cause malfunction with other includes by placing the redefinition under them.

E.g. and include uses MAX_PLAYERS from a_samp as 1000, you redefine MAX_PLAYERS to 50 while the include already considered it 1000 which will return array index out of bounds error.

"- You don't need defining H_HOLDING and H_RELEASED, you just use H_HOLDING and H_RELEASED one time, why extra definitions... I mean such a simple include should not have many useless stuff: i dont see any problem here"

It's not a problem, but you should undef them in the end of the include because they don't have a need throughout the rest of the code.

Other than that, good luck with the release.
__________________
DW4 Community
Variable™ is online now   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Player key state detects key release for no reason PaulDinam Scripting Help 0 15/12/2015 11:52 AM
Command that detects player's same IP? D1am0nd Scripting Help 3 10/11/2015 01:46 PM
[Include] OnPlayerShotTeamVeh - Detects if player shoots team mate's vehicle Maximus0 Includes 7 14/02/2015 02:40 PM


All times are GMT. The time now is 01:16 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.