Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums



(Advanced Search)

Forum Statistics
» Members: 7,716
» Latest member: dinarzinou
» Forum threads: 2,360
» Forum posts: 12,308

Full Statistics

Online Users
There are currently 247 online users.
» 1 Member(s) | 244 Guest(s)
Bing, Google, JakeFalcone

Latest Threads
Vice WRLD Freeroam/RP
Forum: Advertisements
Last Post: pdjumailiev
3 hours ago
» Replies: 0
» Views: 27
Wanting to Start a RP Ser...
Forum: Chat
Last Post: Wein
5 hours ago
» Replies: 1
» Views: 165
Help me for creating a fr...
Forum: General Discussions
Last Post: [Rs]VeNoM
Yesterday, 07:33 AM
» Replies: 0
» Views: 19
The server didn't respond...
Forum: Support
Last Post: richboY
2025-11-22, 10:51 AM
» Replies: 0
» Views: 29
error when joining server
Forum: Support
Last Post: sanved2008
2025-11-22, 09:02 AM
» Replies: 0
» Views: 26
Client issue with object
Forum: Support
Last Post: TheDoctor
2025-11-15, 08:00 PM
» Replies: 0
» Views: 87
San Andreas Police Pursui...
Forum: Advertisements
Last Post: BriBri
2025-11-15, 12:06 AM
» Replies: 0
» Views: 110
[Include] OpenGate (Abrir...
Forum: Portuguese/Portugu?s
Last Post: Crazy_ArKzX
2025-11-13, 06:49 PM
» Replies: 0
» Views: 85
OpenGate (Open Proximity ...
Forum: Libraries
Last Post: Crazy_ArKzX
2025-11-13, 06:46 PM
» Replies: 0
» Views: 107
LS City Hall
Forum: Maps
Last Post: cosminupgaming
2025-11-12, 04:22 PM
» Replies: 3
» Views: 2,734

 
  Weapon Saving MySQL
Posted by: XoMoX - 2020-10-02, 10:44 AM - Forum: Tutorials - Replies (2)

Originated From Vince

Weapon Information



There are 13 different weapon slots and thus a player can theoretically hold up to 13 different weapons. In practice, though, this is usually more like 4 or 5.



[Image: 7Y1My.png]



This structure allows for a more compact view and allows for the use of aggregate functions such as COUNT(). This allows me to find out how many weapons each player has, how many players have an M4 or even the total amount of ammo currently circulating (for a specific weapon). This may all seem trivial but it is difficult, if not impossible, to achieve with your average non-normalized "weapon1, ammo1 ... weapon13, ammo13" approach.




From the above screenshot we can deduct that the player 1 has 3 weapons: a nite stick (id 3) with 1 ammo, a desert eagle (id 24) with 21 ammo and an M4 (id 31) with 266 ammo.



Creating The Table

userid is a reference to the player's unique ID which is stored in another table, along with their name, password, etc. Notice that phpMyAdmin conveniently makes the userid clickable if a foreign key exists. weaponid is simply the weaponid as is returned from functions like GetPlayerWeapon and GetPlayerWeaponData. ammo holds the ammunition associated with aforementioned weaponid.



[Image: 4m11mSS.png]



The options you need to edit are marked in yellow. Note that the type and attributes of the userid may differ in your case: this field needs to be declared with the exact same definition as your main userid. This may mean that you do not need to set that field to unsigned. The userid does need to be declared as an index though. It is neither a primary key, nor an unique key. For the weaponid we choose an unsigned tinyint since we're only dealing with non-negative numbers up to 46. The ammo is declared unsigned as well since there's no such thing as negative ammunition. Lastly, don't forget to set the engine to InnoDB. Click Save to create the table.



Setting Limits

You should've been brought to the structures tab of the table you just created. Navigate there if this isn't the case.

Before continuing, we will first impose some extra limits to avoid cluttering the table with useless data later on. Each player (userid) can only hold exactly one specific weapon (weaponid) at once. This is a PRIMARY?property (Everytable needs to have a PRIMARY key). Therefore, tick the checkboxes in front of userid and weaponid. Then click on the UNIQUE button underneath the table.



[Image: lROnnYA.png]



Creating the foreign key



You should've been brought back to the structures tab. Navigate there if this isn't the case. Underneath the structure definition you should see a link titled Relation view. Click this to be brought to the "relation creator".



[Image: 76QZOqP.png]



I'm creating a link to the id field in the table playerinfo in the database vcnr. Your table and database will be called differently. Select the proper ID. Note that for fields to show up in this list, they need to be defined as a key! We also want any changes made in the main table to be CASCADED into this table. Click Save. This concludes the table creation part in phpMyAdmin. Now back to Pawn.



Saving



For this table, we will only use SELECT, INSERT and DELETE queries. There will be no real UPDATE queries. Instead, we will only use a special insert query:



Code:
INSERT INTO ... ON DUPLICATE KEY UPDATE ...




This query will try to insert the data as normal. If this fails because the data already exists (duplicate key) it will instead perform an update. In our context this means that we will merely update the ammo if a weaponid is already present for a specific user.



Code:
[/color]

new

? ? weaponid,

? ? ammo;

? ?

for(new i; i < 13; i) // looping through all weapon slots (0 - 12)

{

? ? GetPlayerWeaponData(playerid, i, weaponid, ammo); // get weaponid and ammo



? ? if(!weaponid) continue; // don't insert if there's no weapon in this slot

? ?

? ? mysql_format(userDB, mysqlquery, sizeof(mysqlquery), "INSERT INTO player_weapons VALUES (%d, %d, %d) ON DUPLICATE KEY UPDATE ammo = %d;", PlayerInfo[playerid][pSQLID], weaponid, ammo, ammo);

? ? mysql_pquery(userDB, mysqlquery); // parallel queries

}



[color=#000000]}




The above snippet will insert or update all the weapons the player currently has. I am using parallel queries for speed: the order in which the inserts are performed isn't at all important. You will need to substitute the userid variable with your own. The same query can also be used stand-alone in other places. You can, for example, write a hook for GivePlayerWeapon which immediately performs an insert as soon as the weapon is given.



Loading



Now to retrieve this data and give the players their weapons back. Our standard select query;



Code:
SELECT weaponid, ammo FROM player_weapons WHERE userid = %d;



Code:
public OnLoadPlayerWeapons(playerid)

{

? ?

new

? ? ? ? rows,

? ? ? ? weaponid,

? ? ? ? ammo;

? ? cache_get_row_count(rows);

? ? for(new i; i < rows; i) // loop through all the rows that were found

? ? {

? ? ? ? cache_get_value_name_int(i, "weaponid", weaponid);

? ? ? ? cache_get_value_name_int(i, "ammo", ammo;

? ? ? ? if(!(0 <= weaponid <= 46)) // check if weapon is valid (should be)

? ? ? ? {

? ? ? ? ? ? printf("[info] Warning: OnLoadPlayerWeapons - Unknown weaponid '%d'. Skipping.", weaponid);

? ? ? ? ? ? continue;

? ? ? ? }

? ? ? ?

? ? ? ? GivePlayerWeapon(playerid, weaponid, ammo);

? ? }

? ? return;



}



Purging obsolete data



Whenever a weapon is taken away, do not forget to delete it from the database otherwise it will be returned to the player when they next join. You could write a hook for ResetPlayerWeapons. It may also be possible that weapons that have no ammo are left behind in the table. This doesn't affect anything in-game and can be cleaned up with a query (delete where ammo = 0) when the server starts, or on a cron job.


  Similar hexes
Posted by: Kwarde - 2020-10-02, 09:08 AM - Forum: Libraries - No Replies

This is more of a snippet than a library. However, it holds these functions (they all depend on each other):

has_alpha(color)
Checks if HEX (read: integer) input is RRGGBBAA. Does not work properly for other formats (except RRGGBB).
For example, AARRGG would return 0/false.

PHP Code:
if (has_alpha(0xFF0990AA))
{
??? print(
"I am alpha!");
}
else
{
??? print(
"I am merely a beta");
}
//Would print: I am alpha! 

strip_alpha(color)
Strips alpha from HEX if it has any (relies on has_alpha()). Like with has_alpha, inputting AARRGGBB would output AARRGG.
PHP Code:
new const colors[] = {
    
0xAFAFAF,
    
0x124356FF,
    
0xFF0990AA,
    
0x000001
};
for (new 
isizeof(colors); i)
{
    
printf("%x"strip_alpha(colors[i]));
}
/* Would output:
AFAFAF
124356
FF0990
1 //! No bits to shift and check for R and G in 0x000001. 

similar_hexes(hex_a, hex_b, difference = 150)
This checks if two hexes are alike color-wise.
Difference parameter can be used to increase or decrease the difference check in both colors.
Some colors might return false while they are pretty similar and some might return true while they aren't quite similar. Most of the tests I did turned out pretty okay, though.

PHP Code:
#define COLOR_RED 0xFF0000FF
if (similar_hexes(GetPlayerColor(playerid), COLOR_RED))
{
    print(
"Why are you so red?"); //Note that 0x880000FF (darkred) would return false


The functions:
PHP Code:
bool:has_alpha(color)
    return (
color >> 24 0x000000FF) ? true false;

strip_alpha(color)
    return (
has_alpha(color) ? ((((color >>> 24) & 0xFF) << 16) | (((color >>> 16) & 0xFF) << 8) | (((color >>> 8) & 0xFF))) : color);
    
similar_hexes(hex_ahex_bdifference 152)
{
    
hex_a strip_alpha(hex_a);
    
hex_b strip_alpha(hex_b);
    
    new 
R[2], G[2], B[2], diff[3];
    
R[0] = (hex_a >>> 16) & 0xFF;
    
G[0] = (hex_a >>> 8) & 0xFF;
    
B[0] = (hex_a) & 0xFF;
    
R[1] = (hex_b >>> 16) & 0xFF;
    
G[1] = (hex_b >>> 8) & 0xFF;
    
B[1] = (hex_b) & 0xFF;

    
diff[0] = floatround(difference 0.14);
    
diff[1] = floatround(difference 0.2);
    
diff[2] = floatround(difference 0.48);

    return
    (
        (
R[0] - diff[0] <= R[1] && R[1] <= R[0]  diff[0]) &&
        (
G[0] - diff[1] <= G[1] && G[1] <= G[0]  diff[1]) &&
        (
B[0] - diff[2] <= B[1] && B[1] <= B[0]  diff[2])
    );


Question TXD File
Posted by: GeorgeXCarl - 2020-10-01, 02:00 AM - Forum: Pawn Scripting - Replies (4)

Please help how can you can put the txd file in your server and can you give me the script how do i write it on my gamemode ? thanks... i'll rep you if helped


  Optimizing Looping All Streamer Objects
Posted by: JaKe Elite - 2020-09-30, 10:12 PM - Forum: Pawn Scripting - Replies (3)

Hi!?

It's my first time posting here but I would like to know is there any possibilities that I can optimize this code? It causes a huge lag spike in the server when used in a live server. It occurs when this loop is called when removing a furniture/land object or removing the entire furniture/land object.?(This also happens when the script has to reload the furniture/land object)

The lag can also be noticed?when deleting a house (which removes all the furniture in the process)

Things to know; My server has 16,000 objects so it is no surprise that the loop will check each single objects in the server.

I will be showing the functions (codes) that calls the loop:

PHP Code:
RemoveFurniture(objectid)
{
? ? if(
IsValidDynamicObject(objectid) && Streamer_GetExtraInt(objectidE_OBJECT_TYPE) == E_OBJECT_FURNITURE)
{
new
? ? ? ? 
id Streamer_GetExtraInt(objectidE_OBJECT_INDEX_ID);

? ? 
DeleteFurnitureObject(objectid);

? ? 
mysql_format(mysql_connectionqueryBuffersizeof(queryBuffer), "DELETE FROM furniture WHERE id = %i"id);
? ? 
mysql_tquery(mysql_connectionqueryBuffer);
}
}

DeleteFurnitureObject(objectid)
{
if(
IsValidDynamicObject(objectid) && Streamer_GetExtraInt(objectidE_OBJECT_TYPE) == E_OBJECT_FURNITURE)
{
? ? new 
Text3D:textid Text3D:Streamer_GetExtraInt(objectidE_OBJECT_3DTEXT_ID);

? ? ? ? if(
IsValidDynamic3DTextLabel(textid))
? ? ? ? {
? ? ? ? ? ? 
DestroyDynamic3DTextLabel(textid);
? ? ? ? }

? ? ? ? 
DestroyDynamicObject(objectid);
}
}

RemoveAllFurniture(houseid)
{
? ? if(
HouseInfo[houseid][hID] > 0)
{
? ? for(new 
0<= Streamer_GetUpperBound(STREAMER_TYPE_OBJECT); )
? ? {
? ? ? ? if(
IsValidDynamicObject(i) && Streamer_GetExtraInt(iE_OBJECT_TYPE) == E_OBJECT_FURNITURE && Streamer_GetExtraInt(iE_OBJECT_EXTRA_ID) == HouseInfo[houseid][hID])
? ? ? ? {
? ? ? ? ? ? 
DeleteFurnitureObject(i);
}
}

mysql_format(mysql_connectionqueryBuffersizeof(queryBuffer), "DELETE FROM furniture WHERE houseid = %i"HouseInfo[houseid][hID]);
mysql_tquery(mysql_connectionqueryBuffer);
}
}

ReloadFurniture(objectidlabels)
{
if(
IsValidDynamicObject(objectid) && Streamer_GetExtraInt(objectidE_OBJECT_TYPE) == E_OBJECT_FURNITURE)
{
? ? new
? ? ? ? 
id Streamer_GetExtraInt(objectidE_OBJECT_INDEX_ID);

? ? 
DeleteFurnitureObject(objectid);

? ? 
mysql_format(mysql_connectionqueryBuffersizeof(queryBuffer), "SELECT * FROM furniture WHERE id = %i"id);
? ? 
mysql_tquery(mysql_connectionqueryBuffer"SQL_LoadFurnitures""i"labels);
}
}

ReloadAllFurniture(houseid)
{
? ? if(
HouseInfo[houseid][hID] > 0)
{
? ? for(new 
0<= Streamer_GetUpperBound(STREAMER_TYPE_OBJECT); )
? ? {
? ? ? ? if(
IsValidDynamicObject(i) && Streamer_GetExtraInt(iE_OBJECT_TYPE) == E_OBJECT_FURNITURE && Streamer_GetExtraInt(iE_OBJECT_EXTRA_ID) == HouseInfo[houseid][hID])
? ? ? ? {
? ? ? ? ? ? 
DeleteFurnitureObject(i);
}
}

mysql_format(mysql_connectionqueryBuffersizeof(queryBuffer), "SELECT * FROM furniture WHERE houseid = %i"HouseInfo[houseid][hID]);
mysql_tquery(mysql_connectionqueryBuffer"SQL_LoadFurnitures""i"HouseInfo[houseid][hLabels]);
}


I will be editing this thread if more codes are needed.


Photo What's IsValidObject or IsObjectValid
Posted by: GeorgeXCarl - 2020-09-30, 05:20 AM - Forum: Pawn Scripting - Replies (2)

help with my scripting i don't know how to check if the object is spawned or not because the samp wiki is shutdown so i have no idea what to do with IsValidObject or IsObjectValid or something what it calls please give me an example for this


  Character Selection Menu
Posted by: Torque - 2020-09-29, 08:39 AM - Forum: Pawn Scripting - No Replies

Hello all,



Does anybody have a script for a character selection menu UI?



[Image: crowqfbf7rbmd.png]


  SampSharp - Write game modes in .NET Core
Posted by: tim - 2020-09-28, 09:06 PM - Forum: Plugins - Replies (6)

[Image: sampsharp.png]



SampSharp







SampSharp is a plugin and library which allows you to write SA-MP game modes in C#. The plugin works both on Linux and Windows. The library contains various classes for every type of resource available in SA-MP (players, vehicles, textdraws, etc). Aside from this wrapper around native functions, the library also contains a good structure to build your gamemode on. This plugin was initially released in 2014, and has received a good ever since and I'm still available for any questions related to this plugin.



SampSharp provides two structures for developing game modes. SampSharp.GameMode and SampSharp.Entities.



SampSharp.GameMode provides a simple object-oriented structure for developing your game mode. All callbacks are forwarded to the implementation of BaseMode and vanilla callbacks are forwarded as events to the related instances (eg. OnPlayerText fires the PlayerText event on the related Player instance). A simple code sample can be found below.





PHP Code:
public class GameMode BaseMode

{

? ? protected 
override void OnPlayerConnected(BasePlayer playerEventArgs e)

? ? {

? ? ? ? 
base.OnPlayerConnected(playere);



? ? ? ? 
player.SendClientMessage($"Welcome {player.Name}, to a whole new world!");

? ? }



? ? [
Command("spawn")]

? ? public static 
void VehicleCommand(BasePlayer playerVehicleModelType model)

? ? {

? ? ? ? 
Console.WriteLine($"Spawning a {model} for {player.Name}");

? ? ? ? var 
vehicle GtaVehicle.Create(modelplayer.Position  new Vector3(000.5f), player.Rotation.Z);

? ? ? ? 
player.PutInVehicle(vehicle);

? ? ? ? 
player.SendClientMessage(Color.GreenYellow, $"You have spawned a {model}!");

? ? }





SampSharp.Entities (only available since early 2020) provides an Entity-Component-System structure with full dependency injection support for developing your game mode. SampSharp.Entities is still in active development but is already stable and usable. Below, a similar code sample can be found:



PHP Code:
? ? public class SampleSystem ISystem

? ? {

? ? ? ? [
Event]

? ? ? ? public 
void OnPlayerConnected(Player player)

? ? ? ? {

? ? ? ? ? ? 
player.SendClientMessage($"Welcome {player.Name}, to a whole new world!");

? ? ? ? }



? ? ? ? [
PlayerCommand("spawn")]

? ? ? ? public static 
void VehicleCommand(Player playerVehicleModelType modelIWorldService worldService)

? ? ? ? {

? ? ? ? ? ? 
Console.WriteLine($"Spawning a {model} for {player.Name}");

? ? ? ? ? ? var 
vehicle worldService.CreateVehicle(modelplayer.Position  new Vector3(000.5f), player.Rotation.Z, -1, -1);

? ? ? ? ? ? 
player.PutInVehicle(vehicle);

? ? ? ? ? ? 
player.SendClientMessage(Color.GreenYellow, $"You have spawned a {model}!");

? ? ? ? }

? ? } 



Download



Stable version: [Image: SampSharp.svg] [Image: total.svg]

Unstable version: [Image: SampSharp.svg]



https://github.com/ikkentim/SampSharp/releases





Documentation



Our documentation website is still in development and some vital documentation is still lacking. If you need any assistance, feel free to join our Discord server!



https://sampsharp.net


  SA:MP forum offline
Posted by: duduloch - 2020-09-28, 08:46 PM - Forum: Portuguese/Portugu?s - Replies (7)

Forum samp offline temporariamente ou ser? que o tio kalcor decidiu enfim por um ponto final na comunidade sem aviso pr?vio ??


  SA-MP RCON (Xamarin.Forms App)
Posted by: Nacompllo - 2020-09-28, 03:58 PM - Forum: Releases - Replies (1)

[Image: samp512.png]

Description:

SA-MP RCON is the essential tool for SA-MP server administrators, giving you full, real-time control of your server directly from your Android device. With an intuitive interface and powerful features, managing your server has never been so easy and accessible.

With SA-MP RCON, gain the power to make crucial adjustments. From basic operations to advanced settings, this application allows you to:
  • Shutdown your Server: Ensures a safe shutdown when necessary.
  • Customize Server: Change the host name, game mode and map name to refresh the gaming experience.
  • Comprehensive Server Control: Manage player access and server security through a robust system. Kick or ban players by ID, control access via IP bans/unbans, and update RCON passwords to maintain a secure and well-regulated gaming environment.
  • Direct Communication: Message players directly to the in-game chat for announcements or instructions.
  • Game Customization: Adjust the gravity and weather of the game for a unique experience.
Whether you need to perform routine maintenance or quickly respond to unexpected situations, SA-MP RCON gives you the control you need to keep your server running smoothly and keep your gaming community happy and engaged.

Features of the app:
  • Thanks to the open.mp API, the application displays a list of the servers that are online.
  • You can save / delete your favorite servers in a local database thanks to the use of sqlite-net.
  • You can remember your server's RCON password on your device so you don't have to type it every time you open the app (the password is kept encrypted on your device thanks to the use of SecureStorage).

Video:

https://odysee.com/samp-rcon-android:2

Images:

[Image: 2020-05-02_19-10-08.gif]

[Image: 2020-05-02_19-13-44.gif]

[Image: 2020-05-02_19-12-33.gif]
RCON Commands:

List of RCON commands

Credits:

Xamarin.Forms app developed by Sergtek

Icons:

bqlqn
Freepik
surang
Pixel perfect
itim2101

Downloads:

GitHub


  [I-ZCMD]Improved ZCMD - Fastest Command Processor
Posted by: Kwarde - 2020-09-28, 10:34 AM - Forum: Libraries - Replies (1)

NOTE: Directly copied from SAMP Forums (web archive). Fixed some links, and attempted to make the post look prettier (no empty lines). Somehow this editor keeps adding back those empty lines. I'll fix it later (right now gtg)


Improved ZCMD







Latest Version:0.2.3.0 (August 2016)







NOTE: Please do not credit me for the include. The original concept is from ZCMD. This is just a useless optimized (practically insignificant) cleaner version of ZCMD with one bug fixed.








ZCMD hasn't been updated in the last 6 years. We (the SAMP community) have advanced a lot in these years and these advancements haven't been implemented in ZCMD. I just re-wrote ZCMD 0.3.1 include and updated it. This is now a lot faster (still negligible) than ZCMD which makes this the fastest 'PAWN code' based Command Processor at the moment. The speed test results are given at the end of this thread. iZCMD also addresses few issues/bugs with ZCMD and also adds some new features (Case-sensitivity can be turned on/off using a define).






The great improvement in efficiency can be observed when you have small commands(commands which do not take a lot of CPU). If you have just one format function call in your command, I-ZCMD will be almost 2x faster than ZCMD. If you have 10 format calls in your command, I-ZCMD will be 1.5x faster than ZCMD.The main reason why I-ZCMD is amazingly fast when compared to ZCMD is because I-ZCMD gets rid of two CallLocalFunction(very slow function) calls. However, this improvement is negligible compared to the overall performance of your server which means don't expect your server to show measurable improvements after installing iZCMD. Anyway, its always advisable to use updated includes.




Changes from ZCMD:




  • OnPlayerCommandReceived & OnPlayerCommandPerformed are now called directly instead of using CallLocalFunction
  • Removed the OnGameModeInit/OnFilterscriptInit Hooks
  • Minor optimizations
  • Case Sensitivity now toggled on/off using a define
  • Addresses few ZCMD bugs




How to install?



For those who are already using ZCMD, you just need to replace ZCMD include with IZCMD include.There is no change in functionality (by default), all the changes affect the speed and efficiency of the script. The only new feature in I-ZCMD is that now case-sensitivity can be turned on/off by defining IZCMD_ENABLE_CASE_SENSITIVITY before including IZCMD. To maximize compatibility, iZCMD is not case-sensitive by default (ZCMD is not case-sensitive).




For those who are not using ZCMD, you need to download I-ZCMD include and paste it in your include folder. Any ZCMD tutorial will do for I-ZCMD since the syntax and functionality are the same in both.








How to use?






To create a command, all you need to do is create a public function using any of the given formats.




PHP Code:
COMMAND:yourcommand(playerid,params[])
{
? ? return 
CMD_SUCCESS;
}
CMD:yourcommand(playerid,params[])
{
? ? return 
CMD_SUCCESS;
}
command(yourcommand,playerid,params[])
{
? ? return 
CMD_SUCCESS;
}
cmd(yourcommand,playerid,params[])
{
? ? return 
CMD_SUCCESS;

When a player types "/yourcommand parameters", the public function will be called.The playerid parameter will have the id of the player who used the command and the params[] parameter will have the text which the player typed after typing the command (for the given example, params[] will have "parameters").






The "params" parameter will never be empty. If the player did give any parameters then params[0] will be '\1'.



You must return CMD_SUCCESS if the command was executed successfully (return CMD_FAILURE if you wish the server to send the "Unknown Command" message). This result will be passed on to OnPlayerCommandPerformed.




You can also use the ZCMD style of returning, i.e: 1 for success and any other value for failure.






You cannot use OnPlayerCommandText once you include this include. It won't be called if you still have it in your code. There are two new callbacks instead.






OnPlayerCommandReceived




This callback is called before the actual command function is called.




Parameters:

  • playerid is the ID of the player who used the command
  • cmdtext is text which the player typed


Return Values:


1 - command function will be called




0 - the command function won't be called.




PHP Code:
public OnPlayerCommandReceived(playerid,cmdtext[])
{
return 
1;

OnPlayerCommandPerformed



This callback is called after the command function is executed.




Parameters:

  • playerid is the ID of the player who used the command
  • cmdtext is text which the player typed
  • success is what the command function returned (CMD_SUCCESS or CMD_FAILURE)


Return Values:




0 or CMD_FAILURE - Player will see the Error Message, i.e "Unknown command"



1 or CMD_SUCCESS - The error message won't be sent





PHP Code:
public OnPlayerCommandPerformed(playerid,cmdtext[], success)
{
return 
success;

If you are not using OnPlayerCommandPerformed then what you return in your command function will decide if the Error Message will be sent or not.




Returning 0 or CMD_FAILURE in the command function means the error message will be sent.



Returning 1 or CMD_SUCCESS in the command function means the error message won't be sent.





Case-Sensitivity




Case Sensitivity is disabled by default which means that "/pm" and "/PM" will be treated to be the same. Case-sensitivity can be enabled by defining IZCMD_ENABLE_CASE_SENSITIVITY before you include izcmd to your script.






Tips & Tricks




1. Calling command functions manually


You can call a command function using the following code.




PHP Code:
cmd_yourcommand(playerid,params); 
You need to prefix "cmd_" to your command to call the command function.






2. Shortcut Commands?
You can make shortcut commands using the idea given below.



PHP Code:
COMMAND:arrest(playerid,params[])
{
? ? 
//your arrest code
? ? return CMD_SUCCESS
}
COMMAND:ar(playerid,params[])
{
? ? return 
cmd_arrest(playerid,params);

3. Disable Commands if player is not logged in


You can disable commands for a player who hasn't logged in using the following idea.




PHP Code:
public OnPlayerCommandReceived(playerid,cmdtext[])
{
? ? ? ? if(!
PlayerLoggedIn[playerid]) 
? ? ? ? {
? ? ? ? ? ? ? 
SendClientMessage(playerid,-1,"You need to log in to use commands");
? ? ? ? ? ? ? return 
0;
? ? ? ? }
return 
1;

4. I-ZCMD with[b] sscanf is the fastest way to process commands[/b]




PHP Code:
COMMAND:setskin(playerid,params[])
{
? ? ? new 
skinid;
? ? ? if(
sscanf(params,"i",skinid)) SendClientMessage(playerid,-1,"Usage:/setskin [skinid]");
? ? ? else 
SetPlayerSkin(playeridskin);
? ? ? return 
CMD_SUCCESS;

More Examples




PHP Code:
COMMAND:getvid(playerid,params[])
{
new 
id,string[144],vid;
if(
sscanf(params,"u",id))
{
if(
IsPlayerInAnyVehicle(playerid))
{
? ? 
vid GetPlayerVehicleID(playerid);
? ? 
format(string,sizeof(string),"The vehicle ID of your vehicle is %d.Use/getvid [Name/ID] to get vehicle ID of other player's vehicle.",vid);
return 
SendClientMessage(playerid,-1,string);
}
return 
SendClientMessage(playerid,-1,"Your not in a vehicle nor you have specified any player from which to get the vehicle id.Use /getvid [Name/ID] to get the vehicle ID of their vehicle.");
}
if(
IsPlayerConnected(id))
{
? ? if(
IsPlayerInAnyVehicle(id))
? ? {
? ? ? ? ? ? ? ? ? ? ? ? new 
pName[MAX_PLAYER_NAME];
? ? ? ? ? ? ? ? ? ? ? ? 
GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
? ? ? ? 
vid GetPlayerVehicleID(id);
? ? ? ? 
format(string,sizeof(string),"The vehicle ID of the vehicle which %s(%d) is using is %d.",pName,id,vid);
SendClientMessage(playerid,-1,string);
}
? ? else
? ? {
? ? ? ? 
SendClientMessage(playerid,-1,"The given player is not using any vehicle.");
? ? }
}
else { return 
SendClientMessage(playerid,-1,"Usage:/getvid:Invalid Player ID"); }
}
return 
CMD_SUCCESS;

Speed Tests




The test code approximately has 250 test commands out of which 6 valid commands are called and one invalid command is called.




The code which was used for speed test can be found [/url]here.




I-ZCMD (case-sensitive) is 5.4 times faster than ZCMD




I-ZCMD (non-case-sensitive) is 2.2 times faster than ZCMD




ZCMD and y_command perform equally well in cases such as in the above speed test where there are lot of commands.






Please note that if you need any of the y_command features, then use y_commands. If you try to implement a similar feature in iZCMD then iZCMD will most likely get slower than y_commands. Use iZCMD if and only if you don't use any of y_command features.








Download




Download izcmd.inc if you need the I-ZCMD include.





Download izcmd-original.inc if you need the original ZCMD Include








[url=https://web.archive.org/web/20200314132456/https://github.com/YashasSamaga/I-ZCMD]Visit Github project page











Credits




Zeex for the original ZCMD Include & the concept/algorithm.




Yashas for spending 60 minutes to update the include.