Welcome, Guest |
You have to register before you can post on our site.
|
Online Users |
There are currently 273 online users. » 0 Member(s) | 270 Guest(s) Bing, Google, Yandex
|
|
|
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]](http://puu.sh/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]](https://i.imgur.com/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]](https://imgur.com/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]](http://i.imgur.com/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 i; i < sizeof(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_a, hex_b, difference = 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]) ); }
|
|
|
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(objectid, E_OBJECT_TYPE) == E_OBJECT_FURNITURE) { new ? ? ? ? id = Streamer_GetExtraInt(objectid, E_OBJECT_INDEX_ID);
? ? DeleteFurnitureObject(objectid);
? ? mysql_format(mysql_connection, queryBuffer, sizeof(queryBuffer), "DELETE FROM furniture WHERE id = %i", id); ? ? mysql_tquery(mysql_connection, queryBuffer); } }
DeleteFurnitureObject(objectid) { if(IsValidDynamicObject(objectid) && Streamer_GetExtraInt(objectid, E_OBJECT_TYPE) == E_OBJECT_FURNITURE) { ? ? new Text3D:textid = Text3D:Streamer_GetExtraInt(objectid, E_OBJECT_3DTEXT_ID);
? ? ? ? if(IsValidDynamic3DTextLabel(textid)) ? ? ? ? { ? ? ? ? ? ? DestroyDynamic3DTextLabel(textid); ? ? ? ? }
? ? ? ? DestroyDynamicObject(objectid); } }
RemoveAllFurniture(houseid) { ? ? if(HouseInfo[houseid][hID] > 0) { ? ? for(new i = 0; i <= Streamer_GetUpperBound(STREAMER_TYPE_OBJECT); i ) ? ? { ? ? ? ? if(IsValidDynamicObject(i) && Streamer_GetExtraInt(i, E_OBJECT_TYPE) == E_OBJECT_FURNITURE && Streamer_GetExtraInt(i, E_OBJECT_EXTRA_ID) == HouseInfo[houseid][hID]) ? ? ? ? { ? ? ? ? ? ? DeleteFurnitureObject(i); } }
mysql_format(mysql_connection, queryBuffer, sizeof(queryBuffer), "DELETE FROM furniture WHERE houseid = %i", HouseInfo[houseid][hID]); mysql_tquery(mysql_connection, queryBuffer); } }
ReloadFurniture(objectid, labels) { if(IsValidDynamicObject(objectid) && Streamer_GetExtraInt(objectid, E_OBJECT_TYPE) == E_OBJECT_FURNITURE) { ? ? new ? ? ? ? id = Streamer_GetExtraInt(objectid, E_OBJECT_INDEX_ID);
? ? DeleteFurnitureObject(objectid);
? ? mysql_format(mysql_connection, queryBuffer, sizeof(queryBuffer), "SELECT * FROM furniture WHERE id = %i", id); ? ? mysql_tquery(mysql_connection, queryBuffer, "SQL_LoadFurnitures", "i", labels); } }
ReloadAllFurniture(houseid) { ? ? if(HouseInfo[houseid][hID] > 0) { ? ? for(new i = 0; i <= Streamer_GetUpperBound(STREAMER_TYPE_OBJECT); i ) ? ? { ? ? ? ? if(IsValidDynamicObject(i) && Streamer_GetExtraInt(i, E_OBJECT_TYPE) == E_OBJECT_FURNITURE && Streamer_GetExtraInt(i, E_OBJECT_EXTRA_ID) == HouseInfo[houseid][hID]) ? ? ? ? { ? ? ? ? ? ? DeleteFurnitureObject(i); } }
mysql_format(mysql_connection, queryBuffer, sizeof(queryBuffer), "SELECT * FROM furniture WHERE houseid = %i", HouseInfo[houseid][hID]); mysql_tquery(mysql_connection, queryBuffer, "SQL_LoadFurnitures", "i", HouseInfo[houseid][hLabels]); } }
I will be editing this thread if more codes are needed.
|
|
|
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
|
|
|
SampSharp - Write game modes in .NET Core |
Posted by: tim - 2020-09-28, 09:06 PM - Forum: Plugins
- Replies (6)
|
 |
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 player, EventArgs e)
? ? {
? ? ? ? base.OnPlayerConnected(player, e);
? ? ? ? player.SendClientMessage($"Welcome {player.Name}, to a whole new world!");
? ? }
? ? [Command("spawn")]
? ? public static void VehicleCommand(BasePlayer player, VehicleModelType model)
? ? {
? ? ? ? Console.WriteLine($"Spawning a {model} for {player.Name}");
? ? ? ? var vehicle = GtaVehicle.Create(model, player.Position new Vector3(0, 0, 0.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 player, VehicleModelType model, IWorldService worldService)
? ? ? ? {
? ? ? ? ? ? Console.WriteLine($"Spawning a {model} for {player.Name}");
? ? ? ? ? ? var vehicle = worldService.CreateVehicle(model, player.Position new Vector3(0, 0, 0.5f), player.Rotation.Z, -1, -1);
? ? ? ? ? ? player.PutInVehicle(vehicle);
? ? ? ? ? ? player.SendClientMessage(Color.GreenYellow, $"You have spawned a {model}!");
? ? ? ? }
? ? }
Download
Stable version: ![[Image: total.svg]](https://img.shields.io/github/downloads/ikkentim/SampSharp/latest/total.svg)
Unstable version: ![[Image: SampSharp.svg]](https://img.shields.io/github/tag/ikkentim/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 RCON (Xamarin.Forms App) |
Posted by: Nacompllo - 2020-09-28, 03:58 PM - Forum: Releases
- Replies (1)
|
 |
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/@Nacompllo:5/samp-rcon-android:2?src=embed
Images:
RCON Commands:
List of RCON commands
Credits:
Xamarin.Forms app developed by Sergtek (Nacompllo)
Icons:
bqlqn
Freepik
surang
Pixel perfect
itim2101
Downloads:
GitHub
Official Website (All available downloads)
|
|
|
|