Creating a stock 'IfPlayerIsInRangeOfHouse' -
Deal-or-die - 13.09.2012
Hey,
I was just asking if anyone would give me a hand creating a stock basicly finding the location of a house and checking if a player is near it on a command such as lock
For example
pawn Код:
stock IsPlayerInRangeOfHouse(playerid, Float:Range)
{
for(new x = 0; x < MAX_HOUSES; x++)
return IsPlayerInRangeOfPoint(playerid, Range, House[x][hExtPosX], House[x][hExtPosY], House[x][hExtPosZ]));
}
Sorry if the above made you facepalm but that's reason I am asking for help.
Cheers.
AW: Creating a stock 'IfPlayerIsInRangeOfHouse' -
BiosMarcel - 13.09.2012
YOu can create something like GetHousePos and ask if Player is near house posx,y,z
Re: Creating a stock 'IfPlayerIsInRangeOfHouse' -
ddnbb - 13.09.2012
pawn Код:
stock IsPlayerInRangeOfHouse(playerid, Float:Range)
{
for(new x = 0; x < MAX_HOUSES; x++)
if(IsPlayerInRangeOfPoint(playerid, Range, House[x][hExtPosX], House[x][hExtPosY], House[x][hExtPosZ])) return 1;
else return 0;
}
Re: Creating a stock 'IfPlayerIsInRangeOfHouse' -
IstuntmanI - 13.09.2012
Check if the player is in range of a specific house:
Код:
stock IsPlayerInRangeOfHouse( playerid, Float:Range, houseid )
{
if( IsPlayerInRangeOfPoint( playerid, Range, House[ houseid ][ hExtPosX ], House[ houseid ][ hExtPosY ], House[ houseid ][ hExtPosZ ] ) );
return 1;
return 0;
}
Check if the player is in range of any house:
Код:
stock IsPlayerInRangeOfAnyHouse( playerid, Float:Range )
{
for( new houseid = 0; houseid < MAX_HOUSES; houseid ++ )
if( IsPlayerInRangeOfPoint( playerid, Range, House[ houseid ][ hExtPosX ], House[ houseid ][ hExtPosY ], House[ houseid ][ hExtPosZ ] ) );
return houseid;
return 0;
}
Re: Creating a stock 'IfPlayerIsInRangeOfHouse' -
Deal-or-die - 13.09.2012
Ahh righto, thanks all for your responses, may I ask what is this and how does it work?
pawn Код:
for( new houseid = 0; houseid < MAX_HOUSES; houseid ++ )
as far as I know it's a loop or something, whether that's correct or not I have no idea.
Also Costel
This is the error I got
pawn Код:
(4600) : error 036: empty statement
Line 4600
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, Range, House[houseid][hExtPosX], House[houseid][hExtPosY], House[houseid][hExtPosZ]));
surrounding code
pawn Код:
stock IsPlayerInRangeOfAnyHouse(playerid, Float:Range)
{
for(new houseid = 0; houseid < MAX_HOUSES; houseid ++)
{
if(IsPlayerInRangeOfPoint(playerid, Range, House[houseid][hExtPosX], House[houseid][hExtPosY], House[houseid][hExtPosZ]));// <--- Line 4600
{
return houseid;
}
}
return 0;
}
Re: Creating a stock 'IfPlayerIsInRangeOfHouse' - Emmet_ - 13.09.2012
To fix your empty statement problem:
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, Range, House[houseid][hExtPosX], House[houseid][hExtPosY], House[houseid][hExtPosZ]))
Quote:
Originally Posted by Deal-or-die
Ahh righto, thanks all for your responses, may I ask what is this and how does it work?
pawn Код:
for( new houseid = 0; houseid < MAX_HOUSES; houseid ++ )
as far as I know it's a loop or something, whether that's correct or not I have no idea.
|
Correct, that is a loop.
1) It declares a variable, titled 'houseid'.
2) It will check if houseid is lower than MAX_HOUSES, and if it is, the 'houseid' variable is incremented by one each time, and the code below the following brace below the for loop '{' will be executed (it's like an if statement, but it repeats).
More info:
https://sampforum.blast.hk/showthread.php?tid=305770
Re: Creating a stock 'IfPlayerIsInRangeOfHouse' -
Deal-or-die - 13.09.2012
Quote:
Originally Posted by Emmet_
To fix your empty statement problem:
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, Range, House[houseid][hExtPosX], House[houseid][hExtPosY], House[houseid][hExtPosZ]))
|
Cheers, donno why I didn't pick up on that. :P
Quote:
Originally Posted by Emmet_
Correct, that is a loop.
1) It declares a variable, titled 'houseid'.
2) It will check if houseid is lower than MAX_HOUSES, and if it is, the 'houseid' variable is incremented by one each time, and the code below the following brace below the for loop '{' will be executed (it's like an if statement, but it repeats).
More info: https://sampforum.blast.hk/showthread.php?tid=305770
|
Ahh cheers, yea I thought I almost have the idea just couldn't quite get the gist of it :P
I'll have a quick read but I am sure if I use it a few times I'll get used to it.
Thanks all.