Manager quix Posted March 16, 2023 Manager Share Posted March 16, 2023 In this topic, I'll post some codes I'll create for you to understand how this language works. (NOTE: These codes might not work as intended and might need some changes!) 1. Creates 2 text-draws that shows players connected and a welcoming message: #include <a_samp> new TextDraw:gWelcome, TextDraw:gPlayerList; main() { gWelcome = TextDrawCreate(10.0, 100.0, "Welcome to My Server"); TextDrawColor(gWelcome, 0xFFFFFFFF); TextDrawBackgroundColor(gWelcome, 0xFF000000); TextDrawLetterSize(gWelcome, 0.5, 1.0); TextDrawAlignment(gWelcome, 2); TextDrawSetOutline(gWelcome, 1); TextDrawSetShadow(gWelcome, 1); gPlayerList = TextDrawCreate(10.0, 150.0, "Players Online:"); TextDrawColor(gPlayerList, 0xFFFFFFFF); TextDrawBackgroundColor(gPlayerList, 0xFF000000); TextDrawLetterSize(gPlayerList, 0.3, 0.5); TextDrawAlignment(gPlayerList, 0); TextDrawSetOutline(gPlayerList, 1); TextDrawSetShadow(gPlayerList, 1); while (true) { // Update player list new playerCount = 0; for (new i = 0; i < MAX_PLAYERS; i++) { if (!IsPlayerConnected(i)) continue; playerCount++; new playerName[MAX_PLAYER_NAME]; GetPlayerName(i, playerName, sizeof(playerName)); TextDrawSetString(gPlayerList, playerCount + ". " + playerName); } // Wait a bit before updating again Sleep(5000); } return 0; } public OnPlayerConnect(playerid) { new message[128]; format(message, sizeof(message), "Player %s has joined the server.", GetPlayerName(playerid)); SendClientMessageToAll(0xFFFFFFAA, message); return 1; } public OnPlayerDisconnect(playerid, reason) { new message[128]; format(message, sizeof(message), "Player %s has left the server. Reason: %d", GetPlayerName(playerid), reason); SendClientMessageToAll(0xFFFFFFAA, message); return 1; } : adelinrzo : quiixx. : raizo (24.01.2023) (12.03.2023) (30.03.2023) Link to comment Share on other sites More sharing options...
Manager quix Posted March 16, 2023 Author Manager Share Posted March 16, 2023 2. This script creates a text-draw in the top-left corner of the screen with a gradient color, and uses an AI library to respond to player input. When a player types something in the chat, the OnPlayerText function is called and uses the AI_ProcessInput function from the AI library to generate a response. The response is then sent back to the player as a chat message with the prefix "AI:". When a player connects or disconnects, the OnPlayerConnect and OnPlayerDisconnect functions are called, respectively, and show or hide the text-draw accordingly. Finally, when the game mode is unloaded, the OnGameModeExit function is called and destroys the text-draw and frees the AI library resources. #include <a_samp> #include <AI.inc> new TextDraw:gTextDraw; public OnGameModeInit() { // Create a text-draw with a gradient color gTextDraw = TextDrawCreate(100.0, 100.0, "Hello, world!"); TextDrawLetterSize(gTextDraw, 0.5, 1.0); TextDrawTextSize(gTextDraw, 100.0, 10.0); TextDrawAlignment(gTextDraw, 1); TextDrawColor(gTextDraw, 0xFFFFAAFF); TextDrawUseBox(gTextDraw, true); TextDrawBoxColor(gTextDraw, 0x000000FF); TextDrawBackgroundColor(gTextDraw, 0x00000088); TextDrawFont(gTextDraw, 2); TextDrawSetProportional(gTextDraw, true); TextDrawSetShadow(gTextDraw, 2); TextDrawSetOutline(gTextDraw, 1); // Initialize the AI library AI_Init(); } public OnPlayerText(playerid, text[]) { // Use the AI library to generate a response to player input new response[MAX_PLAYER_NAME]; AI_ProcessInput(text, response, sizeof(response)); SendClientMessage(playerid, -1, "AI: " + response); return 1; } public OnPlayerConnect(playerid) { // Display the text-draw to the player TextDrawShowForPlayer(gTextDraw, playerid); return 1; } public OnPlayerDisconnect(playerid, reason) { // Hide the text-draw when the player disconnects TextDrawHideForPlayer(gTextDraw, playerid); return 1; } public OnGameModeExit() { // Destroy the text-draw and free the AI library resources TextDrawDestroy(gTextDraw); AI_Free(); return 1; } : adelinrzo : quiixx. : raizo (24.01.2023) (12.03.2023) (30.03.2023) Link to comment Share on other sites More sharing options...
Manager quix Posted March 16, 2023 Author Manager Share Posted March 16, 2023 3. This script allows players to use the "/holdhands" command to hold hands with another nearby player. When a player types the command, the script checks for nearby players within a certain distance and stores the ID and position of the target player new PlayerData[MAX_PLAYERS][3]; // Store hand-holding data for each player const HOLD_DISTANCE = 2.0; // Maximum distance between players to hold hands public OnPlayerCommandText(playerid, cmdtext[]) { if(!strcmp(cmdtext, "/holdhands", true)) { new Float:playerPos[3], Float:targetPos[3]; GetPlayerPos(playerid, playerPos[0], playerPos[1], playerPos[2]); // Check nearby players for hand-holding eligibility for(new targetid = 0; targetid < MAX_PLAYERS; targetid++) { if(IsPlayerConnected(targetid) && targetid != playerid) { GetPlayerPos(targetid, targetPos[0], targetPos[1], targetPos[2]); if(GetDistanceBetweenPoints3D(playerPos[0], playerPos[1], playerPos[2], targetPos[0], targetPos[1], targetPos[2]) <= HOLD_DISTANCE) { // Store hand-holding data for both players PlayerData[playerid][0] = targetid; // Target player ID PlayerData[playerid][1] = targetPos[0]; // Target player X position PlayerData[playerid][2] = targetPos[1]; // Target player Y position SendClientMessage(playerid, -1, "You are now holding hands with " + GetPlayerName(targetid) + "."); SendClientMessage(targetid, -1, GetPlayerName(playerid) + " is now holding hands with you."); break; } } } return 1; } return 0; } public OnPlayerDisconnect(playerid, reason) { // Remove hand-holding data for disconnected player PlayerData[playerid][0] = INVALID_PLAYER_ID; PlayerData[playerid][1] = 0.0; PlayerData[playerid][2] = 0.0; return 1; } public OnPlayerUpdate(playerid) { // Check if player is holding hands with another player if(PlayerData[playerid][0] != INVALID_PLAYER_ID) { new Float:playerPos[3], Float:targetPos[3]; GetPlayerPos(playerid, playerPos[0], playerPos[1], playerPos[2]); targetPos[0] = PlayerData[playerid][1]; targetPos[1] = PlayerData[playerid][2]; targetPos[2] = playerPos[2]; // Maintain same Z position // Teleport player towards target player to maintain hand-holding distance if(GetDistanceBetweenPoints3D(playerPos[0], playerPos[1], playerPos[2], targetPos[0], targetPos[1], targetPos[2]) > HOLD_DISTANCE) { new Float:direction = atan2(targetPos[1] - playerPos[1], targetPos[0] - playerPos[0]); playerPos[0] += HOLD_DISTANCE * cos(direction); playerPos[1] += HOLD_DISTANCE * sin(direction); SetPlayerPos(playerid, playerPos[0], playerPos[1], playerPos[2]); } } return 1; } : adelinrzo : quiixx. : raizo (24.01.2023) (12.03.2023) (30.03.2023) Link to comment Share on other sites More sharing options...
Manager quix Posted March 17, 2023 Author Manager Share Posted March 17, 2023 4. This script makes the player vulnerable and invulnerable by using the commands [/ungodmode] and [/godmode]: CMD:godmode(playerid, params[]) { SetPlayerHealth(playerid, 1000.0); // Set player health to maximum TogglePlayerControllable(playerid, false); // Make the player unkillable SendClientMessage(playerid, 0xFFFFFFFF, "You are now invincible!"); return 1; } CMD:ungodmode(playerid, params[]) { TogglePlayerControllable(playerid, true); // Make the player vulnerable again SendClientMessage(playerid, 0xFFFFFFFF, "You are no longer invincible!"); return 1; } : adelinrzo : quiixx. : raizo (24.01.2023) (12.03.2023) (30.03.2023) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now