#include <a_samp>
#include <sscanf2>
#include <zcmd>
CMD:god(playerid, params[])
{
//new str3[128];
new str1[128], str2[128], admin[MAX_PLAYER_NAME], p[MAX_PLAYER_NAME], id, Float: health1, Float:health2;
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You must be Admin to use this command");
//Make yourself god by typing only: /god
GetPlayerHealth(playerid, health1);
//format(str3, sizeof(str3), "health: %f.", health1); With these lines I found out that if you set a player's health to 9999~~.0,
//SendClientMessage(playerid, COLOR_ORANGE, str3); his health value becomes actually 0.0 and so I got the code working, took me hours, damn.
if(sscanf(params, "d", id)) //do not change "d" with "u" or in /god [ID] format,
{ //you will receive message "ERROR: Player is not connected." even if you enter valid id.
if (health1==0.0)
{
SetPlayerHealth(playerid, 100.0);
return SendClientMessage(playerid,0x00FF00AA, "Back to mortality.");
}
if (health1>0.0)
{
SetPlayerHealth(playerid, 9999999999999999.0);
return SendClientMessage(playerid, 0x00FF00AA, "You are god now!");
}
}
//Make a player of your server god with /god [ID]
if(IsPlayerConnected(id))
{
GetPlayerName(playerid, admin, MAX_PLAYER_NAME);
GetPlayerName(id, p, MAX_PLAYER_NAME);
GetPlayerHealth(id, health2);
if (health2>0.0)
{
SetPlayerHealth(id, 9999999999999999.0);
format(str2, sizeof(str2), "You have successfully turned %s into god.", p);
SendClientMessage(playerid, 0x00FF00AA, str2);
format(str1, sizeof(str1), "Admin %s has turned you into god!", admin);
SendClientMessage(id, 0x00FF00AA, str1);
}
if (health2==0)
{
SetPlayerHealth(id, 100.0);
format(str2, sizeof(str2), "You have turned god %s into human.", p);
SendClientMessage(playerid, 0x00FF00AA, str2);
return SendClientMessage(id, 0x00FF00AA, "Back to mortality.");
}
}
else SendClientMessage(playerid, 0xFF0000AA, "ERROR: Player is not connected.");
return 1;
}
#if !defined FLOAT_INFINITY
#define FLOAT_INFINITY (Float:0x7F800000)
#endif
Nicely done
Instead of setting their health that that extremely high number, why not just set it to infinity? pawn Code:
|
#include <a_samp>
#include <sscanf2>
#include <zcmd>
#define FLOAT_INFINITY (Float:0x7F800000)
CMD:god(playerid, params[])
{
//new str3[128];
new str1[128], str2[128], admin[MAX_PLAYER_NAME], p[MAX_PLAYER_NAME], id, Float: health1, Float:health2;
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You must be Admin to use this command");
//Make yourself god by typing only: /god
GetPlayerHealth(playerid, health1);
//format(str3, sizeof(str3), "health: %f.", health1); With these lines I found out that if you set a player's health to infinity,
//SendClientMessage(playerid, COLOR_ORANGE, str3); his health value becomes actually 0.0 and so I got the code working, took me hours, damn.
if(sscanf(params, "d", id)) //do not change "d" with "u" or in /god [ID] format,
{ //you will receive message "ERROR: Player is not connected." even if you enter valid id.
if (health1==0.0)
{
SetPlayerHealth(playerid, 100.0);
return SendClientMessage(playerid,0x00FF00AA, "Back to mortality.");
}
if (health1>0.0)
{
SetPlayerHealth(playerid, FLOAT_INFINITY);
return SendClientMessage(playerid, 0x00FF00AA, "You are god now!");
}
}
//Make a player of your server god with /god [ID]
if(IsPlayerConnected(id))
{
GetPlayerName(playerid, admin, MAX_PLAYER_NAME);
GetPlayerName(id, p, MAX_PLAYER_NAME);
GetPlayerHealth(id, health2);
if (health2>0.0)
{
SetPlayerHealth(id, FLOAT_INFINITY);
format(str2, sizeof(str2), "You have successfully turned %s into god.", p);
SendClientMessage(playerid, 0x00FF00AA, str2);
format(str1, sizeof(str1), "Admin %s has turned you into god!", admin);
SendClientMessage(id, 0x00FF00AA, str1);
}
if (health2==0)
{
SetPlayerHealth(id, 100.0);
format(str2, sizeof(str2), "You have turned god %s into human.", p);
SendClientMessage(playerid, 0x00FF00AA, str2);
return SendClientMessage(id, 0x00FF00AA, "Back to mortality.");
}
}
else SendClientMessage(playerid, 0xFF0000AA, "ERROR: Player is not connected.");
return 1;
}
You can't even call this filterscript, is this your first try? If yes, 7/10, not bad..
|
Sorry, but there's no prefix "command" so I put "filterscript".
This is just a command. I ve scripted some other commands (like /akill, /aslap, /goto, /getp, /pm, /heal) but they are even simpler so aren't worthy of being posted here. |
// Creating global player var. We'll use it later to check if player has god mode activated.
new
bool: GodMode[MAX_PLAYERS char];
// Our timer
static
GodTimer;
// Simple god command
CMD:god(playerid, params[])
{
if (!IsPlayerAdmin(playerid)) // Fixed typo
return SendClientMessage(playerid, -1, "Nope.");
GodMode{playerid} = !GodMode{playerid};
SendClientMessage(playerid, -1, GodMode{playerid} ? ("God Mode activated!") : ("God Mode disabled!"));
return 1;
}
// Now we're gonna create 2 secs timer to check if player has god mode activated and fix their health.
// 2 secs timer is ok so don't worry, it's not gonna lag.
forward GodModeCheck();
public GodModeCheck()
{
foreach(new i : Player)
{
if (GodMode{i} == true)
{
SetPlayerHealth(i, 100); // No need for 1k
}
}
return 1;
}
// Now we're gonna place under OnGameModeInit()
public OnGameModeInit()
{
GodTimer = SetTimer("GodModeCheck", 1000, true); // 1 sec timer.
return 1;
}
public OnGameModeExit()
{
KillTimer(GodTimer);
return 1;
}
Your code doesn't even work, cannot be compiled. Reading your logic I see that an admin can make only himself god, and can't transform a non-admin player into god, as mine command can.
|