SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

Reply
 
Thread Tools Display Modes
Old 17/01/2018, 12:16 AM   #1251
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,144
Reputation: 345
Default Re: Useful Snippets

Aha thanks! i edited my post with that valid thing and i'll check your implementation once i get time but just a comment shouldn't this:
PHP Code:
new bool:is_occupied false
        for(new 
0MAX_PLAYERSp++) 
        { 
            if(!
IsPlayerConnected(p)) continue; //Forgot this, foreach could be even better 
            
if(IsPlayerInVehicle(pi)) 
            { 
                
is_occupied true
                break; 
//avoid any more useless loops, we know the vehicle is occupied 
            

        } 
        if(!
is_occupied//without any driver 
be like this?
PHP Code:
new bool:is_occupied[MAX_VEHICLES] = false;
        for(new 
0MAX_PLAYERSp++)
        {
            if(!
IsPlayerConnected(p)) continue; //Forgot this, foreach could be even better
            
if(IsPlayerInVehicle(pi))
            {
                
is_occupied[i] = true;
                break; 
//avoid any more useless loops, we know the vehicle is occupied
            
}
        }
        if(!
is_occupied[i]) //without any driver 
__________________
Quote:
I'm not using the forum to release stuff anymore, if you want updates for my releases or to check my new releases check the links below >
Quote:
Originally Posted by Escobar ⚠
Life sucked me in and shat me on the cruel world.

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link


RogueDrifter is offline   Reply With Quote
Old 17/01/2018, 12:24 AM   #1252
ThePhenix
Gangsta
 
ThePhenix's Avatar
 
Join Date: May 2012
Posts: 823
Reputation: 157
Default Re: Useful Snippets

Quote:
Originally Posted by RogueDrifter View Post
Aha thanks! i edited my post with that valid thing and i'll check your implementation once i get time but just a comment shouldn't this:
PHP Code:
new bool:is_occupied false
        for(new 
0MAX_PLAYERSp++) 
        { 
            if(!
IsPlayerConnected(p)) continue; //Forgot this, foreach could be even better 
            
if(IsPlayerInVehicle(pi)) 
            { 
                
is_occupied true
                break; 
//avoid any more useless loops, we know the vehicle is occupied 
            

        } 
        if(!
is_occupied//without any driver 
be like this?
PHP Code:
new bool:is_occupied[MAX_VEHICLES] = false;
        for(new 
0MAX_PLAYERSp++)
        {
            if(!
IsPlayerConnected(p)) continue; //Forgot this, foreach could be even better
            
if(IsPlayerInVehicle(pi))
            {
                
is_occupied[i] = true;
                break; 
//avoid any more useless loops, we know the vehicle is occupied
            
}
        }
        if(!
is_occupied[i]) //without any driver 
Well, it would be really pointless to use an array for this case (loop through all the unoccupied vehicles), as the variable is_occupied only serves the purpose of telling you whether the vehicle with ID: i is occupied or not and if so it's value changes to true. This line:

PHP Code:
if(!is_occupied
Simply checks whether is_occupied was not changed for vehicle ID: i

If you wanted to make an array of the unoccupied vehicles (can't find a use for that) then what you propose might be possible.
ThePhenix is offline   Reply With Quote
Old 17/01/2018, 12:27 AM   #1253
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,144
Reputation: 345
Default Re: Useful Snippets

Quote:
Originally Posted by ThePhenix View Post
Well, it would be really pointless to use an array for this case (loop through all the unoccupied vehicles), as the variable is_occupied only serves the purpose of telling you whether the vehicle with ID: i is occupied or not and if so it's value changes to true. This line:

PHP Code:
if(!is_occupied
Simply checks whether is_occupied was not changed for vehicle ID: i

If you wanted to make an array of the unoccupied vehicles (can't find a use for that) then what you propose might be possible.
Ohh now i see the use for it thanks for the clarification :)
__________________
Quote:
I'm not using the forum to release stuff anymore, if you want updates for my releases or to check my new releases check the links below >
Quote:
Originally Posted by Escobar ⚠
Life sucked me in and shat me on the cruel world.

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link


RogueDrifter is offline   Reply With Quote
Old 29/01/2018, 12:08 AM   #1254
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,144
Reputation: 345
Default Re: Useful Snippets

This function will return the slot of the weapon id you insert into it: GetWeaponSlot(weaponid)
PHP Code:
stock GetWeaponSlot(weaponid)
{
    switch(
weaponid)
    {
        case 
0..1:   return 0;
        case 
2..9:   return 1;
        case 
22..24: return 2;
        case 
25..27: return 3;
        case 
28..29: return 4;
        case 
32:     return 4;
        case 
30..31: return 5;
        case 
33..34: return 6;
        case 
35..38: return 7;
        case 
16..18: return 8;
        case 
39:     return 8;
        case 
41..43: return 9;
        case 
10..15: return 10;
        case 
44..46: return 11;
        case 
40:     return 12;
    }
    return 
0;//If invalid return 0 you can change that to whatever u want

Can be helpful if u use GetPlayerWeaponData so you won't need to look online for the weapon's slot.
__________________
Quote:
I'm not using the forum to release stuff anymore, if you want updates for my releases or to check my new releases check the links below >
Quote:
Originally Posted by Escobar ⚠
Life sucked me in and shat me on the cruel world.

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link



Last edited by RogueDrifter; 28/05/2018 at 12:40 PM.
RogueDrifter is offline   Reply With Quote
Old 10/02/2018, 09:00 AM   #1255
RxErT
Huge Clucker
 
Join Date: May 2016
Location: SA:MP Lemon
Posts: 258
Reputation: 12
Default Simple Whisper and Car Whisper commands controllable

*Features:
This system contain, 4 commands, are the following:
-/w (/whisper).
-/cw (whispering inside a car).
-/wspy (spying whisper messages).
-/cwspy (spying car whisper)


*Includes used:
-a_samp...
-Zeex command processor.
-sscanf2


Source:

Includes:

PHP Code:
//===Includes===//
#include <a_samp>
#include <zcmd>
#include <sscanf2>
//-------------// 
Variables:
PHP Code:
//===Variables===//
new wspy[MAX_PLAYERS];
new 
cwspy[MAX_PLAYERS];
new 
pmspy[MAX_PLAYERS];
new 
IsSpawned[MAX_PLAYERS];
//=================// 
some optimization under public OnPlayerConnect(playerid) callback:

PHP Code:
public OnPlayerConnect(playerid)
{
   
IsSpawned[playerid] = 0;
   
wspy[playerid] = 0;
   
cwspy[playerid] = 0;
   
pmspy[playerid] = 0;
   return 
1;

Also under public OnPlayerSpawn(playerid):

PHP Code:
public OnPlayerSpawn(playerid)
{
   
IsSpawned[playerid] = 1;
   return 
1;

/*Car Whisper Code:*/
PHP Code:
CMD:cw(playeridparams[])
{
        if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
        new 
string[250], textes[120], name[MAX_PLAYER_NAME];
        
GetPlayerName(playeridname,sizeof(name));

        if (
sscanf(params"s[250]"string))
        {
            
SendClientMessage(playerid0xf8f8f8fff"Syntax: {f48006}/cw <message>");
        }
        else
        {
            if(
IsPlayerInAnyVehicle(playerid))
            {
                new 
vehicleID GetPlayerVehicleID(playerid);

                new 
string2[250];
                
format(string2sizeof(string2), "{adf407}[Car Whisper] {FFFFFF}%s(%i): {adf407}%s",nameplayeridstring);

                for(new 
0<= MAX_PLAYERSi++)
                {
                    if(
IsPlayerInVehicle(ivehicleID))
                    {
                        
SendClientMessage(i, -1string2);
                    }
                }
            }
            else
            {
                
SendClientMessage(playerid,0xf8f8f8fff"ERROR: {F00f00}You are not in a vehicle.");
            }
            for(new 
0<= MAX_PLAYERSi++)
            {
                if(
IsPlayerConnected(i))
                {
                    if(
IsPlayerInAnyVehicle(playerid))
                    {
                        if (
IsPlayerAdmin(i))
                        {
                            if (
cwspy[i])
                            {
                                new 
cwtext[200];
                                
format(cwtextsizeof(cwtext), "{f00f00}[Car Whisper SPY]>> %s: %s",namestringtextes);
                                
SendClientMessage(i, -1cwtext);
                            }
                          }
                      }
                }
            }
        }
        return 
1;

/*Note: you can replaceIsPlayerAdmin(playerid) with your own administrator's system variable.*/

/* Car Whisper Spying */

PHP Code:
CMD:cwspy(playeridparams[])
{
    if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
    if(
IsPlayerConnected(playerid))
    {
        if(
IsPlayerAdmin(playerid))
        {
            if (
cwspy[playerid])
            {
                
cwspy[playerid] = false;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {f41f07}You are not spying on car whisper.");
            }
            else
            {
                
cwspy[playerid] = true;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {adf407}You are now spying on car whisper.");
            }
        }
    }
    return 
1;

/* Whisper */

PHP Code:
CMD:w(playeridparams[])
{
        new 
string[250];
        new 
nameplaya[MAX_PLAYER_NAME];
        new 
textes2[120];
        
GetPlayerName(playeridnameplaya,sizeof(nameplaya));
        if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
        if (
sscanf(params"s[250]"string))
        {
            
SendClientMessage(playerid0xf8f8f8fff"Syntax: {f48006}/(w)hisper <message>");
        }
        else
        {
            new 
Float:x,Float:y,Float:z;
            
GetPlayerPos(playerid,x,y,z);

            new 
string2[250];
            
format(string2sizeof(string2), "{f47e07}[WHISPER] {FFFFFF}%s(%i): {f47e07}%s",nameplayaplayeridstring);

            for(new 
0<= MAX_PLAYERSi++)
            {
                if(
IsPlayerInRangeOfPoint(i15.0xyz))
                {
                    
SendClientMessage(i, -1string2);
                    
PlayerPlaySound(i1085,0.0,0.0,0.0);
                }
                 if(
IsPlayerConnected(i))
                {
                    if(
IsPlayerAdmin(i))
                    {
                         if (
wspy[i])
                        {
                        new 
wtext[200];
                        
format(wtextsizeof(wtext), "{f904e9}[WHISPER SPY]> {FFFFFF}%s: %s",nameplayastringtextes2);
                        
SendClientMessage(i, -1wtext);
                        }
                    }
                }
            }
        }
        return 
1;

/* Whisper spy */

PHP Code:
COMMAND:wspy(playeridparams[])
{
    if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
    if(
IsPlayerConnected(playerid))
    {
        if(
IsPlayerAdmin(playerid))
        {
            if (
wspy[playerid])
            {
                
wspy[playerid] = false;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {f41f07}You are no longer spying on WHISPERS.");
            }
            else
            {
                
wspy[playerid] = true;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {a1f406}You are now spying on WHISPERS.");
            }
        }
    }
    return 
1;

*Whole source code:
PHP Code:
//Whisper, Car Whsiper simple systems, with some administration control.
//Made by RxErT

//===Includes===//
#include <a_samp>
#include <zcmd>
#include <sscanf2>
//-------------//

//===Variables===//
new wspy[MAX_PLAYERS];
new 
cwspy[MAX_PLAYERS];
new 
pmspy[MAX_PLAYERS];
new 
IsSpawned[MAX_PLAYERS];
//=================//

public OnPlayerConnect(playerid)
{
   
IsSpawned[playerid] = 0;
   
wspy[playerid] = 0;
   
cwspy[playerid] = 0;
   
pmspy[playerid] = 0;
   return 
1;
}

public 
OnPlayerSpawn(playerid)
{
   
IsSpawned[playerid] = 1;
   return 
1;
}

/*Car Whisper*/
CMD:cw(playeridparams[])
{
        if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
        new 
string[250], textes[120], name[MAX_PLAYER_NAME];
        
GetPlayerName(playeridname,sizeof(name));

        if (
sscanf(params"s[250]"string))
        {
            
SendClientMessage(playerid0xf8f8f8fff"Syntax: {f48006}/cw <message>");
        }
        else
        {
            if(
IsPlayerInAnyVehicle(playerid))
            {
                new 
vehicleID GetPlayerVehicleID(playerid);

                new 
string2[250];
                
format(string2sizeof(string2), "{adf407}[Car Whisper] {FFFFFF}%s(%i): {adf407}%s",nameplayeridstring);

                for(new 
0<= MAX_PLAYERSi++)
                {
                    if(
IsPlayerInVehicle(ivehicleID))
                    {
                        
SendClientMessage(i, -1string2);
                    }
                }
            }
            else
            {
                
SendClientMessage(playerid,0xf8f8f8fff"ERROR: {F00f00}You are not in a vehicle.");
            }
            for(new 
0<= MAX_PLAYERSi++)
            {
                if(
IsPlayerConnected(i))
                {
                    if(
IsPlayerInAnyVehicle(playerid))
                    {
                        if (
IsPlayerAdmin(i))
                        {
                            if (
cwspy[i])
                            {
                                new 
cwtext[200];
                                
format(cwtextsizeof(cwtext), "{f00f00}[Car Whisper SPY]>> %s: %s",namestringtextes);
                                
SendClientMessage(i, -1cwtext);
                            }
                          }
                      }
                }
            }
        }
        return 
1;
}
/* Car Whisper Spying */
CMD:cwspy(playeridparams[])
{
    if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
    if(
IsPlayerConnected(playerid))
    {
        if(
IsPlayerAdmin(playerid))
        {
            if (
cwspy[playerid])
            {
                
cwspy[playerid] = false;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {f41f07}You are not spying on car whisper.");
            }
            else
            {
                
cwspy[playerid] = true;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {adf407}You are now spying on car whisper.");
            }
        }
    }
    return 
1;
}
/*Done*/




/* Whisper */
CMD:w(playeridparams[])
{
        new 
string[250];
        new 
nameplaya[MAX_PLAYER_NAME];
        new 
textes2[120];
        
GetPlayerName(playeridnameplaya,sizeof(nameplaya));
        if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
        if (
sscanf(params"s[250]"string))
        {
            
SendClientMessage(playerid0xf8f8f8fff"Syntax: {f48006}/(w)hisper <message>");
        }
        else
        {
            new 
Float:x,Float:y,Float:z;
            
GetPlayerPos(playerid,x,y,z);

            new 
string2[250];
            
format(string2sizeof(string2), "{f47e07}[WHISPER] {FFFFFF}%s(%i): {f47e07}%s",nameplayaplayeridstring);

            for(new 
0<= MAX_PLAYERSi++)
            {
                if(
IsPlayerInRangeOfPoint(i15.0xyz))
                {
                    
SendClientMessage(i, -1string2);
                    
PlayerPlaySound(i1085,0.0,0.0,0.0);
                }
                 if(
IsPlayerConnected(i))
                {
                    if(
IsPlayerAdmin(i))
                    {
                         if (
wspy[i])
                        {
                        new 
wtext[200];
                        
format(wtextsizeof(wtext), "{f904e9}[WHISPER SPY]> {FFFFFF}%s: %s",nameplayastringtextes2);
                        
SendClientMessage(i, -1wtext);
                        }
                    }
                }
            }
        }
        return 
1;
}

/* Whisper spy */
COMMAND:wspy(playeridparams[])
{
    if(
IsSpawned[playerid] == 0) return SendClientMessage(playerid,0xf8f8f8fff,"ERROR: {f00f00}You should be spawned first!");
    if(
IsPlayerConnected(playerid))
    {
        if(
IsPlayerAdmin(playerid))
        {
            if (
wspy[playerid])
            {
                
wspy[playerid] = false;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {f41f07}You are no longer spying on WHISPERS.");
            }
            else
            {
                
wspy[playerid] = true;
                
SendClientMessage(playerid0xf8f8f8fff"[SERVER] {a1f406}You are now spying on WHISPERS.");
            }
        }
    }
    return 
1;
}
/* Done */ 
If you find anything strange feel free to remind me!
RxErT is offline   Reply With Quote
Old 28/02/2018, 12:55 PM   #1256
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,144
Reputation: 345
Default Re: Useful Snippets

This function will return true if the player is UNDER water and false if he isn't,
PHP Code:
stock IsPlayerUnderWater(playerid)
{
    new 
PPAnim GetPlayerAnimationIndex(playerid);
    return (
PPAnim == 1540 || PPAnim == 1544);

Very simple and basic but yeah didn't see it anywhere.
__________________
Quote:
I'm not using the forum to release stuff anymore, if you want updates for my releases or to check my new releases check the links below >
Quote:
Originally Posted by Escobar ⚠
Life sucked me in and shat me on the cruel world.

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link



Last edited by RogueDrifter; 09/04/2018 at 10:23 PM.
RogueDrifter is offline   Reply With Quote
Old 07/03/2018, 09:07 PM   #1257
RogerCosta
Huge Clucker
 
RogerCosta's Avatar
 
Join Date: Aug 2014
Location: Santos, Brazil.
Posts: 316
Reputation: 91
Default Re: Useful Snippets

Extra functions created by me for extract value from one key in Y_INI:

Code:
// Global variables
enum {
    INT,
    FLOAT,
    STRING
}

new key_name[50], 
    key_type, 
    key_value_int, 
    Float:key_value_float, 
    key_value_str[128];

stock INI_GetInt(filename[], key[], &variable) {
    INI_ParseFile(filename, "LoadOnlyKey", .bExtra = true, .bLocal = true); 
    format(key_name, sizeof key_name, "%s", key);
    key_type = INT;
    variable = key_value_int;
}

stock INI_GetFloat(filename[], key[], &Float:variable) {
    INI_ParseFile(filename, "LoadOnlyKey", .bExtra = true, .bLocal = true); 
    format(key_name, sizeof key_name, "%s", key);
    key_type = FLOAT;
    variable = key_value_float;
}

stock INI_GetString(filename[], key[], variable[]) {
    INI_ParseFile(filename, "LoadOnlyKey", .bExtra = true, .bLocal = true); 
    format(key_name, sizeof key_name, "%s", key);
    key_type = STRING;
    format(variable, sizeof variable, "%s", key_value_float);
}

forward LoadOnlyKey(name[], value[]) {}
public LoadOnlyKey(name[], value[]) {
    switch(key_type) {
        case STRING:    INI_String(key_name, key_value_str, sizeof key_value_str);
        case FLOAT:     INI_Float(key_name, key_value_float);
        case INT:       INI_Int(key_name, key_value_int);
    }
    return true;
}

Last edited by RogerCosta; 10/03/2018 at 03:20 AM.
RogerCosta is offline   Reply With Quote
Old 11/03/2018, 05:48 PM   #1258
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 280
Reputation: 72
Default Re: Useful Snippets

GetVehicleSpeed:

PHP Code:
GetVehicleSpeed(vehicleidtype)
{
    new 
s;
    new 
Float:xFloat:yFloat:z;
    
GetVehicleVelocity(vehicleidxyz);
    switch(
type)
    {
        case 
1floatround((floatsqroot(floatpower(x2) + floatpower(y2) + floatpower(z2)))*112.1577floatround_round);
        default: 
floatround((floatsqroot(floatpower(x2) + floatpower(y2) + floatpower(z2)))*180.5000floatround_round);
    }
    return 
s;

Types:

Code:
type 1 - mph
any other type - kmh
Example:

PHP Code:
public sometcallaback(playerid)
{
    new 
str[3];
    
format(strsizeof(str), "%d"GetVehicleSpeed(GetPlayerVehicleID(playerid), 0));
    
GameTextForPlayer(playeridstr1004);
    return 
1;

Lokii is offline   Reply With Quote
Old 13/03/2018, 03:17 PM   #1259
RogerCosta
Huge Clucker
 
RogerCosta's Avatar
 
Join Date: Aug 2014
Location: Santos, Brazil.
Posts: 316
Reputation: 91
Default Re: Useful Snippets

Code:
stock RemovePlayerWeapon(playerid, weaponid) {
	if(GetPlayerWeapon(playerid) == weaponid) {
		GivePlayerWeapon(playerid, weaponid, -GetPlayerAmmo(playerid));
	}
	else {
		new slot, weapon, ammo, currentWeapon = GetPlayerWeapon(playerid);
		for(new i = 0; i < 12; i++) {
			GetPlayerWeaponData(playerid, i, weapon, ammo);
			if(weapon == weaponid && ammo > 0) {
				GivePlayerWeapon(playerid, weaponid, -ammo);
				SetPlayerArmedWeapon(playerid, currentWeapon);
				break;
			}
		}
	}
}
RogerCosta is offline   Reply With Quote
Old 13/03/2018, 03:51 PM   #1260
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,806
Reputation: 831
Default Re: Useful Snippets

^^That won't work for melee weapons.
__________________

My GitHub:

Gammix is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
READ Usefull Links to snippets and other -Sneaky- Help Archive 5 02/05/2009 11:22 AM


All times are GMT. The time now is 11:21 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.