Magnetic object SetPlayerVelocity?
#1

So I've wrote up some messy code but I don't understand how SetPlayerVelocity works

PHP код:
#include <a_samp>
#include <foreach>
#define PRESSED(%0) \
    
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
new 
Wreckball[MAX_PLAYERS];
new 
CountWreck[MAX_PLAYERS];
new 
Float:MoveToTargetX[MAX_PLAYERS];
new 
Float:MoveToTargetY[MAX_PLAYERS];
new 
Float:MoveToTargetZ[MAX_PLAYERS];
public 
OnFilterScriptExit()
{
    for(new 
0MAX_PLAYERSo++)
    {
        
DestroyObject(Wreckball[o]);
    }
    return 
1;
}
public 
OnPlayerDisconnect(playerid)
{
    
DestroyObject(Wreckball[playerid]);
    return 
1;
}
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
PRESSED(KEY_FIRE))
    {
        if(
CountWreck[playerid] == 0)
        {
            
CountWreck[playerid] = 1;
            new 
Float:XFloat:YFloat:Z;
            
GetPlayerPos(playeridXYZ);
            
Wreckball[playerid] = CreateObject(18845XYZ+201800300);
            
GetPlayerCameraLookAt(playeridXYZ);
            
MoveToTargetX[playerid] = X;
            
MoveToTargetY[playerid] = Y;
            
MoveToTargetZ[playerid] = Z;
            
SetTimerEx("MoveFuckingObject"7500"i"playerid);
        }
        return 
1;
    }
    return 
1;
}
forward MoveFuckingObject(playerid);
public 
MoveFuckingObject(playerid)
{
        
MoveObject(Wreckball[playerid], MoveToTargetX[playerid], MoveToTargetY[playerid], MoveToTargetZ[playerid], 100.001800);
     
//    foreach(Player,i)
         
{
     
//    if(team[i] == TEAM_ZOMBIE)
               // GetPlayerPos(i, X, Y, Z);
                //GetXYInFrontOfPlayer(i, X, Y, 0.2);
               // SetPlayerVelocity(i, 0.0, 0.0, 0.2);
                
}
    return 
1;
}
stock GetXYInFrontOfPlayer(playerid, &Float:x2, &Float:y2Float:distance)
{
    new 
Float:a;
    
GetPlayerPos(playeridx2y2a);
    
GetPlayerFacingAngle(playerida);
    
x2 += (distance floatsin(-adegrees));
    
y2 += (distance floatcos(-adegrees));
}
stock GetXYBackOfPlayer(const playerid, &Float:x, &Float:y, const Float:distance)
{
    new 
Float:a;
    
GetPlayerPos(playeridxya);
    
GetPlayerFacingAngle(playerida);
    
-= (distance floatsin(-adegrees));
    
-= (distance floatcos(-adegrees));
}
stock GetXYBackOfObject(const playerid, &Float:x, &Float:y, const Float:distance)
{
    new 
Float:a;
    
GetPlayerFacingAngle(playerida);
    
-= (distance floatsin(-adegrees));
    
-= (distance floatcos(-adegrees));
}
stock GetXYRightOfPlayer(playerid, &Float:X, &Float:YFloat:distance)
{
    new 
Float:Angle;
    
GetPlayerFacingAngle(playeridAngle); Angle -= 90.0;
    
+= floatmul(floatsin(-Angledegrees), distance);
    
+= floatmul(floatcos(-Angledegrees), distance);
}
GetPlayerCameraLookAt(playerid, &Float:X, &Float:Y, &Float:Z)
{
    new 
Float:Destination[3], Float:Camera[3], Float:Vector[3];
    
GetPlayerPos(playeridDestination[0], Destination[1], Destination[2]);
    
GetPlayerCameraPos(playeridCamera[0], Camera[1], Camera[2]);
    
GetPlayerCameraFrontVector(playeridVector[0], Vector[1], Vector[2]);
    new 
FloatposAngle atan2(floatsub(Destination[1],Camera[1]),floatsub(Destination[0],Camera[0]));
    if(
posAngle 360posAngle-=360posAngle+=270posAngle *= -1;
    
Destination[0] += 50.0 floatsin(posAngledegrees);
    
Destination[1] += 50.0 floatcos(posAngledegrees);
    new 
Float:dis floatsqroot((Camera[0] - Destination[0]) * (Camera[0] - Destination[0]) + (Camera[1] - Destination[1]) * (Camera[1] - Destination[1]) + (Camera[2] - Destination[2]) * (Camera[2] - Destination[2]));
    
Vector[0] * dis Camera[0]; Vector[1] * dis Camera[1];       Vector[2] * dis Camera[2];

Basically the player shoots this object then the other players should be dragged into the object with SetPlayerVelocity not SetPlayerPos
what I've tried (KEWL LOL)
PHP код:
forward MoveFuckingObject(playerid);
public 
MoveFuckingObject(playerid)
{
        
MoveObject(Wreckball[playerid], MoveToTargetX[playerid], MoveToTargetY[playerid], MoveToTargetZ[playerid], 100.001800);
     
//    foreach(Player,i)
         
{
     
//    if(team[i] == TEAM_ZOMBIE)
               // GetPlayerPos(i, X, Y, Z);
                //GetXYInFrontOfPlayer(i, X, Y, 0.2);
               // SetPlayerVelocity(i, 0.0, 0.0, 0.2);
                
}
    return 
1;

Would appreciate any help, thanks.
Reply
#2

I like the concept! I'll try to compile and run your function - perhaps when I get home, perhaps tomorrow (sorry gotta sleep and currently at work ) and see what's going on, unless someone already fixed it by then. I like the name of the function BTW.
Reply
#3

Bump
Reply
#4

Okay so I didn't run your code yet but from what I can see you're missing some extra trigonometry to calculate the velocity vector from the player to the ball, weighted by the (cubic root?) distance in between. I didn't have time to compile your code yet, let alone work on it, but will help you as soon as I get some free time.
Reply
#5

Quote:
Originally Posted by TheCman
Посмотреть сообщение
Okay so I didn't run your code yet but from what I can see you're missing some extra trigonometry to calculate the velocity vector from the player to the ball, weighted by the (cubic root?) distance in between. I didn't have time to compile your code yet, let alone work on it, but will help you as soon as I get some free time.
Already solved by mua!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)