This Slows The server
#1

When I put This In the Script the server slows so the commands could work after about 15-25 secs
pawn Код:
stock RocketPos(vehid,Float:x,Float:y,Float:z)
{
    new model = GetVehicleModel(vehid);
    switch(model)
    {
        case 411: return GetDynamicObjectPos(infmgun[vehid],x,y,z);
    }
    return 1;
}
use
pawn Код:
RocketPos(vehicleid,x,y,z);
Reply
#2

Try:
pawn Код:
stock RocketPos(vehid, Float:x, Float:y, Float:z)
{
    if(GetVehicleModel(vehid)) == 411)
    {
        GetDynamicObjectPos(infmgun[vehid], x, y, z);
        return 1;
    }
    return 1;
}
Reply
#3

Put the command or whatever it is where you use RocketPos function
Reply
#4

@Opah: What are you exactly trying to do? Currently, that code doesn't do anything. It tries to get a position, but that position isn't used anywhere and it'll just be trown away.

@Income: Well, that's an amazing improvement! It still doesn't do shit.
Reply
#5

@Basssiiie
Actually as you see the position is used to return the position of the object
Reply
#6

Nope, it doesn't return the position. It returns what the GetDynamicObjectPos would return if your did "new variable = GetDynamicObjectPos", which is probably either 0 or 1, depending on if the function was processed correctly.
Reply
#7

pawn Код:
stock RocketPos(vehid, Float:x, Float:y, Float:z)
    return GetVehicleModel(vehid) == 411 ? GetDynamicObjectPos(infmgun[vehid], x, y, z) : -1;
Try this, I doubt it ought to do much but I'm sure on success GetDynamicObjectPos returns 1 thus toggling another feature in the script?

Anyhow, I doubt this would be the cause. Can you show us the portion where this is functioning?
Reply
#8

This shouldn't even lag your server... it's only a stock.
How did you define this variable?
infmgun[vehid]
Reply
#9

ok guys the stock is now unusful i could simply do
pawn Код:
GetDynamicObjectPos(infmgun[vehid],x,y,z);
but the point is i am adding other cases like
pawn Код:
case 453: return GetDynamicObjectPos(reefmgun[vehid],x,y,z);
the hall code is:
pawn Код:
native IsValidVehicle(vehicleid);
new missilet;
new vehhasrocket[MAX_VEHICLES]
,infmgun[MAX_VEHICLES]
,infmgunextra[MAX_VEHICLES]
,ClosestVehicle[MAX_VEHICLES]
;
forward missile(vehid);
public missile(vehid)
    {
    print("timer started");
    new Float:ox,Float:oy,Float:oz;
    RocketPosExtra(vehid,ox,oy,oz);
    printf("rocket pos %f %f %f",ox,oy,oz);
    printf("%f",GetVehicleDistanceFromPoint(ClosestVehicle[vehid],ox,oy,oz));
    if(GetVehicleDistanceFromPoint(ClosestVehicle[vehid],ox,oy,oz) > 5)
        {
        UpdateMissile(infmgunextra[vehid],ClosestVehicle[vehid]);
        print("missile updated");
        }else{
        DestroyObject(infmgunextra[vehid]);
        print("object destroyed");
        CreateExplosion(ox,oy,oz,7,10);
        print("explosion created");
        KillTimer(missilet);
    }
    return 1;
}
stock RocketPos(vehid,Float:x,Float:y,Float:z)
    {
    new model = GetVehicleModel(vehid);
    switch(model)
    {
        case 411: return GetDynamicObjectPos(infmgun[vehid],x,y,z);
    }
    return 1;
}

stock RocketPosExtra(vehid,Float:x,Float:y,Float:z)
    {
    new model = GetVehicleModel(vehid);
    switch(model)
    {
        case 411: return GetDynamicObjectPos(infmgunextra[vehid],x,y,z);
    }
    return 1;
}
forward VehicleHasDriver(vehicleid);
public VehicleHasDriver(vehicleid)
    {
    for(new i=0;i<=MAX_PLAYERS;i++)
        {
        if(IsPlayerInAnyVehicle(i))
            {
            if(GetPlayerVehicleID(i)==vehicleid)
                {
                if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
                    {
                    return 1;
                }
            }
        }
    }
    return 0;
}
GetClosestVehicleFromVehicle(vehicleid)
{
    new
    Float:X,
    Float:Y,
    Float:Z,
    Float:Distance,
    Float:DefaultDistance = 150,
    vID = INVALID_VEHICLE_ID;
   
    GetVehiclePos(vehicleid,X,Y,Z);
   
    for(new carid = 1; carid != MAX_VEHICLES; carid++)
        if(IsValidVehicle(carid))
        {
        if(carid != vehicleid)
            {
            if(VehicleHasDriver(carid))
                {
                Distance = GetVehicleDistanceFromPoint(carid, X, Y, Z);
                if(Distance < DefaultDistance)
                    {
                    DefaultDistance = Distance;
                    vID = carid;
                }
            }
        }
    }
   
    return vID;
}
stock Float:GetAngleFromPosToPos(Float:X, Float:Y, Float:PointX, Float:PointY)
    {
    new Float:Angle;
    if(X > PointX && Y > PointY)
        Angle = floatabs(atan2(floatsub(PointX, X), floatsub(PointY, Y)));
    if(X > PointX && Y <= PointY)
        Angle = floatadd(floatabs(atan2(floatsub(Y, PointY), floatsub(PointX, X))), 270.0);
    if(X <= PointX && Y > PointY)
        Angle = floatadd(floatabs(atan2(floatsub(PointY, Y), floatsub(X, PointX))), 90.0);
    if(X <= PointX && Y <= PointY)
        Angle = floatadd(floatabs(atan2(floatsub(X, PointX), floatsub(Y, PointY))), 180.0);
   
    return Angle >= 360.0 ? floatsub(Angle, 360.0) : Angle;
}

//This function makes objectid point to vehicle and move towards it
stock UpdateMissile(objectid, targetvehicle)
    {
    new
    Float: fFromX,
    Float: fFromY,
    Float: fFromZ,
    Float: fToX,
    Float: fToY,
    Float: fToZ
    ;
   
    //save pos of missile and target so we can do angle calculations
    GetDynamicObjectPos(objectid, fFromX, fFromY, fFromZ);
    GetVehiclePos(targetvehicle, fToX, fToY, fToZ);
   
    //get angle to target
    new Float: fTargetAngle = GetAngleFromPosToPos(fFromX, fFromY, fToX, fToY);
   
    //This is where you need to get offsets
    //these are offsets i made for the arrow object (works perfect with the white arrow object)
    SetDynamicObjectRot(objectid, 0.0, 0, 180+fTargetAngle);
   
    //use your own speeds for the missile
    MoveDynamicObject(objectid, fToX, fToY, fToZ, 150.0);
}
public OnVehicleSpawn(vehicleid)
    {
    new model = GetVehicleModel( vehicleid );
    switch(model)
    {        
        case  411:
        {
            if( vehhasrocket[ vehicleid ] == 0 ) {
                vehhasrocket[ vehicleid ] = 1;
                infmgun[vehicleid] = CreateDynamicObject( 3790, 0, 0, 0, 0, 0, 0 );
                AttachDynamicObjectToVehicle( infmgun[vehicleid], vehicleid, 02, 0, 0, 0.000000, 0.000000, 90); //Object Model: 2985 |
                minigunnum ++;
            }
           
        }
    }
    return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
    {
    new vehid = GetPlayerVehicleID(playerid);
    if(PRESSED(KEY_FIRE) && vehhasrocket[vehid] == 1)
        {
        new Float:x,Float:y,Float:z;
        vehhasrocket[vehid] = 0;
        RocketPos(vehid,x,y,z);
        printf("rocket pos %f %f %f",x,y,z);
        infmgunextra[vehid] = CreateDynamicObject(3790,x+2,y,z,0,0,180);
        printf("created in %f %f %f",x+2,y,z);
        DestroyDynamicObject(infmgun[vehid]);
        ClosestVehicle[vehid] = GetClosestVehicleFromVehicle(vehid);
        printf("Got closest vehicle : %i",ClosestVehicle[vehid]);
        UpdateMissile(infmgunextra[vehid],ClosestVehicle[vehid]);
        print("updated");
        missilet = SetTimerEx("missile",250,1,"i",vehid);
        print("timerSet");
       
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)