PDA

View Full Version : stock CreateVelocity [Help]


[D]ry[D]esert
02/11/2012, 11:18 AM
Hello every one, i would like to know why when i pass on velocity it make me slow(not what type in the command).
the command is /velocity speed:x speed:y speed:z
Here is my code

//at the top
#define MAX_VELOCITY 500
#define UPDATE_PICKUPS_TIMER 1
new VelocityCounter;
enum vinfo
{
Float:Pos[3],
Float:V[3]
};
new VELOCITY[MAX_VELOCITY][vinfo];


public OnGameModeInit()
{
SetTimer("Velocity",UPDATE_PICKUPS_TIMER,true);
return 1;
}


forward Velocity();
public Velocity()
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
for(new x; x<VelocityCounter; x++)
{
if(IsPlayerInRangeOfPoint(i,1,VELOCITY[x][Pos][0],VELOCITY[x][Pos][1],VELOCITY[x][Pos][2]))
{
if(IsPlayerInAnyVehicle(i))
{
new Float:X,Float:Y,Float:Z;
GetVehicleVelocity(GetPlayerVehicleID(i),X,Y,Z);
SetVehicleVelocity(GetPlayerVehicleID(i),X*VELOCIT Y[x][V][0],Y*VELOCITY[x][V][1],Z*VELOCITY[x][V][2]);
}
}
}
}
}
}

and Here is the command for Creating velocity

CMD:velocity(playerid,params[])
{
new Float:v[3];
if(sscanf(params, "ddd", v[0],v[1],v[2])) return SendClientMessage(playerid, 0xFF0000AA, "Command Usage: /velocity [x:speed] [y:speed] [z:speed]");
new Float:PoS[3];
GetPlayerPos(playerid,PoS[0],PoS[1],PoS[2]);
CreateVelocity(PoS[0],PoS[1],PoS[2],v[0],v[1],v[2]);
SendClientMessage(playerid,-1,"Velocity added");
return 1;
}


stock CreateVelocity(Float:x,Float:y,Float:z,Float:vx,Fl oat:vy,Float:vz)
{
Create3DTextLabel("[Velocity]",0xDEEE20FF,x,y,z,100,0);
VELOCITY[VelocityCounter][Pos][0] = x;
VELOCITY[VelocityCounter][Pos][1] = y;
VELOCITY[VelocityCounter][Pos][2] = z;
VELOCITY[VelocityCounter][V][0] = vx;
VELOCITY[VelocityCounter][V][1] = vy;
VELOCITY[VelocityCounter][V][2] = vz;
VelocityCounter++;
return 1;
}

Thanks.

[D]ry[D]esert
02/11/2012, 12:27 PM
You've not actually posted your "CreateVelocity" function.
Ah, added
why are you using arrays to hold three variables?
That wont make different i gusse ?

[D]ry[D]esert
02/11/2012, 01:11 PM
You've not actually posted your "CreateVelocity" function. And why are you using arrays to hold three variables?

No, but I've just spotted the problem - you use "d" not "f" in "sscanf". Try "extract":


extract params -> new Float:vx, Float:vy, Float:vz; else return SendClientMessage(playerid, 0xFF0000AA, "Command Usage: /velocity [x:speed] [y:speed] [z:speed]");


Vastly reduces bugs due to incorrect specifiers by removing the specifiers. You can also still use arrays:


extract params -> new Float:v[3]; else return SendClientMessage(playerid, 0xFF0000AA, "Command Usage: /velocity [x:speed] [y:speed] [z:speed]");


Aha.
Thanks its work now.