SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 12/01/2012, 05:47 PM   #1
iPLEOMAX
High-roller
 
iPLEOMAX's Avatar
 
Join Date: Mar 2011
Location: AE
Posts: 1,251
Reputation: 744
Thumbs up "OnPlayerLookAtVehicle" - Detect if a player is looking at some vehicle.

OnPlayerLookAtVehicle V2*

Info:
Detects if a player is looking at any vehicle and executes a callback on any change.

How it works:
Uses Camera Vector, Position, Streamed Vehicles & your distance between the vehicle to calculate, etc..

Callback & Natives:
pawn Code:
//To Enable this for a player. (If you forget to do this, it won't work!)
EnableVehicleLookAt(playerid);

//The following Callback is called when a player has his camera's point of view towards a vehicle.
public OnPlayerLookAtVehicle(playerid, vehicleid, Float:distance)
{
    new message[128];
    format(message, sizeof message,
    "You are looking at vehicle id %i with a distance of %f meters.", vehicleid, distance);
    SendClientMessage(playerid, -1, message);
    return true;
}

//To disable the lookat system for a player. (Good thing to put it under OnPlayerDisconnect)
DisableVehicleLookAt(playerid);

Are you looking for IsPlayerLookingAt(vehicle ... object ... player) ?
http://forum.sa-mp.com/showpost.php?...postcount=2946

What can I do with it?
Few ideas:
- Make a showroom featuring TDU2's style. (I have done one)
Don't get it? I mean, if you point at any vehicle, it shows up it's name, price, top speed etc with textdraws. (It's cool TBH).

-Making other such thingies

Video Demonstration:
[ame]http://www.youtube.com/watch?v=LOYfW008PNU[/ame]

Download:
LATEST (V2.0)
"OPLAV.inc" V2 raw - Pastebin
OPLAV.V2.pleomax.rar - MediaFire
Requirement: You need YSI Server Includes to make this work!

OLD:
"vla.inc" raw - Pastebin
VLA Include (RAR) - MediaFire

Changelogs:
Code:
Version 1.0:
- Initial Release.

Version 2.0:
- Optimized the code hence increased performance/efficiency.
- Now uses a collection of player's streamed vehicles to check for the 'lookat'. (Thanks to "Kar" for the idea ;))
- Removed "oldvehicle" parameter from the callback since it's useless.
- Added Float:distance parameter to the callback.
- Uses y_hook to hook with the default callbacks.
__________________
Goodbye SA-MP.

Last edited by iPLEOMAX; 28/01/2012 at 07:35 PM.
iPLEOMAX is offline   Reply With Quote
Old 12/01/2012, 05:51 PM   #2
T0pAz
Guest
 
Posts: n/a
Default Re: "OnPlayerLookAtVehicle" - Detect if a player is looking at some vehicle.

I was in need of this. Thanks!
  Reply With Quote
Old 12/01/2012, 05:58 PM   #3
TheArcher
High-roller
 
TheArcher's Avatar
 
Join Date: Dec 2009
Location: Home
Posts: 2,333
Reputation: 251
Default Re: "OnPlayerLookAtVehicle" - Detect if a player is looking at some vehicle.

I took a look at the code, and seems good scripted and faster. It's very useful though but i didn't understand what EnableVehicleLookAt(playerid); function is used for. Yes for enable/disable the function for a player but why? Good job tough.
__________________
TheArcher is offline   Reply With Quote
Old 12/01/2012, 06:01 PM   #4
iPLEOMAX
High-roller
 
iPLEOMAX's Avatar
 
Join Date: Mar 2011
Location: AE
Posts: 1,251
Reputation: 744
Default Re: "OnPlayerLookAtVehicle" - Detect if a player is looking at some vehicle.

Quote:
Originally Posted by T0pAz View Post
I was in need of this. Thanks!
Glad it helped you.

Quote:
Originally Posted by TheArcher View Post
I took a look at the code, and seems good scripted and faster. It's very useful though but i didn't understand what EnableVehicleLookAt(playerid); function is used for. Yes for enable/disable the function for a player but why? Good job tough.
Nothing much actually.. I thought adding these functions would be better because sometimes you don't wanna run this system on each player all the time.. Too much for nothing.

Upto you guys, like Enable on Connect & done! It'll stay active all the time.
__________________
Goodbye SA-MP.
iPLEOMAX is offline   Reply With Quote
Old 12/01/2012, 06:08 PM   #5
Hoss
Big Clucker
 
Join Date: Sep 2010
Posts: 186
Reputation: 85
Default Re: "OnPlayerLookAtVehicle" - Detect if a player is looking at some vehicle.

WoW
Good job pleo!
Hoss is offline   Reply With Quote
Old 12/01/2012, 06:22 PM   #6
System64
Gangsta
 
System64's Avatar
 
Join Date: May 2011
Location: Zadar, Croatia
Posts: 933
Reputation: 143
Default Re: "OnPlayerLookAtVehicle" - Detect if a player is looking at some vehicle.

wow this is awesome job, such a good idea and script

Next time use y_hooks and foreach
__________________
All my works
I left SA:MP! Maybe once I start scripting again but now I'm based on web programming
Soon, I'll buy domain system32.com.hr but for now you can contact me on LogoOff or on my Youtube channel!
System64 is offline   Reply With Quote
Old 12/01/2012, 06:34 PM   #7
TheArcher
High-roller
 
TheArcher's Avatar
 
Join Date: Dec 2009
Location: Home
Posts: 2,333
Reputation: 251
Default Re: "OnPlayerLookAtVehicle" - Detect if a player is looking at some vehicle.

Quote:
Originally Posted by System64 View Post
wow this is awesome job, such a good idea and script

Next time use y_hooks and foreach
This include is fine how is it right now. It ingrease the speed with those add-ons. Anyways he can hook manualy.
__________________
TheArcher is offline   Reply With Quote
Old 12/01/2012, 06:54 PM   #8
Voldemort
Gangsta
 
Voldemort's Avatar
 
Join Date: Aug 2010
Posts: 560
Reputation: 26
Default Re: "OnPlayerLookAtVehicle" - Detect if a player is looking at some vehicle.

Sounds usefull and interesting, great job



btw, your siggi: New Funtions! , small mistake
__________________


Voldemort is offline   Reply With Quote
Old 13/01/2012, 11:23 AM   #9
iPLEOMAX
High-roller
 
iPLEOMAX's Avatar
 
Join Date: Mar 2011
Location: AE
Posts: 1,251
Reputation: 744
Default Re: "OnPlayerLookAtVehicle" - Detect if a player is looking at some vehicle.

Quote:
Originally Posted by Hoss View Post
WoW
Good job pleo!
Quote:
Originally Posted by Voldemort View Post
Sounds usefull and interesting, great job
btw, your siggi: New Funtions! , small mistake
Thanks guys.
@Voldemort: Edited xD

Quote:
Originally Posted by System64 View Post
wow this is awesome job, such a good idea and script

Next time use y_hooks and foreach
Thanks & Alright, I'll post a foreach+y_hooks version too just in case (But I guess 'foreach' wouldn't make much difference here though).
__________________
Goodbye SA-MP.
iPLEOMAX is offline   Reply With Quote
Old 13/01/2012, 12:12 PM   #10
kizla
Big Clucker
 
kizla's Avatar
 
Join Date: Dec 2009
Posts: 173
Reputation: 50
Default Re: "OnPlayerLookAtVehicle" - Detect if a player is looking at some vehicle.

Awesome script, i love it
__________________
Tutorials
Abstract Machine eXecutor / emits
kizla is offline   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
"Slight homing", make a missile "Slightly!" home a vehicle. Donya Help Archive 4 11/06/2011 10:20 PM
Is player talks, use OnePlayAnim(playerid,"PED","IDLE_CHAT",4.0,0,0,0,0,0); Ihsan_Cingisiz Help Archive 5 30/05/2010 04:26 PM
Admin script requires "ReturnUser", "strtok" and "IsNumeric" Rubennnnn Help Archive 1 02/12/2009 07:08 PM
"Bots", "AI", "NPCs"... Computer-controlled pedestrians and traffic! ssflsnoob General 2 23/11/2008 07:06 PM


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


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