SA-MP Forums Archive
Spawn vehicle + player virtual world - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Spawn vehicle + player virtual world (/showthread.php?tid=489408)



Spawn vehicle + player virtual world - Riddick94 - 22.01.2014

pawn Код:
CMD:v(playerid, params[])
{
    new vehicleid, string[128];
    if(sscanf(params, "d", vehicleid))return SendClientMessage(playerid, -1, "Usage: /v [vehicleid]");
    {
        new Float:X, Float:Y, Float:Z, Float:Angle;
        GetPlayerPos(playerid, X, Y, Z);
        GetPlayerFacingAngle(playerid, Angle);
        CreateVehicle(vehicleid, X, Y, Z, Angle, random(10), random(10), -1);
        SetVehicleVirtualWorld(vehicleid, GetPlayerVirtualWorld(playerid));
    }
    return 1;
}
Anybody has a problem with it as me? Players virtual world is: 501. So basically, it should set vehicle virtual world to 501, but it doesn't. It sets to: 0, why?


Re: Spawn vehicle + player virtual world - Hansrutger - 22.01.2014

Try to make the car an object:
pawn Код:
CMD:v(playerid, params[])
{
    new vehicleid, string[128];
    if(sscanf(params, "d", vehicleid))return SendClientMessage(playerid, -1, "Usage: /v [vehicleid]");
    {
        new Float:X, Float:Y, Float:Z, Float:Angle, carObject;
        GetPlayerPos(playerid, X, Y, Z);
        GetPlayerFacingAngle(playerid, Angle);
        carObject = CreateVehicle(vehicleid, X, Y, Z, Angle, random(10), random(10), -1);
        SetVehicleVirtualWorld(carObject, GetPlayerVirtualWorld(playerid));
    }
    return 1;
}

For more vehicles to spawn, make sure to declare carObject as an array above in your script. Not sure if this works, I haven't really made any cars in samp yet, but it's like this objects works. Maybe it's the GetPlayerVirtualWorld part that is messing it up though. But don't see how it should. :S


Re: Spawn vehicle + player virtual world - Riddick94 - 22.01.2014

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
Try to make the car an object:
pawn Код:
CMD:v(playerid, params[])
{
    new vehicleid, string[128];
    if(sscanf(params, "d", vehicleid))return SendClientMessage(playerid, -1, "Usage: /v [vehicleid]");
    {
        new Float:X, Float:Y, Float:Z, Float:Angle, carObject;
        GetPlayerPos(playerid, X, Y, Z);
        GetPlayerFacingAngle(playerid, Angle);
        carObject = CreateVehicle(vehicleid, X, Y, Z, Angle, random(10), random(10), -1);
        SetVehicleVirtualWorld(carObject, GetPlayerVirtualWorld(playerid));
    }
    return 1;
}

For more vehicles to spawn, make sure to declare carObject as an array above in your script. Not sure if this works, I haven't really made any cars in samp yet, but it's like this objects works. Maybe it's the GetPlayerVirtualWorld part that is messing it up though. But don't see how it should. :S
Oh crap, I forgot that we can change vehicle virtual world to the vehicleid (returned by CreateVehicle). Silly me, huh. Thanks.