Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #define Distance 50.0
- new bool:IsAttached[MAX_VEHICLES] = false;
- new missile_object[MAX_VEHICLES];
- new Float:VehPos[MAX_VEHICLES][3];
- new Float:VehCameraPos[MAX_VEHICLES][3];
- new Float:VehVectorPos[MAX_VEHICLES][3];
- new Float:OffSet[MAX_VEHICLES][3];
- const Float:Dist = Distance;
- public OnFilterScriptInit()
- {
- SetTimer("CheckPos",10,true);
- return 1;
- }
- forward AttachMissileToVehicle(vehicleid,Float:OffSetX,Float:OffSetY,Float:OffSetZ);
- public AttachMissileToVehicle(vehicleid,Float:OffSetX,Float:OffSetY,Float:OffSetZ)
- {
- IsAttached[vehicleid] = true;
- OffSet[vehicleid][0] = OffSetX;
- OffSet[vehicleid][1] = OffSetY;
- OffSet[vehicleid][2] = OffSetZ;
- GetVehiclePos(vehicleid,VehPos[vehicleid][0],VehPos[vehicleid][1],VehPos[vehicleid][2]);
- missile_object[vehicleid] = CreateObject(360,VehPos[vehicleid][0]+OffSetX,VehPos[vehicleid][1]+OffSetY,VehPos[vehicleid][2]+OffSetZ,0.0,0.0,0.0,400);
- return 1;
- }
- forward DeAttachMissileFromVehicle(vehicleid);
- public DeAttachMissileFromVehicle(vehicleid)
- {
- IsAttached[vehicleid] = false;
- DestroyObject(missile_object[vehicleid]);
- return 1;
- }
- stock GetVehicleDriver(vehicleid)
- {
- for(new i=0; i<MAX_PLAYERS, IsPlayerConnected(i); i++)
- {
- if(GetPlayerVehicleID(i) == vehicleid && GetPlayerState(i) == PLAYER_STATE_DRIVER) return i;
- }
- return INVALID_PLAYER_ID;
- }
- forward CheckPos();
- public CheckPos()
- {
- for(new i = 0; i < MAX_VEHICLES; i++)
- {
- if(IsAttached[i] == true)
- {
- GetVehiclePos(i,VehPos[i][0],VehPos[i][1],VehPos[i][2]);
- SetObjectPos(missile_object[i],VehPos[i][0]+OffSet[i][0],VehPos[i][1]+OffSet[i][1],VehPos[i][2]+OffSet[i][2]);
- GetPlayerCameraPos(GetVehicleDriver(i),VehCameraPos[i][0],VehCameraPos[i][1],VehCameraPos[i][2]);
- GetPlayerCameraFrontVector(GetVehicleDriver(i),VehVectorPos[i][0],VehVectorPos[i][1],VehVectorPos[i][2]);
- SetObjectRot(missile_object[i],0.0,-asin(VehVectorPos[i][2]),90 - atan2(VehVectorPos[i][0],VehVectorPos[i][1]));
- }
- }
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(newkeys & KEY_FIRE)
- {
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
- {
- for(new i = 0; i < MAX_VEHICLES; i++)
- {
- if(IsAttached[i] == true)
- {
- if(GetPlayerVehicleID(playerid) == i)
- {
- new i2 = GetPlayerVehicleID(playerid);
- CreateExplosion(VehCameraPos[i2][0]+(VehVectorPos[i2][0] * Dist),VehCameraPos[i2][1]+(VehVectorPos[i2][1] * Dist),VehCameraPos[i2][2]+(VehVectorPos[i2][2] * Dist),7,100);
- }
- }
- }
- }
- }
- return 1;
- }
- public OnPlayerCommandText(playerid,cmdtext[])
- {
- if(strcmp(cmdtext,"/attachmissile",true) == 0)
- {
- if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
- {
- AttachMissileToVehicle(GetPlayerVehicleID(playerid),0,0,1.01);
- }
- else return SendClientMessage(playerid,0xFFFFFFFF,"ERROR: You are not driving any vehicle!");
- return 1;
- }
- return 0;
- }
- public OnFilterScriptExit()
- {
- for(new i = 0; i < MAX_VEHICLES; i++)
- {
- if(IsAttached[i] == true)
- {
- DestroyObject(missile_object[i]);
- IsAttached[i] = false;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement