Question about a stock and a command, +Rep! -
K9IsGodly - 14.01.2014
So basically, I made a /spawnboat command where it opens a dialog. However, I wanted a way to check if the player is in water. Well I got help with this the other day, and someone gave me this stock:
Код:
static stock IsPlayerInWater( playerid ) //Credits to Synchro for his coords function.
{
static
Float:fX,
Float:fY,
Float:fZ
;
GetPlayerPos( playerid, fX, fY, fZ );
if((fX >= 2044.6 && fX <= 2192.984 && fY >= 1206.358 && fY <= 1376.552) && fZ < 0xA) return true;
else if((fX >= 2048.504 && fX <= 2185.174 && fY >= 1063.239 && fY <= 1202.49) && fZ < 0xA) return true;
else if((fX >= 2204.698 && fX <= 2204.698 && fY >= 1426.837 && fY <= 1430.705) && fZ < 0xA) return true;
else if((fX >= 2032.885 && fX <= 2114.887 && fY >= 1852.325 && fY <= 1991.575) && fZ < 0xC) return true;
else if((fX >= 2517.086 && fX <= 2606.897 && fY >= 2316.493 && fY <= 2420.93) && fZ < 0x16) return true;
else if((fX >= 2554.5996 && fX <= 2507.7683 && fY >= 1548.6178 && fY <= 1588.9154) && fZ < 0xF) return true;
else if((fX >= -2043.628 && fX <= -1973.561 && fY >= -980.9415 && fY <= -724.0283) && fZ < 0x20) return true;
else if((fX >= -2753.912 && fX <= -2665.071 && fY >= -522.3632 && fY <= -380.3444) && fZ < 0x05) return true;
else if((fX >= 1219.864 && fX <= 1292.118 && fY >= -2435.881 && fY <= -2325.344) && fZ < 0xF) return true;
else if((fX >= 1923.388 && fX <= 2010.854 && fY >= -1223.924 && fY <= -1168.656) && fZ < 0x16) return true;
else if((fX >= 1269.301 && fX <= 1314.935 && fY >= -837.0452 && fY <= -781.7769) && fZ < 0x5A) return true;
else if((fX >= 1087.3953 && fX <= 1102.3138 && fY >= -682.6734 && fY <= -663.0043) && fZ < 0x71) return true;
else if((fX >= 1268.6118 && fX <= 1291.8774 && fY >= -784.2910 && fY <= -764.6104) && fZ < 0x43D) return true;
else if(fZ < 0xF) return true;
else return false;
}
I am not knowledgeable with stocks in anyway, and I would like to learn more about them (if someone has a link to where I could learn about them, or you could take the time to explain it to me). Back to the point, when I do my /spawnboat command, it just shows me the menu, even though I'm on land. My question is, why is this happening? Here's my command. I'd just like some help if anyone can help me.
Код:
CMD:spawnboat(playerid, params[])
{
new currentvehicle;
currentvehicle = GetPlayerVehicleID(playerid);
if(IsPlayerInWater( playerid ))
{
}
else
{
SendClientMessage(playerid, COLOR_RED, "You're not in water, therefore a boat will not be spawned!");
}
if(IsPlayerInAnyVehicle(playerid))
{
DestroyVehicle(currentvehicle);
ShowPlayerDialog(playerid,19,DIALOG_STYLE_LIST,""COL_BLUE"Boats:",""COL_ORANGE"Test\n","Select","Cancel");
}
else
{
ShowPlayerDialog(playerid,19,DIALOG_STYLE_LIST,""COL_BLUE"Boats:",""COL_ORANGE"Test\n","Select","Cancel");
}
return 1;
}
Respuesta: Question about a stock and a command, +Rep! -
Swedky - 14.01.2014
pawn Код:
stock IsPlayerInWeater(playerid)
{
new Float:Pos[3];
GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
if((GetPlayerAnimationIndex(playerid) >= 1538) && (GetPlayerAnimationIndex(playerid) <= 1542))
{
if(Pos[2] <= 1.0) return 1;
if(Pos[2] <= 42.0)
{
if(Pos[0] > -1392.504150 && Pos[0] < 2012.089965 && Pos[1] > -482.504150 && Pos[1] < 2813.089843)
return 1;
}
}
return 0;
}
It is more exact. It extracts the animation of 'swimming', and also it works in the high presses (high places with water).
Re: Question about a stock and a command, +Rep! - Emmet_ - 14.01.2014
A stock function is simply a regular function, like this:
However, the "stock" keyword suppresses the "symbol is never used" warning when a function isn't used, as opposed to doing "#pragma unused".
---
Cut to the chase, you're using the "if" statement incorrectly, so maybe try this:
pawn Код:
CMD:spawnboat(playerid, params[])
{
if (!IsPlayerInWater(playerid))
return SendClientMessage(playerid, COLOR_RED, "You're not in water, therefore a boat will not be spawned!");
if (IsPlayerInAnyVehicle(playerid)) {
DestroyVehicle(GetPlayerVehicleID(playerid));
}
ShowPlayerDialog(playerid, 19, DIALOG_STYLE_LIST, ""COL_BLUE"Boats:", ""COL_ORANGE"Test\n", "Select", "Cancel");
return 1;
}
Re: Question about a stock and a command, +Rep! -
K9IsGodly - 14.01.2014
I'm not sure which of your replies is better in my situation, but I appreciate both responses. I repped you guys. Thanks again!
Edit: For some reason it's not letting me rep you right now Emmet.
Re: Question about a stock and a command, +Rep! -
newbie scripter - 14.01.2014
IMO stock is like a short form, i mean u can supress a code into a line or make a safe function and preventing hack.
for Example
pawn Код:
stock SendClientMessageToAllEx(exception, color, const message[])
{
for(new i; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(i != exception)
{
SendClientMessage(i, color, message);
}
}
}
}
u can use the above code to send a message to players other than the one u mentioned. Instead of typing
pawn Код:
for(new i; i<MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
if(i !=playerid)
{
SendClientMessage(i, -1, "~");
}
}
}
u can type
SendClientMessageToAllEx(playerid, -1, "~");