22.05.2014, 10:00
Hi there!
This is a snippet I found in "the back of the yard"!
Enjoy, and let me know if it works for you. I didn't test it that much!
Cheers,
Jingles
This is a snippet I found in "the back of the yard"!
Enjoy, and let me know if it works for you. I didn't test it that much!
Код:
#include <a_samp> #include <sscanf2> #include <zcmd> enum { DIALOG_WEAPONAMMO } CMD:buyammo(playerid, params[]) { ShowPlayerDialog(playerid, DIALOG_WEAPONAMMO, DIALOG_STYLE_LIST, "Weapon Ammo", "Desert Eagle (100 rounds)\n M4(400 rounds)\nCombat Shotgun (300 rounds)", "Select", "Close"); return 1; } CMD:givedeagle(playerid, params[]) { new iAmmo; iAmmo = 3; GivePlayerWeapon(playerid, 24, iAmmo); SetPlayerAmmo(playerid, 24, iAmmo); SetPVarInt(playerid, "iAmmo", iAmmo); return 1; } CMD:givem4(playerid, params[]) { GivePlayerWeapon(playerid, 31, 50); return 1; } CMD:giveshotgun(playerid, params[]) { GivePlayerWeapon(playerid, 27, 50); return 1; } public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { if(dialogid == DIALOG_WEAPONAMMO) { if(response) // If they clicked 'Select' or double-clicked a weapon { // Give them the weapon switch(listitem) { case 0: SetPlayerAmmo(playerid, GetPVarInt(playerid, "iCurrentWeapon"), 100); case 1: SetPlayerAmmo(playerid, GetPVarInt(playerid, "iCurrentWeapon"), 400); case 2: SetPlayerAmmo(playerid, GetPVarInt(playerid, "iCurrentWeapon"), 300); } } return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText. } return 0; // You MUST return 0 here! Just like OnPlayerCommandText. } public OnPlayerUpdate(playerid) { new iCurWeap = GetPlayerWeapon(playerid); // Return the player's current weapon if(iCurWeap != GetPVarInt(playerid, "iCurrentWeapon")) // If he changed weapons since the last update { // Lets call a callback named OnPlayerChangeWeapon OnPlayerChangeWeapon(playerid, GetPVarInt(playerid, "iCurrentWeapon"), iCurWeap); SetPVarInt(playerid, "iCurrentWeapon", iCurWeap);//Update the weapon variable } return 1; // Send this update to other players. } stock OnPlayerChangeWeapon(playerid, oldweapon, newweapon) { new s[128], oWeapon[24], nWeapon[24]; GetWeaponName(oldweapon, oWeapon, sizeof(oWeapon)); GetWeaponName(newweapon, nWeapon, sizeof(nWeapon)); format(s, sizeof(s), "You changed weapon from %s to %s!", oWeapon, nWeapon); SendClientMessage(playerid, 0xFFFFFFFF, s); } public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ) { GetPVarInt(playerid, "iAmmo"); SetPlayerAmmo(playerid, GetPVarInt(playerid, "iCurrentWeapon"), GetPVarInt(playerid, "iAmmo")-1); SetPVarInt(playerid, "iAmmo", GetPVarInt(playerid, "iAmmo")-1); if(GetPVarInt(playerid, "iAmmo") <= 0 || GetPVarInt(playerid, "iAmmo") > 10000) { GivePlayerWeapon(playerid, GetPVarInt(playerid, "iCurrentWeapon"), 999999999); SetPVarInt(playerid, "iAmmo", 999999999); SendClientMessage(playerid, -1, "You are out of ammo."); } new string[128]; format(string, sizeof(string), "Your ammo: %i", GetPVarInt(playerid, "iAmmo")); SendClientMessage(playerid, -1, string); return 1; } public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid) { if(GetPVarInt(playerid, "iAmmo") <= 0 || GetPVarInt(playerid, "iAmmo") > 10000) { new Float:health; GetPlayerHealth(playerid, health); SetPlayerHealth(issuerid, health); } return 1; } public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { if(newkeys & KEY_FIRE) { if(GetPVarInt(playerid, "iAmmo") <= 0 || GetPVarInt(playerid, "iAmmo") > 10000) SetPlayerArmedWeapon(playerid, 0); } return 1; }
Jingles