pirateship command help
#1

Код:
//Pirate Ship by TonyII

#include <a_samp>
#include <zcmd>

new PirateObject,
	PirateFence,
	PirateRopes,
	PirateShip;
new Camera;
new ControllingShip[MAX_PLAYERS];

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print("Pirate Ship by TonyII is running");
	print("--------------------------------------\n");
	PirateObject = CreateObject(8493,0,0,-100,0,0,0);
	PirateFence = CreateObject(9159,0,0,-100,0,0,0);
	PirateRopes = CreateObject(8981,0,0,-100,0,0,0);
	PirateShip = AddStaticVehicleEx(454, 723.6520, -1890.7867, -0.0164, 180.0000, -1, -1, -1);
	AttachObjectToVehicle(PirateObject, PirateShip, 0.809999, 1.439998, 16.650209, 0.000000, 0.000000, 0.000000);
	AttachObjectToVehicle(PirateRopes, PirateShip, 0.294999, -4.665059, 16.250276, 0.000000, 0.000000, 0.000000);
    AttachObjectToVehicle(PirateFence, PirateShip, 0.784999, 1.439998, 16.655208, 0.000000, 0.000000, 0.000000);
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if (newkeys & KEY_SECONDARY_ATTACK)
	{
		if(ControllingShip[playerid] == 1)
		{
		ControllingShip[playerid] = 0;
		new Float:X,Float:Y,Float:Z;
		GetPlayerPos(playerid, X,Y,Z);
		SetPlayerPos(playerid, X,Y+2,Z+6);
		SetCameraBehindPlayer(playerid);
		DestroyObject(Camera);
		}
	}
	return 1;
}

CMD:commandship(playerid, params[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
	{
	if(ControllingShip[i] == 1) return SendClientMessage(playerid, -1,"The ship is being held in command by someone else.");
	}
	Camera = CreateObject(0, 0,0,0,0,0,0);
	AttachObjectToVehicle(Camera, PirateShip,0,-35,23,0.000000,0.000000,0.0);
	PutPlayerInVehicle(playerid, PirateShip, 0);
	AttachCameraToObject(playerid, Camera);
	ControllingShip[playerid] = 1;
	SendClientMessage(playerid, -1,"Type /quitship or press 'F' if you want to stop commanding this ship.");
	return 1;
}

CMD:quitship(playerid, params[])
{
	if(ControllingShip[playerid] == 0) return SendClientMessage(playerid, -1,"You do not command the ship.");
	ControllingShip[playerid] = 0;
	new Float:X,Float:Y,Float:Z;
	GetPlayerPos(playerid, X,Y,Z);
	SetPlayerPos(playerid, X,Y+2,Z+6);
	SetCameraBehindPlayer(playerid);
	DestroyObject(Camera);
	return 1;
}
please help i need to set it so that the player can only use the command if the player is within a set range of the vehicle
i have tried hard please help
Reply
#2

Your last post was removed, so it probably isn't too clever to post another one about the same.
But if you've tried, show your attempt and how it didn't work.
Reply
#3

Put this function somewhere in your script:
Код:
forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
    if(IsPlayerConnected(playerid))
	{
		new Float:oldposx, Float:oldposy, Float:oldposz;
		new Float:tempposx, Float:tempposy, Float:tempposz;
		GetPlayerPos(playerid, oldposx, oldposy, oldposz);
		tempposx = (oldposx -x);
		tempposy = (oldposy -y);
		tempposz = (oldposz -z);
		//printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
		if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
		{
			return 1;
		}
	}
	return 0;
}
And for the command:
Код:
CMD:commandship(playerid, params[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
	{
	if(ControllingShip[i] == 1) return SendClientMessage(playerid, -1,"The ship is being held in command by someone else.");
	}
       if(PlayerToPoint(5.0,playerid,723.6520, -1890.7867, -0.0164)) // 723.6520, -1890.7867, -0.0164 are the coord from your PirateShip(X,Y,Z) and 5.0 is the range between ship and player.
       {
	Camera = CreateObject(0, 0,0,0,0,0,0);
	AttachObjectToVehicle(Camera, PirateShip,0,-35,23,0.000000,0.000000,0.0);
	PutPlayerInVehicle(playerid, PirateShip, 0);
	AttachCameraToObject(playerid, Camera);
	ControllingShip[playerid] = 1;
	SendClientMessage(playerid, -1,"Type /quitship or press 'F' if you want to stop commanding this ship.");
	return 1;
       }
       else SendClientMessage(playerid, -1,"You're not near the PirateShip.");
}
Reply
#4

it works great but im in need of different code rather that playertopoint

i cant get back in the boat unless im in distance of the cooridinates of playertopoint

if you get out of the boat and your not in distance you cant get back in

long story short im looking to set it on some sort of isplayerinrangeofvehicle or something of that kind so that i can drive around in the pirate ship and still be able to get back in...

last but not least if i use playertopoint anybody can just go to that set point and use /commandship and teleport to wherever it is
Reply
#5

I hope your not planning on letting players surf the pirate ship it won't work as expected and just end up killing players / sending them flying.
Reply
#6

Quote:

Re: [HELP]pirateship command help
Your last post was removed, so it probably isn't too clever to post another one about the same.
But if you've tried, show your attempt and how it didn't work.

i just dont know how to use the whole stock function becuase i see plenty of posts exactly what im looking for but i can never fit it in my script i tried googling isplayerinrangeofvehicle and read a bunch of posts and tried the suggestions but maybe i wasnt inserting them into my pwn the correct way

Quote:

Default Re: pirateship command help
I hope your not planning on letting players surf the pirate ship it won't work as expected and just end up killing players / sending them flying.

well the code i tried with a second computer i tried surfing with it and it works just fine maybe because it is on a reefer rather than a fast boat

ive seen videos of this and some people use squallos
Reply
#7

Doesn't matter objects attached to vehicles kill players it's not really usable.
Reply
#8

ok then ill run peoples boats over can some1 just help

if somebody can help by the time they show me the correct script ill know what i was doing wrong this is scripting help thread after all
Reply
#9

Код:
stock IsPlayerInRangeOfVehicle(playerid, veh, Float: range)
{
    if( !IsPlayerConnected( playerid ) ) return 0;
    if( !IsValidVehicle( veh ) ) return 0;

	new Float: x,
        Float: y,
        Float: z
	;
	GetVehiclePos( veh, x, y, z );

	if( IsPlayerInRangeOfPoint( playerid, range, x, y, z ) ) return 1;
	return 0;
}
thank you so much ALY your reply gave me an idea of how the stock funtion works and i ended up finding this code and thanks to you redoing the actual script it was easy for me to insert this stock instead i also added another pirate ship and it works great
Reply
#10

I also just want to let you know you don't need to do
IsPlayerInRangeOfPoint return 1
return 0
You can simply return IsPlayerInRangeOfPoint, since that returns false / 0 if he's not in range, and true / 1 if he is.
pawn Код:
IsPlayerInRangeOfVehicle(playerid, veh, Float: range)
{
    if( !IsPlayerConnected( playerid ) || !IsValidVehicle( veh ) ) return 0;
    new
        Float: x,
        Float: y,
        Float: z
    ;
    GetVehiclePos( veh, x, y, z );
    return IsPlayerInRangeOfPoint(playerid, range, x, y, z);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)