Vehicle interaction
#1

Hello everybody. Is it possible to investigate the interaction of the object and vehicle? I mean, I have an object then if the player in the vehicle knocks down this object, there must be called some function. Is it possible to do in SA-MP?

I tried to use dynamic areas. But they didn't work, because the object is too small, and streamer can't work accurately. I also tried to use pickups, I mean, I hid them under objects (used modelid -1 to make them invisible), but this method also failed, the same story as dynamic areas.
Reply
#2

No, there is no function. BUT
You can try making a 1 second timer that is looping
PHP код:
SetTimer("Loop"10001); //under ongamemodeinit 
and check the player pos, speed and vehicle id.

PHP код:
forward Loop();
public 
Loop(){
    for(new 
playeridplayerid MAX_PLAYERSplayerid++){
        if(
GetPlayerVehicleID(playerid) == JobVehicle[playerid/*for example*/ && InJob[playerid] == && IsPlayerInRangeOfPoint(playerid10xyz) && GetVehicleSpeed(GetPlayerVehicleID(playerid)) > 10){
            
DestroyObject(TheObjectThatThePlayerMustDestroy[playerid]);
            
//when the object is destroyed
        
}
    }
}
stock GetVehicleSpeed(vehicleid)
{
        if(
vehicleid != INVALID_VEHICLE_ID)
        {
                new 
Float:Pos[3],Float:VS ;
                
GetVehicleVelocity(vehicleidPos[0], Pos[1], Pos[2]);
                
VS floatsqroot(Pos[0]*Pos[0] + Pos[1]*Pos[1] + Pos[2]*Pos[2])*200;
                return 
floatround(VS,floatround_round);
        }
        return 
INVALID_VEHICLE_ID;

Reply
#3

Thank you for answering, but firstly: your method cannot accurately determine the interaction, because the time interval is 1 second. If I decrease the interval then function become unoptimized, and can badly affect server optimization.
Reply
#4

Quote:
Originally Posted by Geebrox
Посмотреть сообщение
Thank you for answering, but firstly: your method cannot accurately determine the interaction, because the time interval is 1 second. If I decrease the interval then function become unoptimized, and can badly affect server optimization.
You can use streamer areas instead of timers!

PHP код:
ObjectArea[id] = CreateDynamicSphere(xyzsizeworldidinteriorid, -1); 
PHP код:
public OnPlayerEnterDynamicArea(playeridareaid)
{
    for(new 
0100i++)
    {
        if(
ObjectArea[i])
        {
            
//speed and destruction code here
        
}    
    }
    return 
1;

Reply
#5

Quote:
Originally Posted by Vennox
Посмотреть сообщение
No, there is no function. BUT
You can try making a 1 second timer that is looping
stock GetVehicleSpeed(vehicleid)
{
if(vehicleid != INVALID_VEHICLE_ID)
{
new Float:Pos[3],Float:VS ;
GetVehicleVelocity(vehicleid, Pos[0], Pos[1], Pos[2]);
VS = floatsqroot(Pos[0]*Pos[0] + Pos[1]*Pos[1] + Pos[2]*Pos[2])*200;
return floatround(VS,floatround_round);
}
return INVALID_VEHICLE_ID;
}
[/PHP]
It should be between "180.0" and "181.5" "200.0" will give incorrect results.
Reply
#6

Quote:
Originally Posted by Geebrox
Посмотреть сообщение
Thank you for answering, but firstly: your method cannot accurately determine the interaction, because the time interval is 1 second. If I decrease the interval then function become unoptimized, and can badly affect server optimization.
No it won't if you do it cleverly.

Create a large area for the object. Then get all players that are in the specified area & meet the conditions. For those players (should only be a few, if any) you can run the desired code at a high frequency without problems. We're only talking about float comparisons, not a physics engine. You're not even sending packets at a high frequency, just check the coords.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)