SetTimer("Loop", 1000, 1); //under ongamemodeinit
forward Loop();
public Loop(){
for(new playerid; playerid < MAX_PLAYERS; playerid++){
if(GetPlayerVehicleID(playerid) == JobVehicle[playerid] /*for example*/ && InJob[playerid] == 1 && IsPlayerInRangeOfPoint(playerid, 10, x, y, z) && 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(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;
}
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.
|
ObjectArea[id] = CreateDynamicSphere(x, y, z, size, worldid, interiorid, -1);
public OnPlayerEnterDynamicArea(playerid, areaid)
{
for(new i = 0; i < 100; i++)
{
if(ObjectArea[i])
{
//speed and destruction code here
}
}
return 1;
}
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] |
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.
|