looking like a jackass right now -_-
#1

so i've been trying to script a temp ban cmd for about 4 hours now and i came down to THIS!
Код:
CMD:tempban(playerid, params[])
{
	printf("%i", Player[playerid][adminlevel]);
	new targetid, reason[350], string[350], hours, minutes, seconds;
	if(Player[playerid][adminlevel] < 2) return ERRORMSG(playerid);
	if(sscanf(params, "usssss", targetid, reason, hours, minutes, seconds)) return 1;
	if(!IsPlayerConnected(targetid)) return NOT_VALID_ID(playerid);

	format(string, sizeof (string), "-AdminServ- %s (id: %d) has Temp-banned %s (id: %d) for:(Hours %d) (Minutes %d) (Seconds %d) Reason: %s.", Player[playerid][name], playerid, Player[targetid][name], targetid, hours, minutes, seconds, reason);
	SendClientMessageToAll(C_ACC, string);

	format(string, sizeof (string), "3AdminServ- %s (id: %d) has Temp-banned %s (id: %d) for:(Hours %d) (Minutes %d) (Seconds %d) Reason: %s.", Player[playerid][name], playerid, Player[targetid][name], targetid, hours, minutes, seconds, reason);
	CallRemoteFunction("OnPlayerAdminAction", "s", string);

	mysql_real_escape_string(reason, reason, mCon);
	TempBanAsshole(targetid, Player[playerid][name], hours, minutes, seconds, reason);
	return true;
}
the errors on this cmd are
Код:
C:\Users\Andrei\Desktop\Andrei\zPlague -v2-\filterscripts\ZPFS.pwn(2033) : warning 219: local variable "hours" shadows a variable at a preceding level
C:\Users\Andrei\Desktop\Andrei\zPlague -v2-\filterscripts\ZPFS.pwn(2033) : warning 219: local variable "minutes" shadows a variable at a preceding level
C:\Users\Andrei\Desktop\Andrei\zPlague -v2-\filterscripts\ZPFS.pwn(2033) : warning 219: local variable "seconds" shadows a variable at a preceding level
C:\Users\Andrei\Desktop\Andrei\zPlague -v2-\filterscripts\ZPFS.pwn(2045) : error 035: argument type mismatch (argument 3)
C:\Users\Andrei\Desktop\Andrei\zPlague -v2-\filterscripts\ZPFS.pwn(2033) : warning 203: symbol is never used: "seconds"
C:\Users\Andrei\Desktop\Andrei\zPlague -v2-\filterscripts\ZPFS.pwn(2033) : warning 203: symbol is never used: "minutes"
C:\Users\Andrei\Desktop\Andrei\zPlague -v2-\filterscripts\ZPFS.pwn(2033) : warning 203: symbol is never used: "hours"
Код:
(my function)
function TempBanAsshole(bannedid, adminname[], hours[], minutes[], seconds[], reason[]) {

	format(gString, sizeof(gString), "INSERT INTO `zp_bans2` (Name, Admin, Reason, IP, Hours, Minutes, Seconds) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
	Player[bannedid][name], adminname, reason, Player[bannedid][pIP], hours, minutes, seconds);
	mysql_function_query(mCon, gString, false, "OnAdminTempBanPlayer", "isiiis", bannedid, adminname, hours, minutes, seconds, reason);
	return 1;
}
with the errors of,
Код:
C:\Users\Andrei\Desktop\Andrei\zPlague -v2-\filterscripts\ZPFS.pwn(2793) : warning 219: local variable "hours" shadows a variable at a preceding level
C:\Users\Andrei\Desktop\Andrei\zPlague -v2-\filterscripts\ZPFS.pwn(2793) : warning 219: local variable "minutes" shadows a variable at a preceding level
C:\Users\Andrei\Desktop\Andrei\zPlague -v2-\filterscripts\ZPFS.pwn(2793) : warning 219: local variable "seconds" shadows a variable at a preceding level
now you see why im going crazy lol -_- please help.
Reply
#2

local variable "hours" shadows a variable at a preceding level

Quote:

local

-- > Within your scope
Quote:

shadows

overlays/replaces something
Quote:

preceding level

at a previous level
.
That means, you have two variables which are shadowing each other at different scope levels!
So change hours -> hours_1, or hours_other_name, and similarly for the other variables.
Also, you have a mistake in the sscanf line. You have "usssss" - 6 - while only passing 5 vars! Also, string size 350 is ridiculous, the max samp can show is 128.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)