SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 25/09/2017, 10:04 PM   #1
grymtn
Huge Clucker
 
Join Date: Jun 2013
Posts: 271
Reputation: 26
Default Usage of variable

hello all today i wrote a simple anti weapon hack sctript that fits my servers variables but i have a simple problem that my mind cant accept.

this is my script and apparently i cant use asd in it becuase its a string and tell me that i need to index it:

Code:
public wepcheat(playerid)
{
	new say1[MAX_PLAYERS],say2[MAX_PLAYERS];
	for(new ii=0; ii<MAX_PLAYERS;ii++)
	{
		for(new i=1; i < 3; i++)
		{
		    new asd[15];
			format(asd,sizeof(asd),"[GUN%d]",i);
		    if(USER[ii]asd!=0)
			{
			    say1[ii]++;
			}
		}
		for(new aa=0; aa<12; aa++)
		{
			new wid,wam;
			GetPlayerWeaponData(ii,aa,wid,wam);
			if(wid!=0)
			{
			    say2[ii]++;
			}
			
		}
		if(say1[ii]!=say2[ii])
		{
		    new rcontext[40],bantext[128];
		    format(bantext,sizeof(bantext),"ADMCMD-AUTOBAN: %s has been banned. Reason: Weapon hacks.");
			SendClientMessageToAll(COLOR_RED,bantext);
		    format(rcontext,sizeof(rcontext),"ban %d",ii);
		    SendRconCommand(rcontext);
		}
	}
}
any help is appreciated
grymtn is offline   Reply With Quote
Old 25/09/2017, 10:16 PM   #2
kAn3
Big Clucker
 
kAn3's Avatar
 
Join Date: Aug 2017
Location: Italia
Posts: 101
Reputation: 13
Default Re: Usage of variable

PHP Code:
public wepcheat(playerid)
{
    new 
say1[MAX_PLAYERS],say2[MAX_PLAYERS];
    for(new 
ii=0ii<MAX_PLAYERS;ii++)
    {
        for(new 
i=13i++)
        {
            new 
asd[15];
            
format(asd,sizeof(asd),"[GUN%d]",i);
            if(
USER[ii]asd!=0// <- WRONG as asd is a string correct this
            
{
                
say1[ii]++;
            }
        }
        for(new 
aa=0aa<12aa++)
        {
            new 
wid,wam;
            
GetPlayerWeaponData(ii,wid,wam);
            if(
wid!=0)
            {
                
say2[ii]++;
            }
            
        }
        if(
say1[ii]!=say2[ii])
        {
            new 
rcontext[40],bantext[128];
            
format(bantext,sizeof(bantext),"ADMCMD-AUTOBAN: %s has been banned. Reason: Weapon hacks.");
            
SendClientMessageToAll(COLOR_RED,bantext);
            
format(rcontext,sizeof(rcontext),"ban %d",ii);
            
SendRconCommand(rcontext);
        }
    }

kAn3 is offline   Reply With Quote
Old 25/09/2017, 10:22 PM   #3
grymtn
Huge Clucker
 
Join Date: Jun 2013
Posts: 271
Reputation: 26
Default Re: Usage of variable

OMG ARE YOU SERIOUS?! I really couldnt see that. If its that so, why im asking what is the correct usage?

EDIT: it works like this but i really wanna know if there is a way to fix it by using FOR

Code:
public wepcheat(playerid)
{
	new say1[MAX_PLAYERS],say2[MAX_PLAYERS];
	for(new ii=0; ii<MAX_PLAYERS;ii++)
	{
		if(USER[ii][GUN1]!=0)
		{
		    say1[ii]++;
  		}
  		if(USER[ii][GUN2]!=0)
		{
		    say1[ii]++;
  		}
  		if(USER[ii][GUN3]!=0)
		{
		    say1[ii]++;
  		}
		for(new aa=0; aa<12; aa++)
		{
			new wid,wam;
			GetPlayerWeaponData(ii,aa,wid,wam);
			if(wid!=0)
			{
			    say2[ii]++;
			}
			
		}
		if(say1[ii]!=say2[ii])
		{
		    new rcontext[40],bantext[128];
		    format(bantext,sizeof(bantext),"ADMCMD-AUTOBAN: %s has been banned. Reason: Weapon hacks.");
			SendClientMessageToAll(COLOR_RED,bantext);
		    format(rcontext,sizeof(rcontext),"ban %d",ii);
		    SendRconCommand(rcontext);
		}
	}
}
grymtn is offline   Reply With Quote
Old 25/09/2017, 10:26 PM   #4
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,528
Reputation: 556
Default Re: Usage of variable

You can't, unless you define GUNX as an array of guns, i.e GUN[MAX_X]
Misiur is offline   Reply With Quote
Old 25/09/2017, 10:31 PM   #5
grymtn
Huge Clucker
 
Join Date: Jun 2013
Posts: 271
Reputation: 26
Default Re: Usage of variable

this is the answer im looking for. thank you
grymtn is offline   Reply With Quote
Old 25/09/2017, 10:33 PM   #6
CodeStyle175
Banned
 
Join Date: Apr 2014
Posts: 455
Reputation: 35
Default Re: Usage of variable

Your anticheat doesnt even work.
PHP Code:
#define max_players 50
#define scm            SendClientMessage

new UWeapon[max_players][13];

GetWeaponSlot(weaponid){ 
    switch(
weaponid){ 
        case 
1: return 0
        case 
2..9: return 1
        case 
22..24: return 2
        case 
25..27: return 3
        case 
282932: return 4
        case 
3031: return 5
        case 
3334: return 6
        case 
35..38: return 7
        case 
16..1839: return 8
        case 
41..43: return 9
        case 
10..15: return 10
        case 
44..46: return 11
        case 
40: return 12
    } 
    return 
0
}  

func Update3sec(){
    new 
wid,wam;
    foreach(
Player,i){
        for(new 
i2i2 13i2++){
            
GetPlayerWeaponData(i,i2,wid,wam);
            if(
wid && UWeapon[i][GetWeaponSlot(wid)]!=wid){
                
scm(i,-1,"STOP CHEATING WEAPONS!");
            }
        }
    }
    return 
1;

CodeStyle175 is offline   Reply With Quote
Old 25/09/2017, 10:38 PM   #7
kAn3
Big Clucker
 
kAn3's Avatar
 
Join Date: Aug 2017
Location: Italia
Posts: 101
Reputation: 13
Default Re: Usage of variable

Copy pasted?
kAn3 is offline   Reply With Quote
Old 26/09/2017, 12:46 AM   #8
grymtn
Huge Clucker
 
Join Date: Jun 2013
Posts: 271
Reputation: 26
Default Re: Usage of variable

Quote:
Originally Posted by CodeStyle175 View Post
Your anticheat doesnt even work.
PHP Code:
#define max_players 50
#define scm            SendClientMessage

new UWeapon[max_players][13];

GetWeaponSlot(weaponid){ 
    switch(
weaponid){ 
        case 
1: return 0
        case 
2..9: return 1
        case 
22..24: return 2
        case 
25..27: return 3
        case 
282932: return 4
        case 
3031: return 5
        case 
3334: return 6
        case 
35..38: return 7
        case 
16..1839: return 8
        case 
41..43: return 9
        case 
10..15: return 10
        case 
44..46: return 11
        case 
40: return 12
    } 
    return 
0
}  

func Update3sec(){
    new 
wid,wam;
    foreach(
Player,i){
        for(new 
i2i2 13i2++){
            
GetPlayerWeaponData(i,i2,wid,wam);
            if(
wid && UWeapon[i][GetWeaponSlot(wid)]!=wid){
                
scm(i,-1,"STOP CHEATING WEAPONS!");
            }
        }
    }
    return 
1;

it definitely works if you get weapons out of script your USER[playerid][GUNx] es will be 0 and it will check if the numbers matches. i already tried and got myself banned. thank you for your attention tho. thanks all of you.

you guys think so big about this code, its working or not thats not even what i asked. I only asked how can i change the string asd there and im not trying to make an anticheat that will be applied to many servers. my code will only will only be capable to work with my variables which is working right now.

Also if you wanna see it working(just because you said no it doesnt work) i will show it on my code block on teamviewer and i get you an account on my server so you can check for yourself.
grymtn is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
local variable shadows a variable at a preceding level NBass Scripting Help 6 08/05/2017 03:33 PM
[Tutorial] SA:MP Images usage, list and usage. Partner Tutorials 23 26/03/2016 10:00 PM
Global variable/direct reference works, local variable doesn't - format (y_va) Misiur Scripting Help 11 25/02/2014 11:43 AM
Dynamic Variable Naming / Variable Variables / Indirect Variable Access Redgie Scripting Help 3 04/06/2012 07:32 PM


All times are GMT. The time now is 05:03 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.