AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How can i connect an array from one plugin to another? (https://forums.alliedmods.net/showthread.php?t=159941)

r4ndomz 06-23-2011 12:03

How can i connect an array from one plugin to another?
 
I want to use a shop with ghw's cs bank, how would i connect the array "bank[id]" so the shop will take money out of the users bank if they have money in there?

Nyuszy 06-23-2011 13:24

Re: How can i connect an array from one plugin to another?
 
you can use fake natives

add to the bank plugin:
PHP Code:

public plugin_natives()
{
    
register_native("get_user_bank""_get_user_bank")
    
register_native("set_user_bank""_set_user_bank")
}
// ...
public _get_user_bank(pluginparams)
{
    if(
params != 1)
        return 
PLUGIN_CONTINUE
    
new id get_param(1)
    return 
bank[id]
}

public 
_set_user_bank(pluginparams)
{
    if(
params != 2)
        return 
PLUGIN_CONTINUE
    
new id get_param(1)
    new 
money get_param(2)
    
bank[id] = money
    
return PLUGIN_HANDLED


add this to your plugin:
PHP Code:

native get_user_bank(id)
native set_user_bank(idmoney

and then you can use get_user_bank and set_user_bank in your plugin to handle the player's bank

SnoW 06-23-2011 15:59

Re: How can i connect an array from one plugin to another?
 
Or you could achieve the same with one line of code by using xvars.

Nyuszy 06-23-2011 16:06

Re: How can i connect an array from one plugin to another?
 
you can't use xvars with arrays

fysiks 06-23-2011 22:55

Re: How can i connect an array from one plugin to another?
 
Quote:

Originally Posted by Nyuszy (Post 1494346)
you can't use xvars with arrays

You should have shown an example of a native that uses arrays.

Exolent[jNr] 06-23-2011 23:33

Re: How can i connect an array from one plugin to another?
 
Quote:

Originally Posted by fysiks (Post 1494600)
You should have shown an example of a native that uses arrays.

His example is using arrays.
He is indexing the array and returning it's value, not copying the array to the plugin.

fysiks 06-24-2011 00:13

Re: How can i connect an array from one plugin to another?
 
Quote:

Originally Posted by Exolent[jNr] (Post 1494639)
His example is using arrays.
He is indexing the array and returning it's value, not copying the array to the plugin.

Oh, you're correct. I was thinking passing an array byref which would be incorrect in this situation.

ConnorMcLeod 06-24-2011 01:46

Re: How can i connect an array from one plugin to another?
 
http://www.amxmodx.org/funcwiki.php?...rray&go=search

Nyuszy 06-24-2011 04:13

Re: How can i connect an array from one plugin to another?
 
but passing the whole array has no sense (i think)

fysiks 06-24-2011 05:24

Re: How can i connect an array from one plugin to another?
 
Quote:

Originally Posted by Nyuszy (Post 1494866)
but passing the whole array has no sense (i think)

You are correct. Your example was the correct example. I was mistaken on what was actually suppose to be happening.


All times are GMT -4. The time now is 23:24.

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