28.01.2011, 14:43
Useful Functions
29.01.2011, 02:40
29.01.2011, 12:57
pawn Код:
stock Teleport( playerid, Float: X, Float: Y, Float: Z, time ) SetTimerEx( "TeleportPlayer", time, false, "dfff", playerid, X, Y, Z );
forward TeleportPlayer( playerid, Float: X, Float: Y, Float: Z );
public TeleportPlayer( playerid, Float: X, Float: Y, Float: Z )
{
if( !IsPlayerInAnyVehicle( playerid ) ) SetPlayerPos( playerid, X, Y, Z );
else SetVehiclePos( GetPlayerVehicleID( playerid ), X, Y, Z );
return true;
}
Teleport( playerid, 0.0, 0.0, 0.0, 1000 );
Will set player coordinates to 0.0 in 1sec
03.02.2011, 15:02
ALLOW MINIGUN FOR PLAYER
Код:
new MinigunCheckTimer; stock AllowMinigunForPlayer(playerid, allow) { if(allow) return 1; MinigunCheckTimer = SetTimerEx("MinigunCheck",2000,1,"i",playerid); return 1; } public MinigunCheck(playerid) { if(GetPlayerWeapon(playerid) != 38) return 1; BanEx(playerid,"Minigun Cheat"); return 1; } public OnPlayerDeath(playerid, killerid, reason) { KillTimer(MinigunCheckTimer); return 1; }
03.02.2011, 15:57
That will ban innocent players. Also thats a snippet, not a fucntion.
Edit; Actually, it wont even work with more then 1 player
Edit; Actually, it wont even work with more then 1 player
03.02.2011, 20:43
Quote:
ALLOW MINIGUN FOR PLAYER
Код:
new MinigunCheckTimer; stock AllowMinigunForPlayer(playerid, allow) { if(allow) return 1; MinigunCheckTimer = SetTimerEx("MinigunCheck",2000,1,"i",playerid); return 1; } public MinigunCheck(playerid) { if(GetPlayerWeapon(playerid) != 38) return 1; BanEx(playerid,"Minigun Cheat"); return 1; } public OnPlayerDeath(playerid, killerid, reason) { KillTimer(MinigunCheckTimer); return 1; } |
04.02.2011, 11:37
what's not working in m script?
04.02.2011, 13:38
Alternative version of "IsNumeric"
How does it work:
It loops through the whole 'string' length. If string length 'i' (per character) is numeric, it increases 'check' with 1.
If 'check' is the same as the string length, it will return true.
It's easy :P
pawn Код:
stock IsNumeric(string[])
{
for(new i = 0, length = strlen(string), check; i < length; i++){
switch(string[i]){
case '0' .. '9': check ++;
}
if(check == length) return true;
}
return false;
}
It loops through the whole 'string' length. If string length 'i' (per character) is numeric, it increases 'check' with 1.
If 'check' is the same as the string length, it will return true.
It's easy :P
04.02.2011, 13:48
-1 is not numeric!
Also, why would you keep looping if you find an invalid number?
Proper version would be (I stole this from myself):
Also, why would you keep looping if you find an invalid number?
Proper version would be (I stole this from myself):
pawn Код:
stock bool:IsValidNumber( const szString[ ] )
{
if ( !szString[ 0 ] )
return false;
new
iLength = strlen( szString ),
i
;
if ( szString[ 0 ] == '-' && szString[ 1 ] )
i = 1;
for ( ; i < iLength; i++ )
{
if ( !( '0' <= szString[ i ] <= '9' ) )
return false;
}
return true;
}
04.02.2011, 14:04
Another version
I know that +-.+ would be valid
But I think that + should be included or . for floats
pawn Код:
stock bool:IsNumeric(const string[])
{
if(string[0] != EOS) {
for(new i = -1; ; ) {
switch(string[++i]) {
case '+', '-', '.', '0'..'9': continue;
case EOS: return true;
default: return false;
}
}
}
return false;
}
But I think that + should be included or . for floats
04.02.2011, 14:29
@Nero_3D: You forgot to make sure the +/- signs are in the beginning, and there can be several dots.
@******: Something equivalent to the JavaScript parseInt function would be cool (since strval isn't capable of dealing with any of the numbers you wrote).
@******: Something equivalent to the JavaScript parseInt function would be cool (since strval isn't capable of dealing with any of the numbers you wrote).
04.02.2011, 16:41
pawn Код:
stock IsValidNumber( const szString[ ] )
{
new i;
if ( szString[0] == '-') i = 1;
while (szString[++i]) if(!('0' <= szString[++i] <= '9')) return false;
return true;
}
05.02.2011, 07:56
@[FeK]DraKiNs: It skips the first character, doesn't check for null, and it's slower.
I don't see why you'd change a fully working function!
"If it ain't broke, don't fix it."
I don't see why you'd change a fully working function!
"If it ain't broke, don't fix it."
05.02.2011, 08:36
05.02.2011, 09:01
Just curious, what's the meaning of the 'sz' in front of ur (string) variable?
05.02.2011, 09:09
Ryder: that is a prefix for zero-terminated string
05.02.2011, 09:10
I get it, thanks
05.02.2011, 16:37
Quote:
That will ban innocent players. Also thats a snippet, not a fucntion. Edit; Actually, it wont even work with more then 1 player |
Sorry for my english...
05.02.2011, 16:50
You're using a global variable for the timer and not a global player variable, hence why it would only work for the last player you started the timer on (the killtimer part, etc.).
06.02.2011, 12:15
pawn Код:
stock PutPlayerInVehicleEx(playerid, vehicleid, seatid)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
CallRemoteFunction("OnPlayerStateChange", "iii", playerid, PLAYER_STATE_ONFOOT, PLAYER_STATE_DRIVER);
PutPlayerInVehicle(playerid, vehicleid, seatid);
CallRemoteFunction("OnPlayerStateChange", "iii", playerid, PLAYER_STATE_DRIVER, PLAYER_STATE_ONFOOT);
return 1;
}
else if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
{
CallRemoteFunction("OnPlayerStateChange", "iii", playerid, PLAYER_STATE_ONFOOT, PLAYER_STATE_PASSENGER);
PutPlayerInVehicle(playerid, vehicleid, seatid);
CallRemoteFunction("OnPlayerStateChange", "iii", playerid, PLAYER_STATE_PASSENGER, PLAYER_STATE_ONFOOT);
return 1;
}
else return PutPlayerInVehicle(playerid, vehicleid, seatid);
}
(Won't work, if PutPlayerInVehicle will be called in another method)
« Next Oldest | Next Newest »
Users browsing this thread: 12 Guest(s)