AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   New to AMX plugins, quick question (https://forums.alliedmods.net/showthread.php?t=17367)

SDJASON 08-30-2005 14:35

New to AMX plugins, quick question
 
Hello, i just started reading about AMX plugins and how they work, and after reading several guides (im aiming to write a program eventually) I have come up with a question i was wondering if anyone could answer

It seems to me, that every mapchange, amx plugin's are "reset" or "re loaded" or something similar, is there any way to circumvent this?

Im not looking to transfer pages of information and keep a running tab, simply looking if there was a way to set a variable during one game that could be checked the next game, regardless of whether a map change occured or not, and an action could be performed based on the True/False 1/0 nature of this variable...

Thank you in advance

~Jason

Brad 08-30-2005 14:40

I don't think there is any straightforward way to do as you ask. However, you could easily write whatever values you want to track across maps to a file when the map ends and then read it in when the next map starts.

SDJASON 08-30-2005 14:42

Thank you for the quick reply.. taht is what i was thinking id have to do, now i know for sure....

But since its just a simple Yes/No thingie... writing it to a tiny ass file shouldnt be too hard.... :)

~Jason

Zenith77 08-30-2005 16:43

lol...he doesnt know what he is getting himself into......

XxAvalanchexX 08-30-2005 16:55

There is a straightforward and simple way which is registering and storing a cvar value, which is good for small amounts of small data, but not good for tracking large amounts of data. If you just want to remember if the user had this plugin on or off, for example, would be a fair use of it. If you wanted to remember every single person's name then storing the information in a file or MySQL is the best choice.

Code:
public plugin_init() {    register_cvar("cvarname","defaultvalue"); } public set() {    set_cvar_num("cvarname",1); } public get() {    if(get_cvar_num("cvarnam") == 1) {    }    else {    } }

There are different commands for getting and setting different types of cvars (floats and strings).

BAILOPAN 08-30-2005 17:03

Plugins are reloaded on mapchange. I don't know why this is but since every plugin ever written implicitly "relies" on its state being refreshed, I will not change it for the lifetime of AMX Mod X. I believe there is no reason for plugins to be refreshed like this by default however.

You can use vault to store persistent things.

SDJASON 08-31-2005 13:30

Thank you again for all the replies, i have several methods of doing it now if i read correctly... ill get to work on it soon, im still teaching myself C++ so i dont even know if ill ever finish it...

Basically im taking a votekick script, and rewriting it as a amx_voterandom script

The end result of this script will be to write to this file a value (say 1) or to a CVAR 1 so it is stored during map switches

Then at the start of every map The randomall script will detect this variable, run normally, then reset the variable, file, or CVAR to 0 so that it has to be re-voted to happen again ....

As i said, this seems pretty straightforward to me, i have the votekick source, the randomall source, piecing this together shouldnt be too hard (stick the randomall source in an if loop and check for this variable) if not, terminate it somehow, or go into an infinite empty loop if true, run the randomall and reset the variable or cvar or file to 0) and modifying the votekick by removing kicking, editing some say_text's, and adding the editing of the file or Cvar.....


This SEEMS pretty straightforward to me.... anyone see any pitfalls i might run into?? like i said, I know Java pretty well, but learning C++... everything is very familiar, but im not familar enuff with C++ to know if something like that is possible.... it seems like an easy thing to do to me tho.... and im gonna try to get it working eventually :) maybe learn some more C++ in the process

~jason

Johnny got his gun 08-31-2005 13:40

One pitfall is plugins are written in Pawn, not C++.

XxAvalanchexX 08-31-2005 15:18

Quote:

Originally Posted by Johnny got his gun
One pitfall is plugins are written in Pawn, not C++.

You win at life.

Riddick51 09-03-2005 05:04

Code:

plugin_cvar 1

//use server.cfg each mapchange
mapchangecfgfile server.cfg

with that bit, your cvar plugin_cvar is set = 1 on each map change.

if you have amxmodx/configs/maps/de_aztec.cfg with the following contents:
Code:

plugin_cvar 0
de_aztec.cfg is "read-in" when the map changes to de_aztec and the plugin_cvar is set = 0

it executes like this:
changelevel de_aztec
server.cfg (is loaded, plugin_cvar=1)
de_aztec.cfg (is loaded, plugin_cvar=0)

and the process repeats for the next map change.


All times are GMT -4. The time now is 14:29.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.