Sed's various stuff

Scripter or interested in scripting? This place just may fancy to your likings!

Moderators: Game Admins, FM, Lead Admins

Post Reply
Sed
Wannabe Don
Wannabe Don
Posts: 811
Joined: Sun Sep 21, 2014 11:40 pm
Ingame name: Alan_Fabbro
Location: North America

Sed's various stuff

Post by Sed » Wed Dec 21, 2016 5:58 am

Languages I know: Java, Python, and osme PAWN. :x
Last edited by Sed on Wed Dec 21, 2016 5:59 am, edited 1 time in total.
ego abscondamus tendiculas

Sed
Wannabe Don
Wannabe Don
Posts: 811
Joined: Sun Sep 21, 2014 11:40 pm
Ingame name: Alan_Fabbro
Location: North America

Me messing around (babysteps)

Post by Sed » Wed Dec 21, 2016 5:58 am

This was my first ever "script" in PAWN. Nothing really special here, nor worth copying, or that I'm too proud of. It was more to just practice syntax of more basic concepts. It's basically 3 commands. I didn't try to pretty it up at all. Script prints out GPCI and IP address when you connect to the server.

Here's a quick background.
GPCI is a (semi) unique number assigned to SAMP at install. It's useful to see when you're comparing player information and combined with IP address information it can help you figure out who is who.
PInfo prints out the player's current stats. This includes there health, armour, and money, as well as GPCI. You can update the health, armour, and money by "pinfoup" command (for the lazy. Ideally you'd just write to the value yourself and change it the appropriate amount Consider if you just updated when someone /pay'd, someone could hack in $12,000,000 and pay a dollar to some random and it would like fine.). Realistically, you'd have this information and you'd update the changes every time the script does damage or "changes" these values; and you'd constantly monitor for discrepancies, warning the admins (or kicking/banning) the player with any major deviations.
Netstats allows you to view the network information of a player, and monitor their packetloss among other things. This is basically stock from the GetPlayerNetworkStats command. An image can be seen of the box below. Image
Stuff I didn't do:
  • I didn't bother to take any parameters, so all commands are run on yourself.
  • I didn't bother to write admin warnings for any commands, nor loop through for checks.
  • I didn't bother to save the GPCI to the disk of the server or interface with any databases.
  • There is various potential cases that can bug out the above.
  • Use enums for the player vars.

Code: Select all

#include <a_samp>
#include <core>
#include <float>
#pragma tabsize 0

#include "../include/gl_common.inc"


native gpci(playerid, serial[], len);

// GPCI.
rGPCI(pid)
{
    new gep[256];

    gpci(pid, gep, sizeof(gep));
    return gep;
}



public OnPlayerSpawn(playerid)
{
    playerInfoUpdate(playerid);
	return 1;
}

public OnPlayerConnect(playerid)
{
//Var declerations
	new plrIP[16];
	GetPlayerIp(playerid, plrIP, sizeof(plrIP));
    playerInfoUpdate(playerid);
	SendClientMessage(playerid, 0xFFFF00FF, "Player Statistics:");
	SendClientMessage(playerid, 0xFFFF00FF, plrIP);
	SendClientMessage(playerid, 0xFFFF00FF, rGPCI(playerid));
	SendClientMessage(playerid, 0xFFFF00FF, "To view stats: /netstats");
	return 1;
}

public playerInfoUpdate(playerid){
 	new Float:pSH;
 	new Float:pSA;
 	new Int:pSM;

 // Gets
	GetPlayerArmour(playerid, pSA);
    GetPlayerHealth(playerid, pSH);
    pSM = GetPlayerMoney(playerid);

 // Sets
	SetPVarFloat(playerid, "pHealth", pSH);
	SetPVarFloat(playerid, "pArmour", pSA);
	SetPVarInt(playerid, "pMoney", GetPlayerMoney(playerid));
	return 1;
}


public OnFilterScriptInit()
{

}


public OnPlayerCommandText(playerid, cmdtext[])
{
	new cmd[256];
	new idx;
	cmd = strtok(cmdtext, idx);
	
	{
	// Put commands and IFs here

	if(strcmp(cmd,"/pinfo",true)==0){
		new Float:playerHealth;
		new Float:playerArmour;
		GetPlayerHealth(playerid, playerHealth);
    	new string[141];
    	SendClientMessage(playerid,-1, "");
    	format(string,141, "Printing report for ID %i", playerid);
    	SendClientMessage(playerid,-1, string);
    	format(string,141, "Playerhealth: %f  Tracked: %f", playerHealth, GetPVarFloat(playerid, "pHealth"));
    	SendClientMessage(playerid,-1, string);
    	format(string,141, "Player Armour: %f  Tracked: %f", playerArmour, GetPVarFloat(playerid, "pArmour"));
    	SendClientMessage(playerid,-1, string);
		format(string,141, "Player Money: %i  Tracked: %i", GetPlayerMoney(playerid), GetPVarInt(playerid, "pMoney"));
		SendClientMessage(playerid,-1, string);
		SendClientMessage(playerid, 0xFFFF00FF, rGPCI(playerid));
    	SendClientMessage(playerid,-1, "");
		return 1;
	}
	
	if(strcmp(cmd,"/pinfoup",true)==0){
		playerInfoUpdate(playerid);
		return 1;
	}

	if(strcmp(cmd,"/heal",true)==0){
		SetPlayerHealth(playerid, 100);
        return 1;
}

	if(strcmp(cmd,"/netstats",true)==0){
		new netst[400+1];
	    GetPlayerNetworkStats(playerid, netst, sizeof(netst));
	    ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Network Information", netst, "Close", "");
		return 1;
	}

    	if(strcmp(cmd,"/gcpi",true)==0)
	{
		SendClientMessage(playerid,0xAFAFAFAA,"ReturnGPCI");
	    SendClientMessage(playerid,0xAFAFAFAA, rGPCI(playerid));
	    return 1;
	}
	}

	return 0;
}
Last edited by Sed on Wed Dec 21, 2016 6:08 pm, edited 1 time in total.
ego abscondamus tendiculas

Sed
Wannabe Don
Wannabe Don
Posts: 811
Joined: Sun Sep 21, 2014 11:40 pm
Ingame name: Alan_Fabbro
Location: North America

BlackJack Simulator

Post by Sed » Wed Dec 21, 2016 6:05 am

If anyone remembers the old BlackJack, you remember the /dice and the betting but not knowing the odds. I wrote this program in Java to help me run games. It runs games rather quickly so I thought I'd share it. Now that the game is retired, from what I've been told, it should cause no issues with it's release.

Code.java

Code: Select all

import java.util.Random;

public class game {
	
	boolean hasRedeals; 
	int upperBound;
	Random r = new Random();
	int pC = 0;
	int dC = 0;
	
	
	public game(int bound){
		this.upperBound = bound;
	}
	
	// 0 is redeal
	// 1 is playerWin
	// 2 is dealerWin
	public int runGame(){
		pC = 0;
		dC = 0;
		pC = pHand();
		dC = dHand();
		//System.out.println("d"+dC+"p"+pC);
		if(pC > 21){
			return 2;
		}
		if(dC > 21){
			return 1;
		}
		if(pC == dC){
			//System.out.println(dC +" " + pC);
			return 0;
		}
		if(pC > dC){
			return 1;
		}
		if(dC > pC){
			return 2;
		}
		return -1;
	}
	
	private int pHand(){
		while(pC < upperBound){
			pC += r.nextInt(7);
		}
		//System.out.println("PC "+pC);
		return pC;
	}
	
	private int dHand(){
		while(dC <= pC){//&& dC != pC){ <- Switch this for redeals! :)
			dC += r.nextInt(7);
		}
		//System.out.println("DC "+dC);
		return dC;
	}
}
main.java

Code: Select all

import java.util.Random;

public class main {
	
	public static void main(String[] arg){
	for(int i = 3; i < 21; i++){
		System.out.println("Running simulation with bound "+i);
		System.out.println("Win percentage "+runGameSim(i, 19389012)); // feel free to change this INT to something more sensible.
	}
	}
	
	
	public static float runGameSim(int bound, int numberOfGames){
		game g = new game(bound);
		int gamesWon=0;
		int gamesLost=0;
		int gamesRedealt=0;
		int totalGames = 0;
		int currentStat = 0;
		for(int i = 0; i < numberOfGames; i++){
			currentStat = g.runGame();
			totalGames++;
			//System.out.println(currentStat);
			if(currentStat == 0)
				gamesRedealt++;
			else if(currentStat == 1)
				gamesWon++;
			else if(currentStat == 2)
				gamesLost++;
		}
		System.out.println("t" + totalGames);
		System.out.println("w" + gamesWon);
		System.out.println("l" + gamesLost);
		System.out.println("r" + gamesRedealt);
		return (gamesWon/(float)(totalGames));
	}

}
After I ran it, I got this output (redealing was turned off):

Running simulation with bound 16
...
Win percentage 0.28517023
Running simulation with bound 17
...
Win percentage 0.39666772
Running simulation with bound 18
....
Win percentage 0.47393987
Running simulation with bound 19
...
Win percentage 0.49635452
Running simulation with bound 20
...
Win percentage 0.44245726

I wrote this in like 15 minutes in AP US History when I was bored :x. Symantics might suck, sorry!
ego abscondamus tendiculas

Sed
Wannabe Don
Wannabe Don
Posts: 811
Joined: Sun Sep 21, 2014 11:40 pm
Ingame name: Alan_Fabbro
Location: North America

SD App Grader

Post by Sed » Wed Dec 21, 2016 8:52 pm

I coded a app to quickly check applications for manual review. A lot of things were hard coded just because how these were structured. It was never used but it was fun just to code and test. It detects formating errors, and various checks in the application. It is deprecated now and I can release it, as SD has changed their application :D

sdappautograder.java

Code: Select all

package sdappautograder;

import java.util.ArrayList;
import java.util.Scanner;

public class SDappautograder {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        String var = "";
        ArrayList<String> app = new ArrayList();
        while(!var.contains("-1")){
            app.add(var);
            var = stdin.nextLine();
        }
        application SedLSRP = new application(app);
    }
    
}
application.java

Code: Select all

package sdappautograder;

import java.util.ArrayList;

public class application {

    // TRUE MEANS ERROR YOU FOOL!
    private ArrayList<String> application;
    private String first;
    private String last;
    private boolean isMale;
    private boolean isCriminal;
    private boolean hasLicense;
    private boolean isCitizen;
    private boolean isHealthy;
    private boolean essayOneShort;
    private boolean essayTwoShort;
    private boolean essayThreeShort;
    private boolean formatError;
    private ArrayList<String> passReasons = new ArrayList();
    private ArrayList<String> failReasons = new ArrayList();

    public application(ArrayList<String> app) {
        application = app;
        varDar();
        formatError = formatError();
        // Length check
        lenass();
        // Null check
        nullCheck();
        // Var printing!
        varPrint();
    }

    public void lenass() {
        essayOneShort = lengthCheck("[b]7.1[/b] In at least 150 words, why would you like to become a Sheriff's Deputy? What motivated you to pursue the career path?", "[b]7.2[/b] In at least 300 words, explain what makes you unique, why we should accept you, and what differs you from any other applicant:", 150, 1);
        essayTwoShort = lengthCheck("[b]7.2[/b] In at least 300 words, explain what makes you unique, why we should accept you, and what differs you from any other applicant:", "[b]7.3[/b] Do you have any relevant past employment history/voluntary experience that is relevant to Law Enforcement? If so, tell us about it:", 300, 1);
        essayThreeShort = lengthCheck("[b]7.3[/b] Do you have any relevant past employment history/voluntary experience that is relevant to Law Enforcement? If so, tell us about it:", "[img]http://i.imgur.com/4k5lGtQ.png[/img] [b][size=110](( OOC INFORMATION ))[", 50, 1);
    }

    // Format Error Checks!
    public boolean formatError() {
        return tagCheck();
    }

    public boolean tagCheck() {
        boolean failed = false;
        int tag1 = 0;
        int tag2 = 0;
        int tag3 = 0;
        int tag4 = 0;
        int tag5 = 0;
        int tag6 = 0;
        int tag7 = 0;
        int tag8 = 0;
        int line = 0;
        int spoiler = 0;
        for (int i = 0; i < application.size(); i++) {
            if (application.get(i).contains("[line][/line]")) {
                line += 1;
            }
        }
        for (int i = 0; i < application.size(); i++) {
            if (application.get(i).contains("[altspoiler=Answer here]")) {
                spoiler += 1;
            }
        }
        for (int i = 0; i < application.size(); i++) {
            if (application.get(i).contains("[b]1.")) {
                tag1 += 1;
            }
        }
        for (int i = 0; i < application.size(); i++) {
            if (application.get(i).contains("[b]2.")) {
                tag2 += 1;
            }
        }
        for (int i = 0; i < application.size(); i++) {
            if (application.get(i).contains("[b]3.")) {
                tag3 += 1;
            }
        }
        for (int i = 0; i < application.size(); i++) {
            if (application.get(i).contains("[b]4.")) {
                tag4 += 1;
            }
        }
        for (int i = 0; i < application.size(); i++) {
            if (application.get(i).contains("[b]5.")) {
                tag5 += 1;
            }
        }
        for (int i = 0; i < application.size(); i++) {
            if (application.get(i).contains("[b]6.")) {
                tag6 += 1;
            }
        }
        for (int i = 0; i < application.size(); i++) {
            if (application.get(i).contains("[b]7.")) {
                tag7 += 1;
            }
        }
        for (int i = 0; i < application.size(); i++) {
            if (application.get(i).contains("[b]8.")) {
                tag8 += 1;
            }
        }
        if (tag1 != 10) {
            System.out.println("Section 1 tag error!");
            failed = true;
        }
        if (tag2 != 4) {
            System.out.println("Section 2 tag error!");
            failed = true;
        }
        if (tag3 != 5) {
            System.out.println("Section 3 tag error!");
            failed = true;
        }
        if (tag4 != 3) {
            System.out.println("Section 4 tag error!");
            failed = true;
        }
        if (tag5 != 5) {
            System.out.println("Section 5 tag error!");
            failed = true;
        }
        if (tag6 != 5) {
            System.out.println("Section 6 tag error!");
            failed = true;
        }
        if (tag7 != 3) {
            System.out.println("Section 7 tag error!");
            failed = true;
        }
        if (tag8 != 14) {
            System.out.println("Section 8 tag error!");
            failed = true;
        }
        if (line != 7) {
            System.out.println("Line error");
            failed = true;
        }
        if (spoiler != 5) {
            System.out.println("Spoiler error");
            failed = true;
        }
        return failed;
    }

    // Variable Decleration.
    public void varDar() {
        for (int i = 0; i < application.size(); i++) {
            String line = application.get(i);
            if (line.contains("[b]1.1[/b] First Name:")) {
                first = line.replace("[b]1.1[/b] First Name:", "").trim();
            }
            if (line.contains("[b]1.2[/b] Last Name:")) {
                last = line.replace("[b]1.2[/b] Last Name:", "").trim();
            }
            if (line.contains("[b]1.3[/b] Sex:")) {
                isMale = !line.replace("[b]1.3[/b] Sex:", "").trim().toLowerCase().contains("female");
            }
            if (line.contains("[b]2.1[/b] Been convicted of a felony charge? If so, specify:")) {
                if (!isCriminal) {
                    if (!line.replace("[b]2.1[/b] Been convicted of a felony charge? If so, specify:", "").trim().toLowerCase().contains("no")) {
                        isCriminal = true;
                        System.out.println("Felony");
                    }
                }
            }
            if (line.contains("[b]2.3[/b] Used any illegal drugs within the last two years? If so, specify which drug:")) {
                if (!isCriminal) {
                    if (!line.replace("[b]2.3[/b] Used any illegal drugs within the last two years? If so, specify which drug:", "").trim().toLowerCase().contains("no")) {
                        isCriminal = true;
                        System.out.println("Drugs");
                    }
                }
            }
            if (line.contains("[[b]2.2[/b] Been convicted of a misdemeanour charge? If so, specify:")) {
                if (!isCriminal) {
                    if (!line.replace("[b]2.2[/b] Been convicted of a misdemeanour charge? If so, specify:", "").trim().toLowerCase().contains("no")) {
                        isCriminal = true;
                    }
                    System.out.println("Mist");
                }
            }
            if (line.contains("[b]3.1[/b] Do you possess a drivers license valid within the state of San Andreas?:")) {

                if (!line.replace("[b]3.1[/b] Do you possess a drivers license valid within the state of San Andreas?:", "").trim().toLowerCase().contains("no")) {
                    hasLicense = true;

                }
            }
            if (line.contains("[b]4.1[/b] Are you a legal U.S citizen?:")) {

                if (!line.replace("[b]4.1[/b] Are you a legal U.S citizen?:", "").trim().toLowerCase().contains("no")) {
                    isCitizen = true;

                }
            }
            if (line.contains("[b]6.1[/b] Physical status:")) {
                if (!line.replace("[b]6.1[/b] Physical status:", "").trim().toLowerCase().contains("un")) {
                    isHealthy = true;

                }
            }
            if (line.contains("[b]6.2[/b] Mental status:")) {
                if (!line.replace("[b]6.2[/b] Mental status:", "").trim().toLowerCase().contains("un")) {
                    isHealthy = true;

                }
            }
        }

    }

    public void nullCheck() {
        //Code isn't included in this release1
    }

    public boolean lengthCheck(String search, String end, int requirement, int offset) {
        //Essay one check
        String line;
        int estart = 0;
        int eend = 0;
        int ewords = 0;
        for (int i = 0; i < this.application.size(); i++) {
            line = application.get(i);
            if (line.contains(search)) {
                estart = i;
            }
            if (line.contains(end)) {
                eend = i - 1;
            }
        }
        // Start at the start and do our subtraction :D
        for (int i = estart; i < eend + 1; i++) {
            line = application.get(i).replace(search, "");
            System.out.println(line);
            ewords += line.split(" ").length;
        }
        // We substract the offset.
        ewords -= offset;
        System.out.println("WC " + ewords);
        return ewords >= requirement;
    }

    private void varPrint() {
        System.out.print("I have decided to vote to accept/deny ");
        if (isMale) {
            System.out.print("Mr. ");
        } else {
            System.out.print("Ms. ");
        }
        System.out.print(first + " " + last + "\n");

//    Obsoleted for formatError
//    System.out.println("Missing Anything:" + missingVar);
        if (isCriminal) {
            passReasons.add("This person is clean of a criminal record.");
        } else {
            failReasons.add("This person has a criminal record, and is inadmissable to the department.");
        }
        if (hasLicense) {
            passReasons.add("This person has a drivers license, a basic requirement for admission");
        } else {
            failReasons.add("This person is missing a drivers license.");
        }
        if (isCitizen) {
            passReasons.add("This person is a citizen of the USA");
        } else {
            failReasons.add("This person is not a citizen.");
        }
        if (isHealthy) {
            passReasons.add("This person is healthy and fit to join.");
        } else {
            failReasons.add("This person is not healthy.");
        }

        //   System.out.println("Gun License:" + hasCert);
        System.out.println("Pass:");
        for (int i = 0; i < passReasons.size(); i++) {
            System.out.println(passReasons.get(i));
        }
        System.out.println("Failure:");
        for (int i = 0; i < failReasons.size(); i++) {
            System.out.println(failReasons.get(i));
        }

        System.out.println("E1 Short:" + essayOneShort);
        System.out.println("E2 Short:" + essayTwoShort);
        System.out.println("E3 Short:" + essayThreeShort);
        System.out.println("Formating Error:" + formatError);
    }
}
ego abscondamus tendiculas

Sed
Wannabe Don
Wannabe Don
Posts: 811
Joined: Sun Sep 21, 2014 11:40 pm
Ingame name: Alan_Fabbro
Location: North America

More babysteps.

Post by Sed » Fri Dec 23, 2016 5:06 pm

I just spent the last 30 minutes horsing around trying to add more admin commands. This is what I got done.

This function is the function I use in my scripts to warn admins of a particular event.

Code: Select all

adminWarn(aLevel, aWarning[]){
	new myString[140];
	format(myString, sizeof(myString), "AdmWarn[%i]: %s", aLevel, aWarning);
	for(new i = 0; i < MAX_PLAYERS; i++){
		if(myAdmins[i] >= aLevel){
			SendClientMessage(i, COLOR_YELLOW, myString);
}
}

}
This is the adminduty command for my script.

Code: Select all

CMD:adminduty(playerid,params[]){
	if(GetPVarInt(playerid, "pAdmin")==0){
		return 0;
}
	new myName[24] = " ";
	new myString[67];
	GetPlayerName(playerid, myName, sizeof(myName));
	format(myString, sizeof(myString), "%s is now on adminduty.", myName);
	
	if(GetPVarInt(playerid, "pDuty")==0){
    	SetPVarInt(playerid, "pDuty", 1);
    	adminWarn(1337, myString);
	}else{
    	SetPVarInt(playerid, "pDuty", 0);
}
    return 1;
}
This is my incomplete /admins command to list the admins.

Code: Select all

CMD:admins(playerid,params[]){
	new myString[140];
	new name[25];
	new isDuty[4] = "No";
	new color = COLOR_GREY;
		for(new i = 0; i < MAX_PLAYERS; i++){
			if(myAdmins[i] > 0){
				GetPlayerName(playerid, name, sizeof(name));
					if(GetPVarInt(i, "pDuty")==1){
						isDuty = "Yes";
						color = COLOR_GREEN;
}
				format(myString, sizeof(myString), "(Level: %i) %s (ID:%i) Adminduty: %s", GetPVarInt(i, "pAdmin"), name, i, isDuty);
				SendClientMessage(playerid, color, myString);
			}
		}
	return 1;
}
ego abscondamus tendiculas

Sed
Wannabe Don
Wannabe Don
Posts: 811
Joined: Sun Sep 21, 2014 11:40 pm
Ingame name: Alan_Fabbro
Location: North America

Re: Sed's various stuff

Post by Sed » Sat Dec 24, 2016 4:27 am

I have updated /admins to reflect that there may not be an admin online and tell the user appropriately.

Code: Select all

CMD:admins(playerid,params[]){
	new myString[140];
	new name[25];
	new isDuty[4] = "No";
	new color = COLOR_GREY;
	new Int:d = 0;
		for(new i = 0; i < MAX_PLAYERS; i++){
			if(myAdmins[i] > 0){
			    d=d+1;
				GetPlayerName(playerid, name, sizeof(name));
					if(GetPVarInt(i, "pDuty")==1){
						isDuty = "Yes";
						color = COLOR_GREEN;
}
				format(myString, sizeof(myString), "(Level: %i) %s (ID:%i) Adminduty: %s", GetPVarInt(i, "pAdmin"), name, i, isDuty);
				SendClientMessage(playerid, color, myString);
			}
		}
	// Tell the user if there is no admins online :P
	if(d==0){
	SendClientMessage(playerid, COLOR_GREY, "There are no administrators online");
	}
	return 1;
}
ego abscondamus tendiculas

F Sullivan
Mafia
Mafia
Posts: 573
Joined: Sun Mar 22, 2015 7:23 am

Re: Sed's various stuff

Post by F Sullivan » Sat Dec 24, 2016 6:35 am

It'd be greatly beneficial to you if you started to use enums for your player data structure.

Sed
Wannabe Don
Wannabe Don
Posts: 811
Joined: Sun Sep 21, 2014 11:40 pm
Ingame name: Alan_Fabbro
Location: North America

Re: Sed's various stuff

Post by Sed » Sat Dec 24, 2016 3:22 pm

F Sullivan wrote:It'd be greatly beneficial to you if you started to use enums for your player data structure.
I was thinking about that I was just unsure, are enums not persistent across filterscripts?
ego abscondamus tendiculas

F Sullivan
Mafia
Mafia
Posts: 573
Joined: Sun Mar 22, 2015 7:23 am

Re: Sed's various stuff

Post by F Sullivan » Sat Dec 24, 2016 6:17 pm

I approach PAWN scripting in a very modular way, meaning each part of my code is broken down into its own module and then included in my gamemode file. I avoid using filterscripts.

Code: Select all

// player.pwn

enum e_PLAYER_DATA 
{
	ID,
	Username[MAX_PLAYER_NAME],
	bool:AdminStatus
}

new Player[MAX_PLAYERS][e_PLAYER_DATA];

Code: Select all

// gamemode.pwn

#include "modules/player.pwn"

public OnPlayerConnect(playerid) {
	Player[playerid][ID] = playerid; // Example
}
The compiler merges the included files into the main gamemode, and as a result, allows you to access the data. This is just my approach to larger gamemodes that I've found to be a great help, you don't have to use filterscripts.

Sed
Wannabe Don
Wannabe Don
Posts: 811
Joined: Sun Sep 21, 2014 11:40 pm
Ingame name: Alan_Fabbro
Location: North America

Re: Sed's various stuff

Post by Sed » Sat Dec 24, 2016 6:26 pm

F Sullivan wrote:I approach PAWN scripting in a very modular way, meaning each part of my code is broken down into its own module and then included in my gamemode file. I avoid using filterscripts.

Code: Select all

// player.pwn

enum e_PLAYER_DATA 
{
	ID,
	Username[MAX_PLAYER_NAME],
	bool:AdminStatus
}

new Player[MAX_PLAYERS][e_PLAYER_DATA];

Code: Select all

// gamemode.pwn

#include "modules/player.pwn"

public OnPlayerConnect(playerid) {
	Player[playerid][ID] = playerid; // Example
}
The compiler merges the included files into the main gamemode, and as a result, allows you to access the data. This is just my approach to larger gamemodes that I've found to be a great help, you don't have to use filterscripts.
Hmm. Interesting. I'm coming from a classful approach from Java (which I'm very used too). I'll probably swap over, because PlayerSetVar doesn't seem as nice. Thanks for the headsup!
ego abscondamus tendiculas

User avatar
EldarCoox
Mafia
Mafia
Posts: 516
Joined: Sun Jul 21, 2013 9:44 pm
Ingame name: Deki

Re: Sed's various stuff

Post by EldarCoox » Sun Jan 08, 2017 11:42 pm

u should use enums dude way more easier :D

Post Reply

Return to “Scripting Section”

Who is online

Users browsing this forum: No registered users